次の方法で共有


CMFCToolBarEditBoxButton Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCToolBarEditBoxButton Class.

A toolbar button that contains an edit control ( CEdit Class).

Syntax

class CMFCToolBarEditBoxButton : public CMFCToolBarButton  

Members

Public Constructors

Name Description
CMFCToolBarEditBoxButton::CMFCToolBarEditBoxButton Constructs a CMFCToolBarEditBoxButton object.
CMFCToolBarEditBoxButton::~CMFCToolBarEditBoxButton Destructor.

Public Methods

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.)

Remarks

To add an edit box button to a toolbar, follow these steps:

  1. Reserve a dummy resource ID for the button in the parent toolbar resource.

  2. Construct a CMFCToolBarEditBoxButton object.

  3. 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.

Example

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.

   CMFCToolBarEditBoxButton* boxButton = new CMFCToolBarEditBoxButton();
    boxButton->CanBeStretched();
    boxButton->HaveHotBorder();
    boxButton->SetContents(_T("edit box button"));
    boxButton->SetFlatMode(true);
    boxButton->SetStyle(TBBS_PRESSED);

Inheritance Hierarchy

CObject

CMFCToolBarButton

CMFCToolBarEditBoxButton

Requirements

Header: afxtoolbareditboxbutton.h

CMFCToolBarEditBoxButton::CanBeStretched

Specifies whether a user can stretch the button during customization.

virtual BOOL CanBeStretched() const;  

Return Value

This method returns TRUE.

Remarks

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.

CMFCToolBarEditBoxButton::CMFCToolBarEditBoxButton

Constructs a CMFCToolBarEditBoxButton object.

CMFCToolBarEditBoxButton(
    UINT uiID,  
    int iImage,  
    DWORD dwStyle=ES_AUTOHSCROLL,  
    int iWidth=0);

Parameters

[in] uiID
Specifies the control ID.

[in] iImage
Specifies the zero-based index of a toolbar image. The image is located in the CMFCToolBarImages Class object that CMFCToolBar Class class maintains.

[in] dwStyle
Specifies the edit control style.

[in] iWidth
Specifies the width in pixels of the edit control.

Remarks

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.

CMFCToolBarEditBoxButton::CopyFrom

Copies the properties of another toolbar button to the current button.

virtual void CopyFrom(const CMFCToolBarButton& src);

Parameters

[in] src
A reference to the source button from which to copy.

Remarks

Call this method to copy another toolbar button to this toolbar button. src must be of type CMFCToolBarEditBoxButton.

CMFCToolBarEditBoxButton::CreateEdit

Creates a new edit control in the button.

virtual CEdit* CreateEdit(
    CWnd* pWndParent,  
    const CRect& rect);

Parameters

[in] pWndParent
Specifies the parent window of the edit control. It must not be NULL.

[in] rect
Specifies the edit control's size and position.

Return Value

A pointer to the newly created edit control; it is NULL if the control's creation and attachment fail.

Remarks

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.

CMFCToolBarEditBoxButton::GetByCmd

Retrieves the first CMFCToolBarEditBoxButton object in the application that has the specified command ID.

static CMFCToolBarEditBoxButton* __stdcall GetByCmd(UINT uiCmd);

Parameters

[in] uiCmd
The command ID of the button to retrieve.

Return Value

The first CMFCToolBarEditBoxButton object in the application that has the specified command ID, or NULL if no such object exists.

Remarks

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.

CMFCToolBarEditBoxButton::GetContentsAll

Retrieves the text of the first edit box toolbar control that has the specified command ID.

static CString __stdcall GetContentsAll(UINT uiCmd);

Parameters

[in] uiCmd
The command ID of the button from which to retrieve contents.

Return Value

A CString object that contains the text of the first edit box toolbar control that has the specified command ID.

Remarks

This method returns the empty string if no CMFCToolBarEditBoxButton objects have the specified command ID.

