title | description | ms.date | f1_keywords | helpviewer_keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CMFCMenuBar Class |
Learn more about: CMFCMenuBar Class |
10/18/2018 |
|
|
A menu bar that implements docking. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.
class CMFCMenuBar : public CMFCToolbar
Name | Description |
---|---|
CMFCMenuBar::AdjustLocations | (Overrides CMFCToolBar::AdjustLocations .) |
CMFCMenuBar::AllowChangeTextLabels | Specifies whether text labels can be shown under images on the toolbar buttons. (Overrides CMFCToolBar::AllowChangeTextLabels.) |
CMFCMenuBar::AllowShowOnPaneMenu | (Overrides CPane::AllowShowOnPaneMenu .) |
CMFCMenuBar::CalcFixedLayout | Calculates the horizontal size of the toolbar. (Overrides CMFCToolBar::CalcFixedLayout.) |
CMFCMenuBar::CalcLayout | (Overrides CMFCToolBar::CalcLayout .) |
CMFCMenuBar::CalcMaxButtonHeight | Calculates the maximum height of buttons in the toolbar. (Overrides CMFCToolBar::CalcMaxButtonHeight.) |
CMFCMenuBar::CanBeClosed | Specifies whether a user can close the toolbar. (Overrides CMFCToolBar::CanBeClosed.) |
CMFCMenuBar::CanBeRestored | Determines whether the system can restore a toolbar to its original state after customization. (Overrides CMFCToolBar::CanBeRestored.) |
CMFCMenuBar::Create | Creates a menu control and attaches it to a CMFCMenuBar object. |
CMFCMenuBar::CreateEx | Creates a CMFCMenuBar object with additional style options. |
CMFCMenuBar::CreateFromMenu | Initializes a CMFCMenuBar object. Accepts a HMENU parameter that acts as a template for a populated CMFCMenuBar . |
CMFCMenuBar::EnableHelpCombobox | Enables a Help combo box that is located on the right side of the menu bar. |
CMFCMenuBar::EnableMenuShadows | Specifies whether to display shadows for pop-up menus. |
CMFCMenuBar::GetAvailableExpandSize | (Overrides CPane::GetAvailableExpandSize.) |
CMFCMenuBar::GetColumnWidth | Returns the width of the toolbar buttons. (Overrides CMFCToolBar::GetColumnWidth.) |
CMFCMenuBar::GetDefaultMenu | Returns a handle to the original menu in the resource file. |
CMFCMenuBar::GetDefaultMenuResId | Returns the resource identifier for the original menu in the resource file. |
CMFCMenuBar::GetFloatPopupDirection | |
CMFCMenuBar::GetForceDownArrows | |
CMFCMenuBar::GetHelpCombobox | Returns a pointer to the Help combo box. |
CMFCMenuBar::GetHMenu | Returns the handle to the menu that is attached to the CMFCMenuBar object. |
CMFCMenuBar::GetMenuFont | Returns the current global font for menu objects. |
CMFCMenuBar::GetMenuItem | Returns the toolbar button associated with the provided item index. |
CMFCMenuBar::GetRowHeight | Returns the height of toolbar buttons. (Overrides CMFCToolBar::GetRowHeight.) |
CMFCMenuBar::GetSystemButton | |
CMFCMenuBar::GetSystemButtonsCount | |
CMFCMenuBar::GetSystemMenu | |
CMFCMenuBar::HighlightDisabledItems | Indicates whether disabled menu items are highlighted. |
CMFCMenuBar::IsButtonExtraSizeAvailable | Determines whether the toolbar can display buttons that have extended borders. (Overrides CMFCToolBar::IsButtonExtraSizeAvailable.) |
CMFCMenuBar::IsHighlightDisabledItems | Indicates whether disabled items are highlighted. |
CMFCMenuBar::IsMenuShadows | Indicates whether shadows are drawn for pop-up menus. |
CMFCMenuBar::IsRecentlyUsedMenus | Indicates whether recently used menu commands are displayed on the menu bar. |
CMFCMenuBar::IsShowAllCommands | Indicates whether pop-up menus display all commands. |
CMFCMenuBar::IsShowAllCommandsDelay | Indicates whether menus display all the commands after a short delay. |
CMFCMenuBar::LoadState | Loads the state of the CMFCMenuBar object from the registry. |
CMFCMenuBar::OnChangeHot | Called by the framework when a user selects a button on the toolbar. (Overrides CMFCToolBar::OnChangeHot.) |
CMFCMenuBar::OnDefaultMenuLoaded | Called by the framework when a frame window loads the default menu from the resource file. |
CMFCMenuBar::OnSendCommand | (Overrides CMFCToolBar::OnSendCommand .) |
CMFCMenuBar::OnSetDefaultButtonText | Called by the framework when a menu is in customization mode and the user changes a menu item's text. |
CMFCMenuBar::OnToolHitTest | (Overrides CMFCToolBar::OnToolHitTest .) |
CMFCMenuBar::PreTranslateMessage | (Overrides CMFCToolBar::PreTranslateMessage .) |
CMFCMenuBar::RestoreOriginalstate | Called by the framework when a menu is in customization mode and the user selects Reset for a menu bar. |
CMFCMenuBar::SaveState | Saves the state of the CMFCMenuBar object to the registry. |
CMFCMenuBar::SetDefaultMenuResId | Sets the original menu in the resource file. |
CMFCMenuBar::SetForceDownArrows | |
CMFCMenuBar::SetMaximizeMode | Called by the framework when an MDI child window changes its display mode. If the MDI child window is newly maximized or is no longer maximized, this method updates the menu bar. |
CMFCMenuBar::SetMenuButtonRTC | Sets the runtime class information that is generated when the user dynamically creates menu buttons. |
CMFCMenuBar::SetMenuFont | Sets the font for all menus in the application. |
CMFCMenuBar::SetRecentlyUsedMenus | Specifies whether a menu bar displays recently used menu commands. |
CMFCMenuBar::SetShowAllCommands | Specifies whether the menu bar shows all commands. |
The CMFCMenuBar
class is a menu bar that implements docking functionality. It resembles a toolbar, although it cannot be closed - it is always displayed.
CMFCMenuBar
supports the option of displaying recently used menu item objects. If this option is enabled, the CMFCMenuBar
displays only a subset of the available commands on first viewing. Thereafter, recently used commands are displayed together with the original subset of commands. In addition, the user can always expand the menu to view all available commands. Thus, each available command is configured to display constantly, or to display only if it has been recently selected.
To use a CMFCMenuBar
object, embed it in the main window frame object. When processing the WM_CREATE
message, call CMFCMenuBar::Create
or CMFCMenuBar::CreateEx
. Regardless of which create function you use, pass in a pointer to the main frame window. Then enable docking by calling CFrameWndEx::EnableDocking. Dock this menu by calling CFrameWndEx::DockPane.
The following example demonstrates how to use various methods in the CMFCMenuBar
class. The example shows how to set the style of the pane, enable the customize button, enable a Help box, enable shadows for pop-up menus, and update the menu bar. This code snippet is part of the IE Demo sample.
[!code-cppNVC_MFC_IEDemo#1] [!code-cppNVC_MFC_IEDemo#3]
CMFCMenuBar
Header: afxmenubar.h
Adjusts the positions of the menu items on the menu bar.
virtual void AdjustLocations();
Determines whether text labels are allowed under images in the menu bar.
virtual BOOL AllowChangeTextLabels() const;
Returns TRUE if the user can choose to show text labels under images.
virtual BOOL AllowShowOnPaneMenu() const;
virtual CSize CalcFixedLayout(
BOOL bStretch,
BOOL bHorz);
[in] bStretch
[in] bHorz
virtual CSize CalcLayout(
DWORD dwMode,
int nLength = -1);
[in] dwMode
[in] nLength
virtual int CalcMaxButtonHeight();
virtual BOOL CanBeClosed() const;
virtual BOOL CanBeRestored() const;
Creates a menu control and attaches it to a CMFCMenuBar object.
virtual BOOL Create(
CWnd* pParentWnd,
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE,
UINT nID = AFX_IDW_MENUBAR);
pParentWnd
[in] Pointer to the parent window for the new CMFCMenuBar
object.
dwStyle
[in] The style of the new menu bar.
nID
[in] The ID for the child window of the menu bar.
TRUE if successful; otherwise FALSE.
After you construct a CMFCMenuBar
object, you must call Create
. This method creates the CMFCMenuBar
control and attaches it to the CMFCMenuBar
object.
For more information about toolbar styles, see CBasePane::SetPaneStyle.
Creates a CMFCMenuBar object with specified extended styles.
virtual BOOL CreateEx(
CWnd* pParentWnd,
DWORD dwCtrlStyle = TBSTYLE_FLAT,
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE,
CRect rcBorders = CRect(1,
1,
1,
1),
UINT nID =AFX_IDW_MENUBAR);
pParentWnd
[in] Pointer to the parent window of the new CMFCMenuBar
object.
dwCtrlStyle
[in] Additional styles for the new menu bar.
dwStyle
[in] The main style of the new menu bar.
rcBorders
[in] A CRect
parameter that specifies the sizes for the borders of the CMFCMenuBar
object.
nID
[in] The ID for the child window of the menu bar.
Nonzero if the method is successful; otherwise 0.
You should use this function instead of CMFCMenuBar::Create when you want to specify styles in addition to the toolbar style. Some frequently used additional styles are TBSTYLE_TRANSPARENT and CBRS_TOP.
For lists of additional styles, see Toolbar Control and Button Styles, common control styles, and common window styles.
The following example demonstrates how to use the CreateEx
method of the CMFCMenuBar
class. This code snippet is part of the IE Demo sample.
[!code-cppNVC_MFC_IEDemo#1] [!code-cppNVC_MFC_IEDemo#2]
Initializes a CMFCMenuBar object. This method models the CMFCMenuBar
object after a HMENU parameter.
virtual void CreateFromMenu(
HMENU hMenu,
BOOL bDefaultMenu = FALSE,
BOOL bForceUpdate = FALSE);
hMenu
[in] A handle to a menu resource. CreateFromMenu
uses this resource as a template for the CMFCMenuBar
.
bDefaultMenu
[in] A Boolean that indicates whether the new menu is the default menu.
bForceUpdate
[in] A Boolean that indicates whether this method forces a menu update.
Use this method if you want a menu control to have the same menu items as a menu resource. You call this method after you call either CMFCMenuBar::Create or CMFCMenuBar::CreateEx.
Enables a Help combo box that is located on the right side of the menu bar.
void EnableHelpCombobox(
UINT uiID,
LPCTSTR lpszPrompt = NULL,
int nComboBoxWidth = 150);
uiID
[in] The command ID for the button of the Help combo box.
lpszPrompt
[in] A string that contains the text that the framework displays in the combo box if it is empty and not active. For example, "Enter the text here".
nComboBoxWidth
[in] The width of the button for the combo box in pixels.
The Help combo box resembles the Help combo box in the menu bar of Microsoft Word.
When you call this method with uiID set to 0, this method hides the combo box. Otherwise, this method displays the combo box automatically on the right side of your menu bar. After you call this method, call CMFCMenuBar::GetHelpCombobox to obtain a pointer to the inserted CMFCToolBarComboBoxButton object.
Enables shadows for pop-up menus.
static void EnableMenuShadows(BOOL bEnable = TRUE);
bEnable
[in] A Boolean parameter that indicates whether shadows should be enabled for pop-up menus.
The algorithm that this method uses is complex and may decrease the performance of your application on slower systems.
virtual int GetAvailableExpandSize() const;
virtual int GetColumnWidth() const;
Retrieves a handle to the original menu. The framework loads the original menu from the resource file.
HMENU GetDefaultMenu() const;
A handle to a menu resource.
If your application customizes a menu, you can use this method to retrieve a handle to the original menu.
Retrieves the resource identifier for the default menu.
UINT GetDefaultMenuResId() const;
A menu resource identifier.
The framework loads the default menu for the CMFCMenuBar
object from the resource file.
int GetFloatPopupDirection(CMFCToolBarMenuButton* pButton);
[in] pButton
BOOL GetForceDownArrows();
Returns a pointer to the Help combo box.
CMFCToolBarComboBoxButton* GetHelpCombobox();
A pointer to the Help combo box. NULL if the Help combo box is hidden or not enabled.
The Help combo box is located on the right side of the menu bar. Call the method CMFCMenuBar::EnableHelpCombobox to enable this combo box.
Retrieves the handle to the menu attached to the CMFCMenuBar object.
HMENU GetHMenu() const;
Retrieves the current menu font.
static const CFont& GetMenuFont(BOOL bHorz = TRUE);
bHorz
[in] A Boolean parameter that specifies whether to return the horizontal or vertical font. TRUE indicates the horizontal font.
A pointer to a CFont parameter that contains the current menu bar font.
The returned font is a global parameter for the application. Two global fonts are maintained for all CMFCMenuBar
objects. These separate fonts are used for horizontal and vertical menu bars.
Retrieves a CMFCToolBarButton object on a menu bar based on the item index.
CMFCToolBarButton* GetMenuItem(int iItem) const;
iItem
[in] The index of the menu item to return.
A pointer to the CMFCToolBarButton
object that matches the index specified by iItem. NULL if the index is invalid.
virtual int GetRowHeight() const;
CMFCToolBarMenuButtonsButton* GetSystemButton(
UINT uiBtn,
BOOL bByCommand = TRUE) const;
[in] uiBtn
[in] bByCommand
int GetSystemButtonsCount() const;
CMFCToolBarSystemMenuButton* GetSystemMenu() const;
Controls whether the framework highlights disabled menu items.
static void HighlightDisabledItems(BOOL bHighlight = TRUE);
bHighlight
[in] A Boolean parameter that indicates whether the framework highlights unavailable menu items.
By default, the framework does not highlight unavailable menu items when the user positions the mouse pointer over them.
virtual BOOL IsButtonExtraSizeAvailable() const;
Indicates whether the framework highlights unavailable menu items.
static BOOL IsHighlightDisabledItems();
TRUE if unavailable menu items are highlighted; otherwise FALSE.
By default, the framework does not highlight unavailable menu items when the user positions the mouse pointer over them. Use the CMFCMenuBar::HighlightDisabledItems method to enable this feature.
Indicates whether the framework draws shadows for pop-up menus.
static BOOL IsMenuShadows();
TRUE if the framework draws menu shadows; otherwise FALSE.
Use the CMFCMenuBar::EnableMenuShadows method to enable or disable this feature.
Indicates whether recently used menu commands are displayed on the menu bar.
static BOOL IsRecentlyUsedMenus();
Nonzero if the CMFCMenuBar
object shows recently used menu commands; otherwise 0.
Use the function CMFCMenuBar::SetRecentlyUsedMenus to control whether the menu bar shows recently used menu commands.
Indicates whether menus display all commands.
static BOOL IsShowAllCommands();
Nonzero if the CMFCMenuBar
displays all commands; otherwise 0.
A CMFCMenuBar
object can be configured to either show all commands or show only a subset of commands. For more information about this feature, see CMFCMenuBar Class.
IsShowAllCommands
will tell you how this feature is configured for the CMFCMenuBar
object. To control which menu commands are shown, use the methods CMFCMenuBar::SetShowAllCommands and CMFCMenuBar::SetRecentlyUsedMenus.
Indicates whether the CMFCMenuBar object displays all the commands after a short delay.
static BOOL IsShowAllCommandsDelay();
Nonzero if the menu bar displays full menus after a short delay; otherwise 0.
When you configure a menu bar to display recently used items, the menu bar displays the full menu in one of two ways:
-
Display the full menu after a programmed delay from when the user hovers the cursor over the arrow at the bottom of the menu.
-
Display the full menu after the user clicks the arrow at the bottom of the menu.
By default, all CMFCMenuBar
objects use the option to display the full menu after a short delay. This option cannot be changed programmatically in the CMFCMenuBar
class. However, a user can change the behavior during toolbar customization by using the Customize dialog box.
Loads the state of the menu bar from the Windows registry.
virtual BOOL LoadState(
LPCTSTR lpszProfileName = NULL,
int nIndex = -1,
UINT uiID = (UINT)-1);
lpszProfileName
[in] A string that contains the path of a Windows registry key.
nIndex
[in] The control ID for the menu bar.
uiID
[in] A reserved value.
TRUE if the method was successful; otherwise FALSE.
Use the CMFCMenuBar::SaveState method to save the state of the menu bar to the registry. The saved information includes the menu items, the dock state, and the position of the menu bar.
In most cases your application does not call LoadState
. The framework calls this method when it initializes the workspace.
virtual void OnChangeHot(int iHot);
[in] iHot
The framework calls this method when it loads the menu resource from the resource file.
virtual void OnDefaultMenuLoaded(HMENU hMenu);
hMenu
[in] The handle for the menu attached to the CMFCMenuBar
object.
The default implementation of this function does nothing. Override this function to execute custom code after the framework loads a menu resource from the resource file.
virtual BOOL OnSendCommand(const CMFCToolBarButton* pButton);
[in] pButton
The framework calls this method when the user changes the text of an item on the menu bar.
virtual BOOL OnSetDefaultButtonText(CMFCToolBarButton* pButton);
pButton
[in] A pointer to the CMFCToolBarButton object that the user wants to customize.
TRUE if the framework applies the user changes to the menu bar; otherwise FALSE.
The default implementation for this method changes the text of the button to the text that the user provides.
virtual INT_PTR OnToolHitTest(
CPoint point,
TOOLINFO* pTI) const;
[in] point
[in] pTI
virtual BOOL PreTranslateMessage(MSG* pMsg);
[in] pMsg
Called by the framework when the user selects Reset from the Customize dialog box.
virtual BOOL RestoreOriginalstate();
Nonzero if the method is successful; otherwise 0.
This method is called when the user selects Reset from the customization menu. You can also manually call this method to programmatically reset the state of the menu bar. This method loads the original state from the resource file.
Override this method if you want to do any processing when the user selects the Reset option.
Saves the state of the CMFCMenuBar object to the Windows registry.
virtual BOOL SaveState (
LPCTSTR lpszProfileName = NULL,
int nIndex = -1,
UINT uiID = (UINT)-1);
lpszProfileName
[in] A string that contains the path of a Windows registry key.
nIndex
[in] The control ID for the menu bar.
uiID
[in] A reserved value.
TRUE if successful; otherwise FALSE;
Usually, your application does not call SaveState
. The framework calls this method when the workspace is serialized. For more information, see CWinAppEx::SaveState.
The saved information includes the menu items, the dock state, and the position of the menu bar.
Sets the default menu for a CMFCMenuBar object based on the resource ID.
void SetDefaultMenuResId(UINT uiResId);
uiResId
[in] The resource ID for the new default menu.
The CMFCMenuBar::RestoreOriginalstate method restores the default menu from the resource file.
Use the CMFCMenuBar::GetDefaultMenuResId method to retrieve the default menu without restoring it.
void SetForceDownArrows(BOOL bValue);
[in] bValue
The framework calls this method when a MDI changes its display mode and the menu bar must be updated.
void SetMaximizeMode(
BOOL bMax,
CWnd* pWnd = NULL,
BOOL bRecalcLayout = TRUE);
bMax
[in] A Boolean that specifies the mode. See the Remarks section for more information.
pWnd
[in] A pointer to the MDI child window that is changing.
bRecalcLayout
[in] A Boolean that specifies whether the layout of the menu bar should be recalculated immediately.
When an MDI child window is maximized, a menu bar attached to the MDI main frame window displays the system menu and the Minimize, Maximize and Close buttons. If bMax is TRUE and pWnd is not NULL, the MDI child window is maximized and the menu bar must incorporate the extra controls. Otherwise, the menu bar returns to its regular state.
Sets the runtime class information that the framework uses when the user creates menu buttons.
void SetMenuButtonRTC(CRuntimeClass* pMenuButtonRTC);
pMenuButtonRTC
[in] The CRuntimeClass information for a class derived from the CMFCMenuButton Class.
When a user adds new buttons to the menu bar, the framework creates the buttons dynamically. By default, it creates CMFCMenuButton
objects. Override this method to change the type of button objects that the framework creates.
Sets the font for all menu bars in your application.
static BOOL SetMenuFont(
LPLOGFONT lpLogFont,
BOOL bHorz = TRUE);
lpLogFont
[in] A pointer to a LOGFONT structure that defines the font to set.
bHorz
[in] TRUE if you want the lpLogFont parameter to be used for the vertical font, FALSE if you want it to be used for horizontal font.
TRUE if the method was successful; otherwise FALSE.
Two fonts are used for all CMFCMenuBar
objects. These separate fonts are used for horizontal and vertical menu bars.
The font settings are global variables and affect all CMFCMenuBar
objects.
Controls whether a menu bar displays recently used menu commands.
static void SetRecentlyUsedMenus (BOOL bOn = TRUE);
bOn
[in] A Boolean that controls whether recently used menu commands are displayed.
Controls whether a menu shows all the available commands.
static void SetShowAllCommands(BOOL bShowAllCommands = TRUE);
bShowAllCommands
[in] A Boolean parameter that specifies whether the pop-up menu shows all the menu commands.
If a menu does not display all the menu commands, it hides the commands that are rarely used. For more information about displaying menu commands, see CMFCMenuBar Class.