dialog box keys handle PreTranslateMessage, onkeydown, and OnChar
1. MFC dialog box cannot respond to onkeydown and OnChar functions
(1) Phenomenon
In the MFC dialog box, the WM_CHAR and WM_KEYDOWN messages are mapped, but the dialog box does not respond to the onkeydown and OnChar functions
(2) Reason
Because MFC in the design, these two messages are intercepted by the control on the dialog box, can not reach the two message response function, for onkeydown, as long as the control on the dialog box is deleted, you can receive the WM_KEYDOWN message, but still do not receive WM_CHAR message
(3) Solve
Overload PreTranslateMessage this function; add SendMessage (Pmsg->message,pmsg->wparam,pmsg->lparam) in it; after this sentence, The onkeydown and OnChar Functions of the dialog box are in effect. OnKeyDown is processed before OnChar.
2.wm_keydown, Wm_keyup and WM_CHAR
The order of execution for three messages is Wm_keydown, WM_CHAR, Wm_keyup
3. In MFC's single document application, it extracts the key content directly.
4. If the direction key is handled, the following:
Arrow keys (←): Vk_left (37)
Arrow keys (↑): Vk_up (38)
direction keys (→): vk_right (39)
Arrow keys (↓): Vk_down (40)
Response Wm_keydown
1 void Cxxxxview::onkeydown (UINT NChar, uint nrepcnt, uint nflags) 2 {3 if (vk_left==NChar) 4 {5 MessageBox ("xxx"); 6 }7 cview::onkeydown (NChar, nrepcnt, nflags); 8 }
The keys of the
dialog box handle PreTranslateMessage, onkeydown, and OnChar