Implementation of Bitmap Buttons:
First, create a dialog box-based application cmydialog;
Middleware. MFC cbitmapbutton class, which is also the simplest and most powerful bitmap button. We can take the following steps:
1. specify a unique button title for the button (in this example, set the button title to OK), select the ownerdraw attribute, and add some bitmap Resources in the project, these resources are marked by their names instead of numerical IDs. The IDS are "Oku", "OKD", "okf", and "okx" (double quotation marks must be added ), it corresponds to the buttons in the "up", "down", "focused", and "Disable" statuses.
2. Add the cbitmapbutton m_abmpbtn and data member to the dialog box class.
3. Call for this member during initialization:
...
M_abmpbtn. autoload (idok, this );
...
Click the compile button to run the program. Haha, check the effect. Our bitmap button has been created.
/* If the preceding method does not work, check your bitmap resources. Resource names in appstudio, such as "Oku" and "OKD" must be enclosed by quotation marks. autoload fails, this is probably the result. */
To change the title of the cancle button, you can set the title to icon or bitmap: (Here we demonstrate the usage of Bitmap. The icon button reader can follow the following code to process it)
Ii. Use the icon to create a button
1. Open the attribute page of the icon button and select the icon in the style.
2. Define the member variable in the header file of the dialog box class (use classwizard to add this member variable)
Cbutton M _ iconbtn; // corresponds to the icon button
3. Create corresponding icons or bitmap resources:
Icon Resource: idi_iconbutton
4. Add the following code in Initialization:
...
// Corresponds to the icon button
Hicon = afxgetapp ()-> loadicon (IDI _ iconbutton );
M_iconbtn.seticon (hicon );
...
Re-compile and run our program, and the amazing image button is present in front of us.
Iii. Use bitmap to create a button
1. Open the properties page of the bitmap button and select bitmap in the style.
2. Define the member variable in the header file of the dialog box class (use classwizard to add this member variable)
Cbutton m_iconbtn;
3. Create a bitmap Resource:
Bitmap Resource: idb_bitmapbutton
4. Add the following code in Initialization:
// Corresponds to the bitmap button
...
Hbitmap hbmp =: loadbitmap (AfxGetInstanceHandle (),
Makeintresource (IDB _ bitmapbutton ));
M_bmp btn.setbitmap (hbmp );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.