MFC edit box control only enter decimals, and control the number of decimal places, the number of digits, the value

Source: Internet
Author: User

Effect


Key code

void Cdecimaledit::onchar (UINT NChar, uint nrepcnt, uint nflags) {//Todo:add your message Handler co De here and/or call default///guarantee that the decimal point can only occur once if ((nchar==0x08) | | (nchar==0x10)) 
	, Backspace,delete {Cedit::onchar (NChar, nrepcnt, nflags);

	} CString str;
	Gets the string GetWindowText (str) in the original edit box; int len = str.
	GetLength ();
	if (Len >=) {return;
	} if (nchar== '. ') {///Wakahara has a decimal point in the string, it is not entered so that you can enter at most one decimal if (str). Find ('. ')! 
		=-1) {}//otherwise enter this decimal dot else {Cedit::onchar (NChar, nrepcnt, nflags);
	} return; 
	}//Except the decimal point, also allows the input number if ((nchar>= ' 0 ' && nchar<= ' 9 ')) {Cedit::onchar (NChar, nrepcnt, nflags);
	}//Other keys do not respond to else {} getwindowtext (str); Len = str.
	GetLength ();
		if (len >=) {checkwidth (str);
	Return
		} if (Atoi (str) > 4000000) {AfxMessageBox ("the maximum value must not exceed 4000000");
		SetWindowText ("");
	Return	


	} checkwidth (str);
Return }


Project Download:

http://download.csdn.net/detail/ycs34082419900527/9912505 Click to open link

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.