Limit on number in the edit box in MFC

Source: Internet
Author: User

When an int variable is added to the edit box, the following two values can be set to the maximum and minimum values;

Or add it by yourselfCodeDdv_minmaxint (PDX, m_nport, 1, 65535 );

But this does not have to work.

Solution: Add a message with no focus (killfocus) to the edit box, and set updatedata (true) in it.

The reason is that when the focus is lost, synchronize the values of the form and related variables so that the subsystem can correctly determine whether the value exceeds the set range.

However, there is another reason, as long as your input value is not in the Set range, then your focus cannot leave the control, because it will always pop up.

Solution: Remove ddv_minmaxint (PDX, m_nport, 1, 65535) and write the code in the killfocus function to determine the cause.
 

{
Updatedata (true );
If(M <0) | (M>65535))
{
Messageboxw (null, l"The value range is exceeded!", L"Error", Mb_ OK );
M =0;
Updatedata (false );
}
}

Note: In fact, this is no different from the first one, but it is more flexible.The cstring type variable can be used to set the string length..

Supplement: After Techwalker reminder,ProgramThe user may not lose the focus of the edit box after the input, but directly press the Enter key to go to the next step, so what is mentioned above will cause problems. So I searched and should useEn_changeMessage insteadKillfocusMessage.

{
// Todo: if this is a RichEdit control, the control will not
// Send this notification unless you override the cdialog: oninitdialog ()
// Function and call cricheditctrl (). seteventmask ()
// With the enm_change flag ored into the mask.

// Todo: add your control notification handler code here
Updatedata (true );
If (M_neditnum>100 ) | (M_neditnum < 1 ))
{
M_neditnum = 1 ;
Updatedata (false );
}
}

For more information, see: cedit class (edit class) member function and message http://hi.baidu.com/chaohona/blog/item/0d1d8f597486608b800a1880.html

[Thank you for your reference]
How in the text box input MFC can get data: http://zhidao.baidu.com/question/308978825.html? Fr = qrl & cid = 93 & Index = 5
Edit box cedit wrap simple settings: http://www.cnblogs.com/ziwuge/archive/2011/12/03/2274886.html

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.