Button control usage Summary

Source: Internet
Author: User
The button control is represented by cbutton in MFC. cbutton contains three styles: Push Button, check box, and radio button.
I. Static controlsDrag the push button, check box, and radio button controls in the toolbox to the dialog box, and use the wizard function of Visual Studio to associate the cbutton variable and add corresponding response events. After dragging the button control to the dialog box, you can also manually associate variables and add event response functions. The steps are as follows (take push button as an example): 1. add the variable cbutton m_btn to the dialog box class; 2. associated variables: Add ddx_control (PDX, idc_button1, m_btn) to the dodataexchange function; 3. add message ing: Add on_bn_clicked (idc_button1, & ctestdlg: onbnclickedbutton1) between consumer and end_message_map and add the void ctestdlg: onbnclickedbutton1 ().
Ii. Dynamic Creation1. create a cbutton instance cbutton * p_mybutton = new cbutton (); 2. call the CREATE () function of the cbutton class to create the function prototype: bool create (lpctstr lpszcaption, DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint NID ); lpszcaption --- text dwstyle displayed on the button --- window style, which can be a combination of the following styles: [general] ws_child subwindow, ws_visible window must be visible ws_tabstop. You can use the tab key to switch the focus ws_group to a group, used for the first ws_disabled button in the radio button group to disable the window [Button dedicated] bs_pushbutton press button, that is, the push button bs_autoradiobutton radio button and the radio button bs_autocheckbox check button and check box rect --- button size and position pparentwnd --- parent window NID --- add message ing to id3. associated with the button (same as above) 4. the destroy resource delete function in the cbutton class destructor calls destroywindow to release window resources related to it.

Sample Code:

// Create push buttoncbutton * m_pmybutton = new cbutton (); crect rcbtn (0, 0,100, 20); m_pmybutton-> Create (text ("test "), ws_child | ws_visible | ws_tabstop | bs_pushbutton, rcbtn, this, 1000); // set the font m_pmybutton-> setfont (this-> getfont () that is the same as that in the dialog box ()); // release the resource Delete m_pmybutton;
Iii. detailed usage rules1. The group Rule ws_group of the radio button specifies the first control of the radio button group. This control group is composed of the first control and all radio buttons defined after it until the next radio button with the ws_group style. 2. getcheck and setcheck functions: Get and set the selection status int getcheck () const of the radio button and check box; Return Value: bst_unchecked, bst_checkedvoid setcheck (INT ncheck); ncheck value: bst_unchecked

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.