MFC - Button

A button is an object that the user clicks to initiate an action. Button control is represented by CButton class.
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 Button control −
Let us look into a simple example by dragging two buttons from the Toolbox.
Step 1 − Change the Caption from Start, Stop and ID to IDC_BUTTON_START, IDC_BUTTON_STOP for both buttons.
Step 2 − Let us add event handler for both buttons.
Step 3 − Here is an implementation of both events in which we will start and stop animation.
void CMFCAnimationDemoDlg::OnBnClickedButtonStart() {
   
   // TODO: Add your control notification handler code here
   m_animationCtrl.Open(L"res\\copyfile.avi");
}

void CMFCAnimationDemoDlg::OnBnClickedButtonStop() {
   
   // TODO: Add your control notification handler code here
   m_animationCtrl.Stop();
}
Step 4 − When the above code is compiled and executed, you will see the following output.
Step 5 − When you click the Stop button, the animation stops and when you press the Start button, it starts again.
 Print
 Add Notes
 Bookmark this page