CMFCButton Class
The CMFCButton class adds functionality to the CButton class such as aligning button text, combining button text and an image, selecting a cursor, and specifying a tool tip.
class CMFCButton : public CButton
Members
Public Constructors
Name |
Description |
---|---|
CMFCButton::CMFCButton |
Default constructor. |
CMFCButton::~CMFCButton |
Destructor. |
Public Methods
Name |
Description |
---|---|
Resets internal variables and frees allocated resources such as images, bitmaps, and icons. |
|
CMFCButton::CreateObject |
Used by the framework to create a dynamic instance of this class type. |
CMFCButton::DrawItem |
Called by the framework when a visual aspect of an owner-drawn button has changed. (Overrides CButton::DrawItem.) |
Specifies whether to display the full text of a tooltip in a large tooltip window or a truncated version of the text in a small tooltip window. |
|
Specifies whether the button text font is the same as the application menu font. |
|
Specifies whether the style of the button border corresponds to the current Windows theme. |
|
CMFCButton::GetThisClass |
Used by the framework to obtain a pointer to the CRuntimeClass object that is associated with this class type. |
Returns a reference to the underlying tooltip control. |
|
Indicates whether a check box or radio button is an automatic button. |
|
Indicates whether a button is set to auto-repeat mode. |
|
Indicates whether a button is a check box button. |
|
Indicates whether the current button is checked. |
|
Indicates whether a button is highlighted. |
|
Indicates whether a button is pushed and highlighted. |
|
Indicates whether a button is pushed. |
|
Indicates whether a button is a radio button. |
|
Indicates whether the style of the button border corresponds to the current Windows theme. |
|
CMFCButton::OnDrawParentBackground |
Draws the background of a button's parent in the specified area. (Overrides AFX_GLOBAL_DATA::DrawParentBackground.) |
CMFCButton::PreTranslateMessage |
Translates window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions. (Overrides CWnd::PreTranslateMessage.) |
Sets a button to auto-repeat mode. |
|
Sets the image for a checked button. |
|
Sets the background color for the button text. |
|
Sets the image for a button. |
|
Sets the cursor image. |
|
Sets the cursor to the image of a hand. |
|
Uses a CMenuImages object to set the button image. |
|
Sets the color of the button text for a button that is not selected. |
|
Sets the color of the button text for a button that is selected. |
|
Associates a tooltip with a button. |
|
Resizes a button to contain its button text and image. |
Protected Methods
Name |
Description |
---|---|
Called by the framework to draw a button. |
|
Called by the framework to draw the border of a button. |
|
Called by the framework to draw the focus rectangle for a button. |
|
Called by the framework to draw the button text. |
|
Called by the framework to draw the background of the button text. |
|
Retrieves the font that is associated with the specified device context. |
Data Members
Name |
Description |
---|---|
Indicates whether to draw a focus rectangle around a button. |
|
Indicates whether to highlight a BS_CHECKBOX-style button when the cursor hovers over it. |
|
Indicates whether to display an image on the right side of the button. |
|
Indicates whether the button is transparent. |
|
Specifies the alignment of the button text. |
|
Specifies the style of the button, such as borderless, flat, semi-flat, or 3D. |
Remarks
Other types of buttons are derived from the CMFCButton class, such as the CMFCURLLinkButton class, which supports hyperlinks, and the CMFCColorButton class, which supports a color picker dialog box.
The style of a CMFCButton object can be 3D, flat, semi-flat or no border. Button text can be aligned at the left, top, or center of a button. At run time, you can control whether the button displays text, an image, or text and an image. You can also specify that a particular cursor image be displayed when the cursor hovers over a button.
Create a button control either directly in your code, or by using the MFC Class Wizard tool and a dialog box template. If you create a button control directly, add a CMFCButton variable to your application, and then call the constructor and Create methods of the CMFCButton object. If you use the MFC Class Wizard, add a CButton variable to your application, and then change the type of the variable from CButton to CMFCButton.
To handle notification messages in a dialog box application, add a message map entry and an event handler for each notification. The notifications sent by a CMFCButton object are the same as those sent by a CButton object.
Example
The following example demonstrates how to configure the properties of the button by using various methods in the CMFCButton class. The example is part of the New Controls sample.
CMFCButton m_Button;
...
// int m_iImage
// IDB_BTN1_32, IDB_BTN1_HOT_32, IDB_BTN1, IDB_BTN1_HOT are int macros that are #define.
if (m_iImage == 1)
{
m_Button.SetImage((HBITMAP) NULL);
}
else
{
m_Button.SetImage(IDB_BTN1_32, IDB_BTN1_HOT_32);
}
...
// int m_iImage
if (m_iImage == 0)
{
m_Button.SetWindowText(_T(""));
}
else
{
m_Button.SetWindowText(_T("Button"));
}
...
// Resize the button.
m_Button.SizeToContent();
m_Button.EnableFullTextTooltip(true);
// Use the application menu font at the button text font.
m_Button.EnableMenuFont();
// Use the current Windows theme to draw the button borders.
m_Button.EnableWindowsTheming(true);
// Set the button to auto-repeat mode.
m_Button.SetAutorepeatMode();
// Set the background color for the button text.
m_Button.SetFaceColor(RGB(255,0,0),true);
m_Button.SetTextColor(RGB(0,0,255));
// Set the tooltip of the button.
m_Button.SetTooltip(_T("this is a button!"));
Inheritance Hierarchy
Requirements
Header: afxbutton.h