Up/down key

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.