VC + + generated dialog box by default will not respond to OnChar and onkeydown messages, will be blocked by other controls
if you do not modify the code, use will be found not to enter the two event response function, you must modify the rewrite PreTranslateMessage () Virtual functions can correctly
In response to these two message functions, the implementation is as follows:
BOOL Ctestdlg::P retranslatemessage (msg* pMsg)
{
SendMessage (pmsg->message,pmsg- >wparam,pmsg->lparam);
return 0;
Return CDialog::P retranslatemessage (PMSG);
}
This allows the program to correctly invoke both the onkeydown and OnChar functions, and onkeydown () is processed before Oncchar ().
This allows you to respond to WM_CHAR, WM_KEYDOWM messages in a dialog box, and notice that when you send WM_CHAR, you actually send three messages
that WM_CHAR
wm_keydowm
wm_keyup
So if you have the following code:
void Cmy1dlg::onchar (UINT nChar, UINT nrepcnt, UINT nflags)
{
//todo:add your message Handl ER code here and/or call default
if (nchar== ' a ')
MessageBox ("a");
Cdialog::onchar (NChar, nrepcnt, nflags);
}
Two messages dialog boxes pop up, so it's best to handle the events individually in WM_KEYDOWM or wm_keyup.