Key methods and events for button controls see mfc++ Program Development Reference (P186-P188)
Here is an example of using buttons to display bitmaps, display icons, display mouse images, and select buttons in the following steps:
1. Create a dialog-based application
2. Add a Check button to the dialog box, a radio button control, and 5 button controls to add variables for the button control, M_button1, M_button2, M_button3, respectively.
3. Import an ICO icon into the factory. A BMP bitmap and a cur mouse image.
4. Implement button display bitmap function
void Cbuttondlg::onbutton1 ()
{
M_button1.modifystyle (0,BS_BITMAP); Setting the Bitmap property
M_button1.setbitmap (LoadBitmap (AfxGetInstanceHandle (),
Makeintresource (IDB_BITMAP1)); Set bitmap
}
5. Implement button Display icon function
void Cbuttondlg::onbutton2 ()
{
M_button2.modifystyle (0,bs_icon); Set the Icon property
M_button2.seticon (AfxGetApp ()->loadicon (Idi_icon1)); Set icon
}
6. Implement button display mouse function
void Cbuttondlg::onbutton3 ()
{
M_button3.modifystyle (0,bs_icon); Set the Icon property
M_button3.setcursor (AfxGetApp ()->loadcursor (Idc_cursor1)); Set Mouse image
}
7. Implement the Check button function
void Cbuttondlg::onbutton4 ()
{
cbutton* M_button = (cbutton*) GetDlgItem (IDC_CHECK1); To point the button pointer to a check button
M_button->setcheck (TRUE);//Make the Check button selected
M_button = (cbutton*) GetDlgItem (IDC_RADIO1);//Make button pointer point to radio button
M_button->setcheck (TRUE);//Make radio button selected
}
8. Uncheck Button function
void Cbuttondlg::onbutton5 ()
{
cbutton* M_button = (cbutton*) GetDlgItem (IDC_CHECK1);
M_button->setcheck (FALSE);
M_button = (cbutton*) GetDlgItem (IDC_RADIO1);
M_button->setcheck (FALSE);
}
MFC buttons Control (button)