Tag: Dialog Box
In this caseVc6.0In the MFC mode dialog box, this dialog box can be used for addition, subtraction, multiplication, division.
The procedure is as follows:
1) create a modal dialog box, refer to the http://blog.csdn.net/sanqima/article/details/34076191
2) add four buttons in the "Four arithmetic operations" dialog box and name them "add", "sub", "Mul", and "Div" in sequence. For example, add () is set as follows:
3) Compile the correspondingResponse FunctionsAdd (), sub (), MUL (), and Div (). The Code is as follows:
Void ctestdlg: onadd () {// todo: add your control notification handler code heredouble num1, num2, num3; char limit [10], CH2 [10], CH3 [10]; getdlgitem (idc_edit1)-> getwindowtext (success, 10); getdlgitem (idc_edit2)-> getwindowtext (CH2, 10); num1 = atof (SUCCESS ); num2 = atof (CH2); num3 = num1 + num2; gcvt (num3, 10, CH3); getdlgitem (idc_edit3)-> setwindowtext (CH3);} void ctestdlg :: onsub () {// todo: add your control notification handler cod E heredouble num1, num2, num3; char values [10], CH2 [10], CH3 [10]; getdlgitem (idc_edit1)-> getwindowtext (values, 10 ); getdlgitem (idc_edit2)-> getwindowtext (CH2, 10); num1 = atof (random); num2 = atof (CH2); num3 = num1-num2; gcvt (num3, 10, CH3 ); getdlgitem (idc_edit3)-> setwindowtext (CH3);} void ctestdlg: onmul () {// todo: add your control notification handler code heredouble num1, num2, num3; char keys [10], CH2 [10], CH3 [10]; getdlgitem (idc_e Dit1)-> getwindowtext (success, 10); getdlgitem (idc_edit2)-> getwindowtext (CH2, 10); num1 = atof (SUCCESS); num2 = atof (CH2 ); num3 = num1 * num2; gcvt (num3, 10, CH3); getdlgitem (idc_edit3)-> setwindowtext (CH3);} void ctestdlg: ondiv () {// todo: add your control notification handler code heredouble num1, num2, num3; char comment [10], CH2 [10], CH3 [10]; getdlgitem (idc_edit1)-> getwindowtext (comment, 10); getdlgitem (idc_edit2)-> getwindowtext (CH2, 10); Num1 = atof (random); num2 = atof (CH2); If (num2 = 0) {MessageBox ("the divisor cannot be 0. Please input it again! ") ;}Else {num3 = num1/num2; gcvt (num3, 10, CH3); getdlgitem (idc_edit3)-> setwindowtext (CH3 );}}
Note: When converting double to string, useAtof ();When converting string to double, useGcvt (),The referenced header file is# Include <stdlib. h>
Double atof (const char *String );
Char * gcvt (double value, int ndigit, char * BUF );
Value-- The converted value.Ndigit-- The number of valid digits stored.Buf-- Storage location of the result.
Note: The gcvt function converts a floating point value into a string (including a decimal point and possible symbolic bytes) and stores the string in the buffer. The buffer should be large enough to accommodate the converted value and the ending space character. It is automatically added. If the size of a buffer zone is digits size + 1, this function overwrites the end of the buffer zone. This is because the conversion string contains a decimal point and may contain symbols and exponent information. No overflow is provided. Gcvt tries to generate digits numbers in decimal format. If it is not possible, it generates digits numbers in exponential format. during conversion, it may remove the end 0.
Full Code address: http://download.csdn.net/detail/sanqima/7546847