Article ID: 126874
Article Last Modified on 11/21/2006
-------------------------------------
| CWinApp::PumpMessage |
-------------------------------------
|
|
-------------------------------------
| CWinApp::PreTranslateMessage |
-------------------------------------
|
|
-------------------------------------
| CWnd:: PreTranslateMessage |
-------------------------------------
When a modal dialog box has been invoked, the above sequence is no longer
used. A modal dialog box uses the Dialog Manager (the code built into
Windows for implementing dialog boxes) to retrieve messages from the
application's message queue and process them. In other words, the Dialog
Manager takes control of all message processing during the existence of a
modal dialog box. Here's a picture of this process:
-------------------------------------
| CWinApp::PumpMessage |
-------------------------------------
|
|
-------------------------------------
| CDialog::DoModal |
-------------------------------------
|
|
-------------------------------------
| Dialog Manager's Message Loop |
-------------------------------------
The PumpMessage has dispatched the message that invoked the dialog box in
the first place. PumpMessage will not be called again until the Dialog
Manager exits its message loop -- when the modal dialog box has been
dismissed.
AfxGetApp()->m_pMainWnd->EnableWindow(FALSE)
This window should be re-enabled once the dialog box has been destroyed.
Use the following call to do it:
AfxGetApp()->m_pMainWnd->EnableWindow(TRUE)
One possible place to do this might be in the CDialog-derived object's
PostNcDestroy function that gets called when the dialog box window
itself (the HWND) is destroyed.
BOOL CMyApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
// Check to see if the modal dialog box is up
if (m_hwndDialog != NULL)
if (lpMsg->hwnd == m_hwndDialog ||
::IsChild(m_hwndDialog, lpMsg->hwnd))
{
// Use the global IsChild() function to get
// messages destined for the dialog's controls
// Perform customized message processing here
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
// The OnInitDialog to initialize m_hwndDialog
//
CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
((CMyApp *)AfxGetApp())->m_hwndDialog=m_hWnd;
}
// When the dialog is destroyed restore m_hwnDialog to NULL
//
void CMyDialog::PostNcDestroy()
{
CDialog::PostNcDestroy();
((CMyApp *)AfxGetApp())->m_hwndDialog=NULL;
}
// The CWinApp object's constructor to initialize m_hwndDialog
CMyApp::CMyApp()
{
m_hwndDialog=NULL;
}
Additional query words: 1.00 1.50 2.00 2.10 2.50 2.51 3.00 3.10 4.00 WM_KEYDOWN
Keywords: kbcode kbprb kbuidesign KB126874