面对现实,超越自己
逆水行舟,不进则退
posts - 269,comments - 32,trackbacks - 0
PreTranslateMessage(MSG* pMsg)中调用DoModal()模态窗口如下:

 1 BOOL CMainDlg::PreTranslateMessage(MSG* pMsg)
 2 {
 3     // TODO: Add your specialized code here and/or call the base class
 4     if ( pMsg->message == WM_LBUTTONDOWN)
 5     {
 6         GetWindowRect(m_oldRect);
 7         ::SetCapture(this->m_hWnd);
 8         m_bCanDrag = TRUE;
 9         m_lastPt = pMsg->pt ;
10     }
11     else if ( pMsg->message == WM_LBUTTONUP)
12     {
13         if( m_bCanDrag )
14         {
15             ::ReleaseCapture();
16             m_bCanDrag = FALSE;
17             GetWindowRect(m_newRect);
18             if (m_oldRect.EqualRect(m_newRect))
19             {
20                 GetMainItemID(pMsg);//调用对话框函数
21                 //return TRUE;
22             }
23         }
24     } 
25     else if( pMsg->message == WM_MOUSEMOVE)
26     {
27         if( m_bCanDrag )
28         {
29             CRect rc;
30             GetWindowRect(&rc);
31             rc.OffsetRect( pMsg->pt.x - m_lastPt.x , pMsg->pt.y - m_lastPt.y  ) ;
32             m_lastPt = pMsg->pt;
33             this->MoveWindow( rc );
34         }
35     }
36 
37     return CDialog::PreTranslateMessage(pMsg);
38 }

39  void CMainDlg::GetMainItemID(MSG* pMsg)
40 {
41     if (pMsg->hwnd == GetDlgItem( IDC_BTN_MYCOMPUTER )->m_hWnd)
42     {
43        CTestDlg dlg;
44        dlg.DoModal();
45     }
46 }

再单击对话框上的按钮时发送断言中断,具体位置如下:


::IsWindow(m_hWnd)

函数功能:该函数确定给定的窗口句柄是否标识一个已存在的窗口。
函数原型:BOOL IsWindow(HWND hWnd);
参数:
hWnd:被测试窗口的句柄。
返回值:如果窗口句柄标识了一个已存在的窗口,返回值为非零;如果窗口句柄未标识一个已存在窗口,返回值为零。

可能原因:在PreTranslateMessage里的获取对应m_hWnd,DoModal()模态对话框退出后,m_hWnd不是有效的窗口句柄。
解决办法:处理完WM_LBUTTONUP后,需要返回TRUE。
posted on 2013-12-05 10:58 王海光 阅读(2391) 评论(0)  编辑 收藏 引用 所属分类: MFC

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理