MFC - Command Button

A command button is an enhanced version of the regular button. It displays a green arrow icon on the left, followed by a caption in regular size. Under the main caption, it can display another smaller caption that serves as a hint to provide more information.
Create
Creates the Windows button control and attaches it to the CButton object.
DrawItem
Override to draw an owner-drawn CButton object.
GetBitmap
Retrieves the handle of the bitmap previously set with SetBitmap.
GetButtonStyle
Retrieves information about the button control style.
GetCheck
Retrieves the check state of a button control.
GetCursor
Retrieves the handle of the cursor image previously set with SetCursor.
GetIcon
Retrieves the handle of the icon previously set with SetIcon.
GetIdealSize
Retrieves the ideal size of the button control.
GetImageList
Retrieves the image list of the button control.
GetNote
Retrieves the note component of the current command link control.
GetNoteLength
Retrieves the length of the note text for the current command link control.
GetSplitGlyph
Retrieves the glyph associated with the current split button control.
GetSplitImageList
Retrieves the image list for the current split button control.
GetSplitInfo
Retrieves information that defines the current split button control.
GetSplitSize
Retrieves the bounding rectangle of the drop-down component of the current split button control.
GetSplitStyle
Retrieves the split button styles that define the current split button control.
GetState
Retrieves the check state, highlight state, and focus state of a button control.
GetTextMargin
Retrieves the text margin of the button control.
SetBitmap
Specifies a bitmap to be displayed on the button.
SetButtonStyle
Changes the style of a button.
SetCheck
Sets the check state of a button control.
SetCursor
Specifies a cursor image to be displayed on the button.
SetDropDownState
Sets the drop-down state of the current split button control.
SetIcon
Specifies an icon to be displayed on the button.
SetImageList
Sets the image list of the button control.
SetNote
Sets the note on the current command link control.
SetSplitGlyph
Associates a specified glyph with the current split button control.
SetSplitImageList
Associates an image list with the current split button control.
SetSplitInfo
Specifies information that defines the current split button control.
SetSplitSize
Sets the bounding rectangle of the drop-down component of the current split button control.
SetSplitStyle
Sets the style of the current split button control.
SetState
Sets the highlighting state of a button control.
SetTextMargin
Sets the text margin of the button control.
Here is the list of messages mapping for Command Button control −
Let us look into a simple example of command button by creating a new MFC dialog based project MFCCommandButton
Step 1 − From the Toolbox, add Command Button Control.
Step 2 − Change the Caption to My Command button.
Step 3 − Add the event handler for this button and add the following message in the event handler.
void CMFCCommandButtonDlg::OnBnClickedCommand1() {
   
   // TODO: Add your control notification handler code here
   MessageBox(L"My Command Button Clicked");
}
Step 4 − When the above code is compiled and executed, you will see the following output.
Step 5 − When the My Command Button is clicked; the following message will be displayed.
 Print
 Add Notes
 Bookmark this page