How can I make the cedit control in the dialog box didit not catch a cold when I press enter?

Source: Internet
Author: User

Method:

  1. Select the want return attribute for the cedit that can be edited for multiple rows.
  2. For cedit of a single row, you need to reload onok () and oncancel ()
  3. Intercept the Enter key message

 

Select the attributes multiline and want return of the cedit control.

 

I used to encounter such a problem when I was just learning it. No one around me could use MFC (or csdn). At that time, I was very depressed. The current students are really happy. In fact, the reason is very simple: when you press enter, Windows will check the current input focus. If it is not on the button, you can see which button is the default one (the default attribute in the resource editor button ). If no default button is available, the application framework sends the message to the onok () virtual function in the dialog box. So you just need to reload this function. This is basically the same as that of the ms mvp.
The specific method is as follows:
1. Remove the default properties of the OK button.
2. Add a message processing function for the OK button. Onok ()
3. Remove cdialog: onok () from onok. // if your dialog box class is directly inherited from cdialog
4. Rename the OK button ID to idc_ OK.
5. Re-Add the message processing function for the OK button. Generally, it is named onclickedok (). Here is the function that the real processing button is pressed.
In this way, you can

 

 

I also encountered this problem at the beginning, as if it was related to the keyboard response function of the program.
This function is added to the message in the Class Wizard.
Bool cserverdlg: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class
If (PMSG-> message = wm_keydown & PMSG-> wparam = vk_return)

{
// Add the action you want the program to take after receiving the Keyboard Message.
Return true;
}

Return cdialog: pretranslatemessage (PMSG );
}

Related Article

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.