Use of Button controls

Source: Internet
Author: User
Tags unique id

Recently a lot of friends to send letters to my mailbox, which has a master also have rookie, perhaps they ask the question I can not answer one by one, but their letter really let me feel a great encouragement. Today, a piece of foreign translation of the article, dedicated to those who grope in the rookie.

The following is a simple program to illustrate the message mechanism for Windows. The program mainly uses two button controls, it requires the user to enter two digits, when you press one of the buttons, according to the corresponding calculation and output results. For example, if you enter 1 and 2, and then press the ' Plus ' button, the result is output.

Because in most cases the button control is used in a dialog box, our program starts with the dialog box. Use the Program Wizard to create a project named "Buttondemo" that selects the type of program based on the dialog box.

Select the Resourcevew property page in workspace, where you'll find an item named IDD_BUTTONDEMO_DLG and double hit the Open dialog box Editing window. You can see that the system has added the ' OK ' and ' Cancel ' two buttons to the window for us, we reserve the OK button, delete the Cancel button, and change the position of the button as shown in the picture.

Add two buttons to the form by dragging and dropping the mouse (because you need ' Plus ' and ' minus ' two buttons in this program), right-click on the button, and select Properties to enter the control's property settings. MFC assigns a unique ID value to each button that is added to the window, and the corresponding ID value is recorded in a file named "Resource.h." To express the function of each control, we change the ID value of the button to Id_button_add and modify the contents of the caption to "Plus".

Next we'll add the edit box control to enter and output data in the program. Adding the edit box control is the same as adding the button control by first pulling in the control, adjusting its position in the window, and then modifying its ID value. As shown in the following illustration, but remember to hook the ' disable ' property in the last edit box control's property setting because the result of the calculation does not need to be entered by the user. We also add a static control to the two edit box on the right to display the equals sign in the equation, just drag the control in to change its caption.

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.