- MFC Tutorial
- MFC - Home
- MFC - Overview
- MFC - Environment Setup
- MFC - VC++ Projects
- MFC - Getting Started
- MFC - Windows Fundamentals
- MFC - Dialog Boxes
- MFC - Windows Resources
- MFC - Property Sheets
- MFC - Windows Layout
- MFC - Controls Management
- MFC - Windows Controls
- MFC - Messages & Events
- MFC - Activex Controls
- MFC - File System
- MFC - Standard I/O
- MFC - Document View
- MFC - Strings
- MFC - Carray
- MFC - Linked Lists
- MFC - Database Classes
- MFC - Serialization
- MFC - Multithreading
- MFC - Internet Programming
- MFC - GDI
- MFC - Libraries
- MFC Useful Resources
- MFC - Quick Guide
- MFC - Useful Resources
- MFC - Discussion
MFC - Button
A button is an object that the user clicks to initiate an action. Button control is represented by CButton class.
Here is the list of messages mapping for Button control −
Message | Map entry | Description |
---|---|---|
BN_CLICKED | ON_BN_CLICKED( <id>, <memberFxn> ) | The framework calls this member function when the button is clicked. |
BN_DISABLE | ON_BN_DISABLE( <id>, <memberFxn> ) | The framework calls this member function when the button is disabled. |
BN_DOUBLECLICKED | ON_BN_DOUBLECLICKED( <id>, <memberFxn> ) | The framework calls this member function when the button is double clicked. |
BN_PAINT | ON_BN_PAINT( <id>, <memberFxn> ) | The framework calls this member function when an application makes a request to repaint a button. |
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.
mfc_windows_controls.htm
Advertisements