各位大侠,我从CWnd派生了一个类CDebugEdit,并重载了它的OnChar函数
然后将它创建在了一个Dialog上,在OnInitDialog函数里面加入了m_debugedit.Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_VSCROLL|WS_BORDER,CRect(50, 50, 300, 200), this, 110, NULL);
但运行时,CDebugEdit都不响应WM_CHAR消息,请各位大侠救命!!
然后将它创建在了一个Dialog上,在OnInitDialog函数里面加入了m_debugedit.Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_VSCROLL|WS_BORDER,CRect(50, 50, 300, 200), this, 110, NULL);
但运行时,CDebugEdit都不响应WM_CHAR消息,请各位大侠救命!!
The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function.
已经获得焦点了,也可以响应WM_KEYDOWN消息!
在PreTranslateMessage里面也可以截获WM_CHAR消息
if((pMsg->message == WM_CHAR)&&(pMsg->hwnd == m_hWnd))
{
return CWnd::PreTranslateMessage(pMsg);
}
但跟进CWnd::PreTranslateMessage(pMsg)函数时发现:
BOOL CWnd::PreTranslateMessage(MSG* pMsg)
{
// handle tooltip messages (some messages cancel, some may cause it to popup)
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
if (pModuleState->m_pfnFilterToolTipMessage != NULL)
(*pModuleState->m_pfnFilterToolTipMessage)(pMsg, this);// no default processing
return FALSE;
}跟踪发现pModuleState->m_pfnFilterToolTipMessage == NULL
函数CWnd::PreTranslateMessage(MSG* pMsg)的返回为FALSE!
如果加入如下代码
void CDebugEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default CString Msg;
Msg.Format("%c", nChar);
AfxMessageBox(Msg);
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}void CDebugEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CString Msg;
Msg.Format("%c", nChar);
AfxMessageBox(Msg);
CWnd::OnChar(nChar, nRepCnt, nFlags);
}则按键时会有响应,弹出两个消息框,但我如果将OnKeyDown中的“AfxMessageBox(Msg);”注释掉,则WM_CHAR没有响应,注释OnKeyDown中的其它代码时,WM_CHAR也可以响应。
晕晕晕!!!急急急!!!
CWnd::WindowProc是什么意思?是要查哪方面?请多提示一点,谢谢!to tigerfox(混合体:=初级程序员 . 正在郁闷中):
SPY++观察没有什么异常
OnChar( pMsg->wParam,lParam & 0xffff,lParam);
这时不能在调用CWnd::PreTranslateMessage(pMsg),而是直接返回TRUE
果然是高手,太谢谢你了!