description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CMFCToolBarEditBoxButton Class |
CMFCToolBarEditBoxButton Class |
11/04/2016 |
|
|
b21d9b67-6bf7-4ca9-bd62-b237756e0ab3 |
A toolbar button that contains an edit control ( CEdit Class).
class CMFCToolBarEditBoxButton : public CMFCToolBarButton
Name | Description |
---|---|
CMFCToolBarEditBoxButton::CMFCToolBarEditBoxButton | Constructs a CMFCToolBarEditBoxButton object. |
CMFCToolBarEditBoxButton::~CMFCToolBarEditBoxButton |
Destructor. |
Name | Description |
---|---|
CMFCToolBarEditBoxButton::CanBeStretched | Specifies whether a user can stretch the button during customization. (Overrides CMFCToolBarButton::CanBeStretched.) |
CMFCToolBarEditBoxButton::CopyFrom | Copies the properties of another toolbar button to the current button. (Overrides CMFCToolBarButton::CopyFrom.) |
CMFCToolBarEditBoxButton:: CMFCToolBarEditBoxButton::CreateEdit |
Creates a new edit control in the button. |
CMFCToolBarEditBoxButton::CreateObject |
Used by the framework to create a dynamic instance of this class type. |
CMFCToolBarEditBoxButton::GetByCmd | Retrieves the first CMFCToolBarEditBoxButton object in the application that has the specified command ID. |
CMFCToolBarEditBoxButton::GetContentsAll | Retrieves the text of the first edit box toolbar control that has the specified command ID. |
CMFCToolBarEditBoxButton::GetContextMenuID | Retrieves the resource ID of the shortcut menu that is associated with the button. |
CMFCToolBarEditBoxButton::GetEditBorder | Retrieves the bounding rectangle of the edit part of the edit box button. |
CMFCToolBarEditBoxButton:: CMFCToolBarEditBoxButton::GetEditBox |
Returns a pointer to the edit control that is embedded in the button. |
CMFCToolBarEditBoxButton::GetHwnd | Retrieves the window handle that is associated with the toolbar button. (Overrides CMFCToolBarButton::GetHwnd.) |
CMFCToolBarEditBoxButton::GetInvalidateRect | Retrieves the region of the client area of the button that must be redrawn. (Overrides CMFCToolBarButton::GetInvalidateRect.) |
CMFCToolBarEditBoxButton::GetThisClass |
Used by the framework to obtain a pointer to the CRuntimeClass object that is associated with this class type. |
CMFCToolBarEditBoxButton::HaveHotBorder | Determines whether a border of the button is displayed when a user clicks the button. (Overrides CMFCToolBarButton::HaveHotBorder.) |
CMFCToolBarEditBoxButton::IsFlatMode | Determines whether edit box buttons have a flat style. |
CMFCToolBarEditBoxButton::NotifyCommand | Specifies whether the button processes the WM_COMMAND message. (Overrides CMFCToolBarButton::NotifyCommand.) |
CMFCToolBarEditBoxButton::OnAddToCustomizePage | Called by the framework when the button is added to a Customize dialog box. (Overrides CMFCToolBarButton::OnAddToCustomizePage.) |
CMFCToolBarEditBoxButton::OnCalculateSize |
Called by the framework to calculate the size of the button for the specified device context and docking state. (Overrides CMFCToolBarButton::OnCalculateSize.) |
CMFCToolBarEditBoxButton::OnChangeParentWnd | Called by the framework when the button is inserted into a new toolbar. (Overrides CMFCToolBarButton::OnChangeParentWnd.) |
CMFCToolBarEditBoxButton::OnClick | Called by the framework when the user clicks the mouse button. (Overrides CMFCToolBarButton::OnClick.) |
CMFCToolBarEditBoxButton::OnCtlColor | Called by the framework when the parent toolbar handles a WM_CTLCOLOR message. (Overrides CMFCToolBarButton::OnCtlColor.) |
CMFCToolBarEditBoxButton::OnDraw |
Called by the framework to draw the button by using the specified styles and options. (Overrides CMFCToolBarButton::OnDraw.) |
CMFCToolBarEditBoxButton::OnDrawOnCustomizeList |
Called by the framework to draw the button in the Commands pane of the Customize dialog box. (Overrides CMFCToolBarButton::OnDrawOnCustomizeList.) |
CMFCToolBarEditBoxButton::OnGlobalFontsChanged | Called by the framework when the global font has changed. (Overrides CMFCToolBarButton::OnGlobalFontsChanged.) |
CMFCToolBarEditBoxButton::OnMove | Called by the framework when the parent toolbar moves. (Overrides CMFCToolBarButton::OnMove.) |
CMFCToolBarEditBoxButton::OnShow | Called by the framework when the button becomes visible or invisible. (Overrides CMFCToolBarButton::OnShow.) |
CMFCToolBarEditBoxButton::OnSize | Called by the framework when the parent toolbar changes its size or position and this change causes the button to change size. (Overrides CMFCToolBarButton::OnSize.) |
CMFCToolBarEditBoxButton::OnUpdateToolTip | Called by the framework when the parent toolbar updates its tooltip text. (Overrides CMFCToolBarButton::OnUpdateToolTip.) |
CMFCToolBarEditBoxButton::Serialize |
Reads this object from an archive or writes it to an archive. (Overrides CMFCToolBarButton::Serialize.) |
CMFCToolBarEditBoxButton::SetACCData |
Populates the provided CAccessibilityData object with accessibility data from the toolbar button. (Overrides CMFCToolBarButton::SetACCData.) |
CMFCToolBarEditBoxButton:: CMFCToolBarEditBoxButton::SetContents |
Sets the text in the edit control of the button. |
CMFCToolBarEditBoxButton:: CMFCToolBarEditBoxButton::SetContentsAll |
Finds the edit control button that has a specified command ID, and sets the text in the edit control of that button. |
CMFCToolBarEditBoxButton::SetContextMenuID | Specifies the resource ID of the shortcut menu that is associated with the button. |
CMFCToolBarEditBoxButton::SetFlatMode | Specifies the flat style appearance of edit box buttons in the application. |
CMFCToolBarEditBoxButton:: CMFCToolBarEditBoxButton::SetStyle |
Specifies the style of the button. (Overrides CMFCToolBarButton::SetStyle.) |
To add an edit box button to a toolbar, follow these steps:
-
Reserve a dummy resource ID for the button in the parent toolbar resource.
-
Construct a
CMFCToolBarEditBoxButton
object. -
In the message handler that processes the AFX_WM_RESETTOOLBAR message, replace the dummy button with the new combo box button by using CMFCToolBar::ReplaceButton.
For more information, see Walkthrough: Putting Controls On Toolbars.
The following example demonstrates how to use various methods in the CMFCToolBarEditBoxButton
class. The example shows how to specify that a user can stretch the button during customization, specify that a border of the button is displayed when a user clicks the button, set the text in the text box control, specify the flat style appearance of edit box buttons in the application, and specify the style of a toolbar edit box control.
[!code-cppNVC_MFC_RibbonApp#40]
CMFCToolBarEditBoxButton
Header: afxtoolbareditboxbutton.h
Specifies whether a user can stretch the button during customization.
virtual BOOL CanBeStretched() const;
This method returns TRUE.
By default, the framework does not allow the user to stretch a toolbar button during customization. This method extends the base class implementation ( CMFCToolBarButton::CanBeStretched) by allowing the user to stretch an edit box toolbar button during customization.
Constructs a CMFCToolBarEditBoxButton object.
CMFCToolBarEditBoxButton(
UINT uiID,
int iImage,
DWORD dwStyle=ES_AUTOHSCROLL,
int iWidth=0);
uiID
[in] Specifies the control ID.
iImage
[in] Specifies the zero-based index of a toolbar image. The image is located in the CMFCToolBarImages Class object that CMFCToolBar Class class maintains.
dwStyle
[in] Specifies the edit control style.
iWidth
[in] Specifies the width in pixels of the edit control.
The default constructor sets the edit control style to the following combination:
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL
The default width of the control is 150 pixels.
Copies the properties of another toolbar button to the current button.
virtual void CopyFrom(const CMFCToolBarButton& src);
src
[in] A reference to the source button from which to copy.
Call this method to copy another toolbar button to this toolbar button. src must be of type CMFCToolBarEditBoxButton
.
Creates a new edit control in the button.
virtual CEdit* CreateEdit(
CWnd* pWndParent,
const CRect& rect);
pWndParent
[in] Specifies the parent window of the edit control. It must not be NULL.
rect
[in] Specifies the edit control's size and position.
A pointer to the newly created edit control; it is NULL if the control's creation and attachment fail.
You construct a CMFCToolBarEditBoxButton
object in two steps. First call the constructor, and then call CreateEdit
, which creates the Windows edit control and attaches it to the CMFCToolBarEditBoxButton
object.
Retrieves the first CMFCToolBarEditBoxButton
object in the application that has the specified command ID.
static CMFCToolBarEditBoxButton* __stdcall GetByCmd(UINT uiCmd);
uiCmd
[in] The command ID of the button to retrieve.
The first CMFCToolBarEditBoxButton
object in the application that has the specified command ID, or NULL if no such object exists.
This shared utility method is used by methods such as CMFCToolBarEditBoxButton::SetContentsAll and CMFCToolBarEditBoxButton::GetContentsAll to set or get the text of the first edit box toolbar control that has the specified command ID.
Retrieves the text of the first edit box toolbar control that has the specified command ID.
static CString __stdcall GetContentsAll(UINT uiCmd);
uiCmd
[in] The command ID of the button from which to retrieve contents.
A CString
object that contains the text of the first edit box toolbar control that has the specified command ID.
This method returns the empty string if no CMFCToolBarEditBoxButton
objects have the specified command ID.
Retrieves the resource ID of the shortcut menu that is associated with the button.
UINT GetContextMenuID();
The resource ID of the shortcut menu that is associated with the button or 0 if the button has no associated shortcut menu.
The framework uses the resource ID to create the shortcut menu when the user right-clicks on the button.
Retrieves the bounding rectangle of the edit part of the edit box button.
virtual void GetEditBorder(CRect& rectBorder);
rectBorder
[out] A reference to the CRect
object that receives the bounding rectangle.
This method retrieves the bounding rectangle of the edit control in client coordinates. It expands the size of the rectangle in each direction by one pixel.
The CMFCVisualManager::OnDrawEditBorder method calls this method when it draws the border around a CMFCToolBarEditBoxButton
object.
Returns a pointer to the CEdit Class control that is embedded in the button.
CEdit* GetEditBox() const;
A pointer to the CEdit Class control that the button contains. It is NULL if the CEdit
control has not been created yet.
You create the CEdit
control by calling CMFCToolBarEditBoxButton::CreateEdit.
Retrieves the window handle that is associated with the toolbar button.
virtual HWND GetHwnd();
The window handle that is associated with the button.
This method overrides the CMFCToolBarButton::GetHwnd method by returning the window handle of the edit control part of the edit box button.
Retrieves the region of the client area of the button that must be redrawn.
virtual const CRect GetInvalidateRect() const;
A CRect
object that specifies the region that must be redrawn.
This method extends the base class implementation, CMFCToolBarButton::GetInvalidateRect, by including in the region the area of the text label.
Determines whether a border of the button is displayed when a user clicks the button.
virtual BOOL HaveHotBorder() const;
Nonzero if a button displays its border when selected; otherwise 0.
This method extends the base class implementation, CMFCToolBarButton::HaveHotBorder, by returning a nonzero value if the control is visible.
Determines whether edit box buttons have a flat style.
static BOOL __stdcall IsFlatMode();
Nonzero if the buttons have a flat style; otherwise, 0.
By default, edit box buttons have a flat style. Use the CMFCToolBarEditBoxButton::SetFlatMode method to change the flat style appearance for your application.
Specifies whether the button processes the WM_COMMAND message.
virtual BOOL NotifyCommand(int iNotifyCode);
iNotifyCode
[in] The notification message that is associated with the command.
TRUE if the button processes the WM_COMMAND message, or FALSE to indicate that the message must be handled by the parent toolbar.
The framework calls this method when it is about to send a WM_COMMAND message to the parent window.
This method extends the base class implementation ( CMFCToolBarButton::NotifyCommand) by processing the EN_UPDATE notification. For each edit box with the same command ID as this object, it sets its text label to the text label of this object.
Called by the framework when the button is added to a Customize dialog box.
virtual void OnAddToCustomizePage();
This method extends the base class implementation ( CMFCToolBarButton::OnAddToCustomizePage) by copying the properties from the edit box control in any toolbar that has the same command ID as this object. This method does nothing if no toolbar has an edit box control that has the same command ID as this object.
For more information about the Customize dialog box, see CMFCToolBarsCustomizeDialog Class.
Called by the framework when the button is inserted into a new toolbar.
virtual void OnChangeParentWnd(CWnd* pWndParent);
pWndParent
[in] A pointer to the new parent window.
This method overrides the base class implementation ( CMFCToolBarButton::OnChangeParentWnd) by recreating the internal CEdit
object.
Called by the framework when the user clicks the mouse button.
virtual BOOL OnClick(
CWnd* pWnd,
BOOL bDelay = TRUE);
pWnd
[in] Unused.
bDelay
[in] Unused.
Nonzero if the button processes the click message; otherwise 0.
This method overrides the base class implementation ( CMFCToolBarButton::OnClick) by returning a nonzero value if the internal CEdit
object is visible.
Called by the framework when the parent toolbar handles a WM_CTLCOLOR message.
virtual HBRUSH OnCtlColor(
CDC* pDC,
UINT nCtlColor);
pDC
[in] The device context that displays the button.
nCtlColor
[in] Unused.
A handle to the global window brush.
This method overrides the base class implementation ( CMFCToolBarButton::OnCtlColor) by setting the text and background colors of the provided device context to the global text and background colors, respectively.
For more information about global options that are available to your application, see AFX_GLOBAL_DATA Structure.
Called by the framework when the global font has changed.
virtual void OnGlobalFontsChanged();
This method extends the base class implementation ( CMFCToolBarButton::OnGlobalFontsChanged) by changing the font of the control to that of the global font.
For more information about global options that are available to your application, see AFX_GLOBAL_DATA Structure.
Called by the framework when the parent toolbar moves.
virtual void OnMove();
This method overrides the default class implementation ( CMFCToolBarButton::OnMove) by updating the position of the internal CEdit
object
Called by the framework when the button becomes visible or invisible.
virtual void OnShow(BOOL bShow);
bShow
[in] Specifies whether the button is visible. If this parameter is TRUE, the button is visible. Otherwise, the button is not visible.
This method extends the base class implementation ( CMFCToolBarButton::OnShow) by displaying the button if bShow is TRUE. Otherwise, this method hides the button.
Called by the framework when the parent toolbar changes its size or position and this change causes the button to change size.
virtual void OnSize(int iSize);
iSize
[in] The new width of the button, in pixels.
This method overrides the default class implementation, CMFCToolBarButton::OnSize, by updating the size and position of the internal CEdit
object.
Called by the framework when the parent toolbar updates its tooltip text.
virtual BOOL OnUpdateToolTip(
CWnd* pWndParent,
int iButtonIndex,
CToolTipCtrl& wndToolTip,
CString& str);
pWndParent
[in] Unused.
iButtonIndex
[in] Unused.
wndToolTip
[in] The control that displays the tooltip text.
str
[out] A CString
object that receives the updated tooltip text.
Nonzero if the method updates the tooltip text; otherwise 0.
This method extends the base class implementation ( CMFCToolBarButton::OnUpdateToolTip) by displaying the tooltip text that is associated with the edit part of the button. If the internal CEdit
object is NULL or the window handle of the CEdit
object does not identify an existing window, this method does nothing and returns FALSE.
Sets the text in the text box control.
virtual void SetContents(const CString& sContents);
sContents
[in] Specifies the new text to set.
Finds a CMFCToolBarEditBoxButton object that has a specified command ID and sets the specified text within its text box.
static BOOL SetContentsAll(
UINT uiCmd,
const CString& strContents);
uiCmd
[in] Specifies the command ID of the control for which the text will be changed.
strContents
[in] Specifies the new text to set.
Nonzero if the text was set; 0 if the CMFCToolBarEditBoxButton
control with the specified command ID does not exist.
Specifies the resource ID of the shortcut menu that is associated with the button.
void SetContextMenuID(UINT uiResID);
uiCmd
[in] The resource ID of the shortcut menu.
The framework uses the resource ID to create the shortcut menu when the user right-clicks the toolbar button.
Specifies the flat style appearance of edit box buttons in the application.
static void __stdcall SetFlatMode(BOOL bFlat = TRUE);
bFlat
[in] The flat style for edit box buttons. If this parameter is TRUE, the flat style appearance is enabled; otherwise the flat style appearance is disabled.
The default flat style for edit box buttons is TRUE. Use the CMFCToolBarEditBoxButton::IsFlatMode method to retrieve the flat style appearance for your application.
Specifies the style of a toolbar edit box control.
virtual void SetStyle(UINT nStyle);
nStyle
[in] A new style to set.
This method sets CMFCToolBarButton::m_nStyle to nStyle It also disables the text box when the application is in Customize mode, and enables it when the application is not in Customize mode (see CMFCToolBar::SetCustomizeMode and CMFCToolBar::IsCustomizeMode). See ToolBar Control Styles for a list of valid style flags.
Hierarchy Chart
Classes
CMFCToolBarButton Class
CEdit Class
CMFCToolBar::ReplaceButton
Walkthrough: Putting Controls On Toolbars