CMFCToolBarEditBoxButton::GetContextMenuID

Retrieves the resource ID of the shortcut menu that is associated with the button.

UINT GetContextMenuID();

Return Value

The resource ID of the shortcut menu that is associated with the button or 0 if the button has no associated shortcut menu.

Remarks

The framework uses the resource ID to create the shortcut menu when the user right-clicks on the button.

CMFCToolBarEditBoxButton::GetEditBorder

Retrieves the bounding rectangle of the edit part of the edit box button.

virtual void GetEditBorder(CRect& rectBorder);

Parameters

[out] rectBorder
A reference to the CRect object that receives the bounding rectangle.

Remarks

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.

CMFCToolBarEditBoxButton::GetEditBox

Returns a pointer to the CEdit Class control that is embedded in the button.

CEdit* GetEditBox() const;  

Return Value

A pointer to the CEdit Class control that the button contains. It is NULL if the CEdit control has not been created yet.

Remarks

You create the CEdit control by calling CMFCToolBarEditBoxButton::CreateEdit.

CMFCToolBarEditBoxButton::GetHwnd

Retrieves the window handle that is associated with the toolbar button.

virtual HWND GetHwnd();

Return Value

The window handle that is associated with the button.

Remarks

This method overrides the CMFCToolBarButton::GetHwnd method by returning the window handle of the edit control part of the edit box button.

CMFCToolBarEditBoxButton::GetInvalidateRect

Retrieves the region of the client area of the button that must be redrawn.

virtual const CRect GetInvalidateRect() const;  

Return Value

A CRect object that specifies the region that must be redrawn.

Remarks

This method extends the base class implementation, CMFCToolBarButton::GetInvalidateRect, by including in the region the area of the text label.

CMFCToolBarEditBoxButton::HaveHotBorder

Determines whether a border of the button is displayed when a user clicks the button.

virtual BOOL HaveHotBorder() const;  

Return Value

Nonzero if a button displays its border when selected; otherwise 0.

Remarks

This method extends the base class implementation, CMFCToolBarButton::HaveHotBorder, by returning a nonzero value if the control is visible.

CMFCToolBarEditBoxButton::IsFlatMode

Determines whether edit box buttons have a flat style.

static BOOL __stdcall IsFlatMode();

Return Value

Nonzero if the buttons have a flat style; otherwise, 0.

Remarks

By default, edit box buttons have a flat style. Use the CMFCToolBarEditBoxButton::SetFlatMode method to change the flat style appearance for your application.

CMFCToolBarEditBoxButton::NotifyCommand

Specifies whether the button processes the WM_COMMAND message.

virtual BOOL NotifyCommand(int iNotifyCode);

Parameters

[in] iNotifyCode
The notification message that is associated with the command.

Return Value

TRUE if the button processes the WM_COMMAND message, or FALSE to indicate that the message must be handled by the parent toolbar.

Remarks

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.

CMFCToolBarEditBoxButton::OnAddToCustomizePage

Called by the framework when the button is added to a Customize dialog box.

virtual void OnAddToCustomizePage();

Remarks

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.

CMFCToolBarEditBoxButton::OnChangeParentWnd

Called by the framework when the button is inserted into a new toolbar.

virtual void OnChangeParentWnd(CWnd* pWndParent);

Parameters

[in] pWndParent
A pointer to the new parent window.

Remarks

This method overrides the base class implementation ( CMFCToolBarButton::OnChangeParentWnd) by recreating the internal CEdit object.

CMFCToolBarEditBoxButton::OnClick

Called by the framework when the user clicks the mouse button.

virtual BOOL OnClick(
    CWnd* pWnd,  
    BOOL bDelay = TRUE);

Parameters

[in] pWnd
Unused.

[in] bDelay
Unused.

Return Value

Nonzero if the button processes the click message; otherwise 0.

Remarks

