Article ID: 117563
Article Last Modified on 1/18/2007
SCRIBBLE.H
<Inside CScribbleApp class>
public:
HWND m_hwndDialog;
SCRIBBLE.CPP
<Inside CScribbleApp::InitInstance>
m_hwndDialog = NULL;
NOTE: Because this message filter applies to the entire application,
there may be a performance hit when you use this method.
SCRIBBLE.H
public:
virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);
SCRIBBLE.CPP
BOOL CScribbleApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
// Check to make sure CPenWidthsDlg is up
if (m_hwndDialog != NULL)
{
if ((lpMsg->hwnd == m_hwndDialog) ||
::IsChild(m_hwndDialog, lpMsg->hwnd))
// Use ::IsChild to get messages that may be going
// to the dialog's controls. In the case of
// WM_KEYDOWN this is required.
{
if (lpMsg->message == WM_KEYDOWN)
TRACE("Got WM_KEYDOWN\n");
}
}
// Default processing of the message.
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
For more information on overriding ProcessMessageFilter, please see
the MFC online Help.
PENDLG.H
protected:
virtual BOOL OnInitDialog();
afx_msg void OnDestroy();
PENDLG.CPP
<Add to Message Map>
ON_WM_DESTROY()
BOOL CPenWidthsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Use AfxGetApp() to get pointer to CWinApp-derived
// object; then cast the pointer to our type and assign
((CScribbleApp *)AfxGetApp())->m_hwndDialog = m_hWnd;
return TRUE; // Return TRUE
// unless you set the focus to a control.
}
void CPenWidthsDlg::OnDestroy()
{
CDialog::OnDestroy();
// Use AfxGetApp() to get pointer to CWinApp-derived
// object; then cast the pointer to our type and assign
((CScribbleApp *)AfxGetApp())->m_hwndDialog = NULL;
}
Additional query words: kbinf 1.00 1.50 2.00 2.10 2.50 3.00 3.10 4.00 key keystroke
Keywords: kbhowto kbkeyin kbhook kbarchitecture kbdlg KB117563