在PreTranslateMessage(MSG* pMsg)中調(diào)用DoModal()模態(tài)窗口如下:
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);//調(diào)用對(duì)話框函數(shù)
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 }
再單擊對(duì)話框上的按鈕時(shí)發(fā)送斷言中斷,具體位置如下:
::IsWindow(m_hWnd)
函數(shù)功能:該函數(shù)確定給定的
窗口句柄是否標(biāo)識(shí)一個(gè)已存在的窗口。
函數(shù)原型:BOOL IsWindow(HWND hWnd);
參數(shù):
hWnd:被測(cè)試窗口的句柄。
返回值:如果
窗口句柄標(biāo)識(shí)了一個(gè)已存在的窗口,返回值為非零;如果窗口句柄未標(biāo)識(shí)一個(gè)已存在窗口,返回值為零。
可能原因:在PreTranslateMessage里的獲取對(duì)應(yīng)m_hWnd,DoModal()模態(tài)對(duì)話框退出后,m_hWnd不是有效的窗口句柄。解決辦法:處理完WM_LBUTTONUP后,需要返回TRUE。
posted on 2013-12-05 10:58
王海光 閱讀(2463)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
MFC