This method overrides the base class implementation ( CMFCToolBarButton::OnClick) by returning a nonzero value if the internal CEdit object is visible.

CMFCToolBarEditBoxButton::OnCtlColor

Called by the framework when the parent toolbar handles a WM_CTLCOLOR message.

virtual HBRUSH OnCtlColor(
    CDC* pDC,  
    UINT nCtlColor);

Parameters

[in] pDC
The device context that displays the button.

[in] nCtlColor
Unused.

Return Value

A handle to the global window brush.

Remarks

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.

CMFCToolBarEditBoxButton::OnGlobalFontsChanged

Called by the framework when the global font has changed.

virtual void OnGlobalFontsChanged();

Remarks

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.

CMFCToolBarEditBoxButton::OnMove

Called by the framework when the parent toolbar moves.

virtual void OnMove();

Remarks

This method overrides the default class implementation ( CMFCToolBarButton::OnMove) by updating the position of the internal CEdit object

CMFCToolBarEditBoxButton::OnShow

Called by the framework when the button becomes visible or invisible.

virtual void OnShow(BOOL bShow);

Parameters

[in] bShow
Specifies whether the button is visible. If this parameter is TRUE, the button is visible. Otherwise, the button is not visible.

Remarks

This method extends the base class implementation ( CMFCToolBarButton::OnShow) by displaying the button if bShow is TRUE. Otherwise, this method hides the button.

CMFCToolBarEditBoxButton::OnSize

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);

Parameters

[in] iSize
The new width of the button, in pixels.

Remarks

This method overrides the default class implementation, CMFCToolBarButton::OnSize, by updating the size and position of the internal CEdit object.

CMFCToolBarEditBoxButton::OnUpdateToolTip

Called by the framework when the parent toolbar updates its tooltip text.

virtual BOOL OnUpdateToolTip(
    CWnd* pWndParent,  
    int iButtonIndex,  
    CToolTipCtrl& wndToolTip,  
    CString& str);

Parameters

[in] pWndParent
Unused.

[in] iButtonIndex
Unused.

[in] wndToolTip
The control that displays the tooltip text.

[out] str
A CString object that receives the updated tooltip text.

Return Value

Nonzero if the method updates the tooltip text; otherwise 0.

Remarks

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.

CMFCToolBarEditBoxButton::SetContents

Sets the text in the text box control.

virtual void SetContents(const CString& sContents);

Parameters

[in] sContents
Specifies the new text to set.

CMFCToolBarEditBoxButton::SetContentsAll

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);

Parameters

[in] uiCmd
Specifies the command ID of the control for which the text will be changed.

[in] strContents
Specifies the new text to set.

Return Value

Nonzero if the text was set; 0 if the CMFCToolBarEditBoxButton control with the specified command ID does not exist.

CMFCToolBarEditBoxButton::SetContextMenuID

Specifies the resource ID of the shortcut menu that is associated with the button.

void SetContextMenuID(UINT uiResID);

Parameters

[in] uiCmd
The resource ID of the shortcut menu.

Remarks

The framework uses the resource ID to create the shortcut menu when the user right-clicks the toolbar button.

CMFCToolBarEditBoxButton::SetFlatMode

Specifies the flat style appearance of edit box buttons in the application.

static void __stdcall SetFlatMode(BOOL bFlat = TRUE);

Parameters

[in] bFlat
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.

Remarks

The default flat style for edit box buttons is TRUE. Use the CMFCToolBarEditBoxButton::IsFlatMode method to retrieve the flat style appearance for your application.

CMFCToolBarEditBoxButton::SetStyle

Specifies the style of a toolbar edit box control.

virtual void SetStyle(UINT nStyle);

Parameters

[in] nStyle
A new style to set.

Remarks

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.

See Also

Hierarchy Chart
Classes
CMFCToolBarButton Class
CEdit Class
CMFCToolBar::ReplaceButton
Walkthrough: Putting Controls On Toolbars