作者:朱金灿

来源:http://www.cnblogs.com/clever101

 

 

本文拙文《在对话框上创建视图的方法总结》,有网友朋友来邮件反映:在对话框上可以成功创建视图,但是用鼠标单击视图的时候,就会出现Assert错误,说ViewCore.cpp   252行中有错。具体是:CView类的onmouseActive函数中ASSERT(pParentFrame   ==   pDesktopWnd   ||   pDesktopWnd->IsChild(pParentFrame)),出错!

 

下班回家我决心亲自试验一番,我在我的对话框程序上添加了各种鼠标消息,包括WM_LBUTTONDOWN、WM_MOUSEMOVE和WM_LBUTTONUP,但是都没有出错。我一下抓瞎了,只好上论坛发贴求助,但是一时之间也没多少人回应。我只好直接在google上搜索ASSERT(pParentFrame   ==   pDesktopWnd   ||   pDesktopWnd->IsChild(pParentFrame))这个断言错误。终于搜到了一篇相关文章《如何在没有文档的情况下使用CView及其派生类》。阅读之下我算是明白了为什么会出错。首先我们明确断言错误是在CView::OnMouseActivate函数上发生的,那么让我们看看MSDN对OnMouseActivate函数的解释:

 

The framework calls this member function when the cursor is in an inactive window and the user presses a mouse button.

      

     大意是当光标在一个非活动窗口和用户按下鼠标时框架就会调用这个消息。那我们再看看CView::OnMouseActivate函数的源码:

 

int CView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
    
int nResult = CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
    
if (nResult == MA_NOACTIVATE || nResult == MA_NOACTIVATEANDEAT)
        
return nResult;   // frame does not want to activate

    CFrameWnd
* pParentFrame = GetParentFrame();
    
if (pParentFrame != NULL)
    {
        
// eat it if this will cause activation
        ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame));

        
// either re-activate the current view, or set this view to be active
        CView* pView = pParentFrame->GetActiveView();
        HWND hWndFocus 
= ::GetFocus();
        
if (pView == this &&
            m_hWnd 
!= hWndFocus && !::IsChild(m_hWnd, hWndFocus))
        {
            
// re-activate this view
            OnActivateView(TRUE, thisthis);
        }
        
else
        {
            
// activate this view
            pParentFrame->SetActiveView(this);
        }
    }
    
return nResult;
}

相关文章:

  • 2021-07-25
  • 2021-09-30
  • 2021-12-08
  • 2022-12-23
  • 2021-12-15
  • 2022-02-25
  • 2021-11-23
猜你喜欢
  • 2021-11-06
  • 2022-01-02
  • 2021-10-13
  • 2022-01-05
  • 2022-01-01
相关资源
相似解决方案