Using MFC to make a simple calculator in VS2012

Source: Internet
Author: User

Using MFC to make a simple calculator, to deepen the understanding of MFC learning, this calculator is based on the dialog box, the following to briefly explain how to make your own calculator

1. First, click VS2012, launch the VS software, then build the application as shown, enter the project name below the diagram


2. create a dialog-based standard program, as shown in the rest of the settings using System settings, click Finish


3. For example, the software will generate the following dialog box, as well as the corresponding library, code, resource files, etc.


4. Edit the above dialog box, as shown in, the last edit looks like this, where 1,5,6 is the edit control, 2,7 is a static control, 3 is the buttion,4 is the Cancel button changed the name, the individual controls are sorted, and changed the name, The remainder uses the software default


5. 1, 5,7 the control to add a variable, right-click on the control and select the following


/span>

6. As variable add Wizard, 1 Select value,2 Select double (convenient to calculate decimal number) 3, is the variable name, we choose a, the same way, the 1,5,7 in the corresponding variable, respectively, the work a,b,sum


7. When you're done, double-click the Calculate button on the dialog box , the corresponding message map is generated, which is entered in the following code, see


/span>

8. /span>

Add the following code to this function, the parameter true in the Updatadate () function means getting the value from the control variable, false instead

Sum=a+b, which is the three variables we added to the control first, the calculator here is just for an addition.


9. after adding the above code, the compilation succeeds as follows


Ctrl+f5 Run as


Input values for addition calculation, you can do other related extensions, such as subtraction, multiplication, etc., are the same method


Using MFC to make a simple calculator in VS2012

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.