BOOL Create( const char FAR* lpCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
lpCaption
Specifies the button control's text.
dwStyle
Specifies the button control's style.
rect
Specifies the button control's size and position. It can be either a CRect object or a RECT structure.
pParentWnd
Specifies the button control's parent window, usually a CDialog or CModalDialog. It must not be NULL.
nID
Specifies the button control's resource ID.
You construct a CButton object in two steps. First call the constructor, then call Create, which creates the Windows button control and attaches it to the CButton object.
When Create executes, Windows sends the WM_NCCREATE, WM_CREATE, WM_NCCALCSIZE, and WM_GETMINMAXINFO messages to the button control.
These messages are handled by default by the OnNcCreate, OnCreate, OnNcCalcSize, and OnGetMinMaxInfo member functions in the CWnd base class. To extend the default message handling, derive a class from CButton, add a message map to the new class, and override the preceding message-handler member functions. Override OnCreate, for example, to perform needed initialization for a new class.
To handle Windows notification messages that the CButton object sends to its parent, add any of the following message-map entries that you want to process to the parent-class message map:
ON_COMMAND
ON_BN_CLICKED
ON_BN_DOUBLECLICKED
If the WS_VISIBLE style is given, Windows sends the button control all the messages required to activate and show the button.
Apply the following window styles to a button control:
Style | Application |
WS_CHILD | Always. |
WS_VISIBLE | Usually. |
WS_DIABLED | Rarely. |
WS_GROUP | To group controls. |
WS_TABSTOP | To include the button in the tabbing order. |
See CreateEx in the CWnd base class for a full description of these window styles.
Use any combination of the following button styles for dwStyle:
Value | Meaning |
BS_AUTOCHECKBOX | Same as a check box, except that an appears in the check box when the user selects the box; the disappears the next time the user selects the box. |
BS_AUTORADIOBUTTON | Same as a radio button, except that when the user selects it, the button automatically highlights itself and removes the selection from any other radio buttons with the same style in the same group. |
BS_AUTO3STATE | Same as a three-state check box, except that the box changes its state when the user selects it. The state cycles through checked, dimmed, and normal. |
BS_CHECKBOX | Creates a small square that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). |
BS_DEFPUSHBUTTON | Creates a button that has a heavy black border. The user can select this button by pressing the ENTER key. This style is useful for enabling the user to quickly select the most likely option (the default option). |
BS_GROUPBOX | Creates a rectangle in which other buttons can be grouped. Any text associated with this style is displayed in the rectangle's upper-left corner. |
BS_LEFTTEXT | When combined with a radio-button or check-box style, the text appears on the left side of the radio button or check box. |
BS_OWNERDRAW | Creates an owner-draw button. The owner window receives a WM_MEASUREITEM message when the button is created and a WM_DRAWITEM message when a visual aspect of the button has changed. |
BS_PUSHBUTTON | Creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button. |
BS_RADIOBUTTON | Creates a small circle that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). Radio buttons are usually used in groups of related but mutually exclusive choices. |
BS_3STATE | Same as a check box, except that the box can be dimmed as well as checked. The dimmed state typically is used to show that a check box has been disabled. |
TRUE if successful; otherwise FALSE.