I haven't written anything on my blog for nearly a year. Now I start to accumulate my knowledge and record the problems or solutions I encountered during my work and study.
In the MFC dialog boxProgram.
After trying various messages in the form, I found this solution on the Internet:
Override the pretranslatemessage function, regardless of the key PMSG-> message = wm_keydown on the form.
To monitor the top, bottom, left, right-click, it should be like this
// Override the pretranslatemessage function of the Form class
Bool cdemodlg: pretranslatemessage (msg * PMSG)
{
If (PMSG -> Message = Wm_keydown)
{
If (PMSG -> Wparam = Vk_left)
{}
Else If (PMSG -> Wparam = Vk_right)
{}
Else If (PMSG -> Wparam = Vk_up)
{}
Else If (PMSG -> Wparam = Vk_down)
{}
}
Return Cdialog: pretranslatemessage (PMSG );
}
Tests show that this method is very powerful-even if there are other widgets on the form that can accept the focus, you can also respond to keyboard messages on the form. In contrast, when a text control on the form is receiving keyboard input, the form can still get the upper, lower, and lower messages.
Conclusion: The pretranslatemessage function opens the door for message processing in MFC. Based on the function name, you can know that this function is executed before the translatemessage function. After checking the msdn function, you can see that this is indeed the case. If you want to control messages by yourself, you can implement them here, so you need to implement more useful functions in this function in the future.