Edit

Share via


CMFCPopupMenu Class

Implements Windows pop-up menu functionality and extends it by adding features such as tear-off menus and tooltips. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

Syntax

class CMFCPopupMenu : public CMiniFrameWnd

Members

Protected Constructors

Name Description
CMFCPopupMenu::CMFCPopupMenu Constructs a CMFCPopupMenu object.

Public Methods

Name Description
CMFCPopupMenu::ActivatePopupMenu
CMFCPopupMenu::AlwaysShowEmptyToolsEntry Sets whether a pop-up menu is enabled to show empty entries for user-defined tools.
CMFCPopupMenu::AreAllCommandsShown
CMFCPopupMenu::CheckArea Determines the location of a point relative to the pop-up menu.
CMFCPopupMenu::CloseMenu
CMFCPopupMenu::Create Creates a pop-up menu and attaches it to the CMFCPopupMenu object.
CMFCPopupMenu::DefaultMouseClickOnClose
CMFCPopupMenu::EnableMenuLogo Initializes the logo for a pop-up menu.
CMFCPopupMenu::EnableMenuSound Enables menu sound.
CMFCPopupMenu::EnableResize
CMFCPopupMenu::EnableScrolling
CMFCPopupMenu::EnableVertResize
CMFCPopupMenu::FindSubItemByCommand
CMFCPopupMenu::GetActiveMenu Returns the currently active menu.
CMFCPopupMenu::GetAnimationSpeed Returns the animation speed for pop-up menus.
CMFCPopupMenu::GetAnimationType Returns the current type of pop-up menu animation.
CMFCPopupMenu::GetDropDirection
CMFCPopupMenu::GetForceMenuFocus Indicates whether the focus is returned to the menu bar when a pop-up menu is displayed.
CMFCPopupMenu::GetForceShadow
CMFCPopupMenu::GetHMenu Returns a handle to the attached menu resource.
CMFCPopupMenu::GetMenuBar Returns the CMFCPopupMenuBar embedded inside the pop-up menu.
CMFCPopupMenu::GetMenuItem Returns a pointer to the menu item at the specified index.
CMFCPopupMenu::GetMenuItemCount Returns the number of items in a popup menu.
CMFCPopupMenu::GetMessageWnd Returns a pointer to the window where the framework routes the pop-up menu messages.
CMFCPopupMenu::GetParentArea
CMFCPopupMenu::GetParentButton Returns a pointer to the parent toolbar button.
CMFCPopupMenu::GetParentPopupMenu Returns a pointer to the parent pop-up menu.
CMFCPopupMenu::GetParentRibbonElement
CMFCPopupMenu::GetParentToolBar Returns a pointer to the parent toolbar.
CMFCPopupMenu::GetQuickCustomizeType
CMFCPopupMenu::GetSelItem Returns a pointer to the currently selected menu command.
CMFCPopupMenu::HasBeenResized
CMFCPopupMenu::HideRarelyUsedCommands Indicates whether the pop-up menu can hide rarely used commands.
CMFCPopupMenu::InCommand
CMFCPopupMenu::InsertItem Inserts a new item into the pop-up menu at the specified location.
CMFCPopupMenu::InsertSeparator Inserts a separator into the pop-up menu at the specified location.
CMFCPopupMenu::IsAlwaysClose
CMFCPopupMenu::IsAlwaysShowEmptyToolsEntry
CMFCPopupMenu::IsCustomizePane Indicates whether the pop-up menu is functioning as a QuickCustomizePane.
CMFCPopupMenu::IsEscClose
CMFCPopupMenu::IsIdle Indicates whether a pop-up menu is currently idle.
CMFCPopupMenu::IsMenuSound
CMFCPopupMenu::IsQuickCustomize Determines whether the associated CMFCToolBarMenuButton Class is in QuickCustomize mode.
CMFCPopupMenu::IsResizeble
CMFCPopupMenu::IsRightAlign Indicates whether the menu is right-aligned or left-aligned.
CMFCPopupMenu::IsScrollable
CMFCPopupMenu::IsSendMenuSelectMsg Indicates whether the framework notifies the parent frame when the user selects a command from the pop-up menu.
CMFCPopupMenu::IsShown Indicates whether the pop-up menu is currently visible.
CMFCPopupMenu::MoveTo
CMFCPopupMenu::OnCmdMsg (Overrides CFrameWnd::OnCmdMsg.)
CMFCPopupMenu::PostCommand
CMFCPopupMenu::PreTranslateMessage (Overrides CFrameWnd::PreTranslateMessage.)
CMFCPopupMenu::RecalcLayout Called by the framework when the standard control bars are toggled on or off or when the frame window is resized. (Overrides CFrameWnd::RecalcLayout.)
CMFCPopupMenu::RemoveAllItems Clears all the items from a pop-up menu.
CMFCPopupMenu::RemoveItem Removes the specified item from a pop-up menu.
CMFCPopupMenu::SaveState
CMFCPopupMenu::SetAnimationSpeed Sets the animation speed for pop-up menus.
CMFCPopupMenu::SetAnimationType Sets the animation type for the pop-up menu.
CMFCPopupMenu::SetAutoDestroy
CMFCPopupMenu::SetDefaultItem Sets the default command for the pop-up menu.
CMFCPopupMenu::SetForceMenuFocus Forces the input focus to return to the menu bar when a pop-up menu is displayed.
CMFCPopupMenu::SetForceShadow Forces the framework to draw menu shadows when pop-up menus appear outside the main frame.
CMFCPopupMenu::SetMaxWidth Set the maximum width for the pop-up menu.
CMFCPopupMenu::SetMessageWnd
CMFCPopupMenu::SetParentRibbonElement
CMFCPopupMenu::SetQuickCustomizeType
CMFCPopupMenu::SetQuickMode
CMFCPopupMenu::SetRightAlign Sets the menu alignment for pop-up menus.
CMFCPopupMenu::SetSendMenuSelectMsg Sets a flag that controls whether the pop-up menu notifies its parent frame when the user selects a command.
CMFCPopupMenu::ShowAllCommands Forces the pop-up menu to display all commands.
CMFCPopupMenu::TriggerResize
CMFCPopupMenu::UpdateAllShadows Updates the shadows for all opened pop-up menus.
CMFCPopupMenu::UpdateShadow Updates the shadow for the pop-up menu.

Protected Methods

Name Description
CMFCPopupMenu::CreateTearOffBar
CMFCPopupMenu::OnChangeHot
CMFCPopupMenu::OnChooseItem

Remarks

Normally, MFC creates pop-up menus automatically. If you want to create a CMFCPopupMenu object manually, allocate one on the heap and then call CMFCPopupMenu::Create.

Example

The following example demonstrates how to configure a pop-up menu object. The example shows how to set the logo and the sound of the pop-up menu, set the animation speed and type, draw menu shadows when the pop-up menu appears outside the main frame, set the maximum width, and set the right menu alignment of the pop-up menu. This code snippet is part of the Custom Pages sample.

// 30 is the size of the logo in pixels.
pPopupMenu->EnableMenuLogo(30);
pPopupMenu->EnableMenuSound();
// 500 is the animation speed in milliseconds.
pPopupMenu->SetAnimationSpeed(500);
pPopupMenu->SetAnimationType(CMFCPopupMenu::SLIDE);
pPopupMenu->SetForceShadow(true);
// 200 is the maximum width of the pop-up menu in pixels.
pPopupMenu->SetMaxWidth(200);
pPopupMenu->SetRightAlign();
pPopupMenu->InsertSeparator();

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CFrameWnd

CMiniFrameWnd

CMFCPopupMenu

Requirements

Header: afxpopupmenu.h

CMFCPopupMenu::ActivatePopupMenu

static BOOL __stdcall ActivatePopupMenu(
    CFrameWnd* pTopFrame,
    CMFCPopupMenu* pPopupMenu);

Parameters

[in] pTopFrame
[in] pPopupMenu

Return Value

Remarks

CMFCPopupMenu::AlwaysShowEmptyToolsEntry

Sets whether a pop-up menu is enabled to show empty entries for user-defined tools.

static void AlwaysShowEmptyToolsEntry(BOOL bShow = TRUE);

Parameters

bShow
[in] TRUE if the pop-up menu can display empty entries; FALSE otherwise.

CMFCPopupMenu::AreAllCommandsShown

BOOL AreAllCommandsShown() const;

Return Value

Remarks

CMFCPopupMenu::CheckArea

Determines the location of a point relative to the pop-up menu.

MENUAREA_TYPE CheckArea(const CPoint& ptScreen) const;

Parameters

ptScreen
[in] A point, in screen coordinates.

Return Value

A MENUAREA_TYPE parameter that indicates where the point is relative to the pop-up menu.

Remarks

A MENUAREA_TYPE parameter can have any one of the following values.

  • OUTSIDE - ptScreen is outside the pop-up menu.

  • LOGO - ptScreen is over a logo area.

  • TEAROFF_CAPTION - ptScreen is over the tear-off caption.

  • SHADOW_BOTTOM - ptScreen is over the bottom shadow of the pop-up menu.

  • SHADOW_RIGHT - ptScreen is over the right shadow of the pop-up menu.

  • MENU - ptScreen is over a command.

CMFCPopupMenu::CloseMenu

void CloseMenu(BOOL bSetFocusToBar = FALSE);

Parameters

[in] bSetFocusToBar

Remarks

CMFCPopupMenu::CMFCPopupMenu

Constructs a CMFCPopupMenu object.

CMFCPopupMenu(
    CMFCToolBarsMenuPropertyPage* pCustPage,
    LPCTSTR lpszTitle);

Parameters

pCustPage
[in] A pointer to a customization page.

lpszTitle
[in] A string that contains the menu caption.

Remarks

This method allocates the resources for a CMFCPopupMenu. To create the pop-up menu item, call CMFCPopupMenu::Create.

CMFCPopupMenu::Create

Creates a pop-up menu and attaches it to a CMFCPopupMenu object.

virtual BOOL Create(
    CWnd* pWndParent,
    int x,
    int y,
    HMENU hMenu,
    BOOL bLocked = FALSE,
    BOOL bOwnMessage = FALSE);

Parameters

pWndParent
[in] The parent window for the CMFCPopupMenu.

x
[in] The horizontal screen coordinate for the location of the pop-up menu

y
[in] The vertical screen coordinate for the location of the pop-menu.

hMenu
[in] A handle to a menu resource.

bLocked
[in] A Boolean parameter that indicates whether the menu is customizable. FALSE indicates that the pop-up menu is customizable.

bOwnMessage
[in] A Boolean parameter that indicates how the framework routes the menu messages. See the Remarks section for more details.

Return Value

TRUE if the method is successful; otherwise FALSE.

Remarks

If bOwnMessage is TRUE, the framework routes any menu messages to pWndParent. pWndParent must not be NULL if bOwnMessage is TRUE. If bOwnMessage is FALSE, the framework routes the menu messages to the parent pop-up menu.

Example

The following example demonstrates how to use the Create method of the CMFCPopuMenu class. This code snippet is part of the Custom Pages sample.

CMFCPopupMenu *pPopupMenu = new CMFCPopupMenu;
// CPoint point
// CMenu* pPopup
// The this pointer points to CMainFrame class which extends the CFrameWnd class.
pPopupMenu->Create(this, point.x, point.y, pPopup->Detach());

CMFCPopupMenu::CreateTearOffBar

virtual CPane* CreateTearOffBar(
    CFrameWnd* pWndMain,
    UINT uiID,
    LPCTSTR lpszName);

Parameters

[in] pWndMain
[in] uiID
[in] lpszName

Return Value

Remarks

CMFCPopupMenu::DefaultMouseClickOnClose

virtual BOOL DefaultMouseClickOnClose() const;

Return Value

Remarks

Initializes the logo for a pop-up menu.

void EnableMenuLogo(
    int iLogoSize,
    LOGO_LOCATION nLogoLocation = MENU_LOGO_LEFT);

Parameters

iLogoSize
[in] The size of the logo, in pixels.

nLogoLocation
[in] An enumerated data type that indicates the location of the logo.

Remarks

To display the logo, implement the method CFrameWndEx::OnDrawMenuLogo in the main frame window.

The possible values for nLogoLocation are MENU_LOGO_LEFT, MENU_LOGO_RIGHT, MENU_LOGO_TOP, and MENU_LOGO_BOTTOM.

CMFCPopupMenu::EnableMenuSound

Enables menu sound.

static void EnableMenuSound(BOOL bEnable = TRUE);

Parameters

bEnable
[in] TRUE to enable sound, FALSE otherwise.

Remarks

If you enable sound, the framework calls the PlaySound method when a user opens a pop-up menu or selects a menu command. By default, this feature is enabled.

CMFCPopupMenu::EnableResize

void EnableResize(CSize sizeMinResize);

Parameters

[in] sizeMinResize

Remarks

CMFCPopupMenu::EnableScrolling

void EnableScrolling(BOOL = TRUE);

Parameters

[in] BOOL

Remarks

CMFCPopupMenu::EnableVertResize

void EnableVertResize(int nMinResize);

Parameters

[in] nMinResize

Remarks

CMFCPopupMenu::FindSubItemByCommand

CMFCToolBarMenuButton* FindSubItemByCommand(UINT uiCmd) const;

Parameters

[in] uiCmd

Return Value

Remarks

CMFCPopupMenu::GetActiveMenu

Returns the currently active menu.

static CMFCPopupMenu* GetActiveMenu();

Return Value

A pointer to the active pop-up menu, or NULL if no pop-up menu is currently active.

Remarks

Each application can have at most one active pop-up menu.

CMFCPopupMenu::GetAnimationSpeed

Returns the animation speed for pop-up menus.

static UINT GetAnimationSpeed();

Return Value

An integer that indicates the time, in milliseconds, that a pop-up menu animation takes to finish.

Remarks

The animation speed is a global value. Use CMFCPopupMenu::SetAnimationSpeed to change the animation speed for pop-up menus.

CMFCPopupMenu::GetAnimationType

Returns the current type of pop-up animation.

static CMFCPopupMenu::ANIMATION_TYPE GetAnimationType(BOOL bNoSystem = FALSE);

Parameters

bNoSystem
[in] A Boolean parameter that indicates whether this method checks the global value. FALSE if you want this method to return the animation style for this instance of the CMFCPopupMenu Class.

Return Value

An enumerated value that describes the animation type.

Remarks

The style of animation for pop-up menus is global for your application. Use CMFCPopupMenu::SetAnimationType to set the animation style.

The following table lists the possible animation types.

Value Description
NO_ANIMATION The pop-up menu is not animated and appears immediately.
UNFOLD The framework reveals the pop-up menu from the upper-left corner to the lower right corner.
SLIDE The pop-up menu moves from top to bottom.
FADE The pop-up menu first appears transparent and gradually solidifies.

CMFCPopupMenu::GetDropDirection

DROP_DIRECTION GetDropDirection() const;

Return Value

Remarks

CMFCPopupMenu::GetForceMenuFocus

Indicates whether the focus is returned to the menu bar when a pop-up menu is displayed.

static BOOL GetForceMenuFocus();

Return Value

TRUE if the input focus is returned to the menu bar when a pop-up menu is displayed; FALSE if the pop-up menu retains the focus.

Remarks

By default, your application does not return focus to the menu bar. To change this setting, use CMFCPopupMenu::SetForceMenuFocus.

CMFCPopupMenu::GetForceShadow

static BOOL __stdcall GetForceShadow();

Return Value

Remarks

CMFCPopupMenu::GetHMenu

Returns a handle to the attached menu resource.

HMENU GetHMenu();

CMFCPopupMenu::GetMenuBar

Returns the CMFCPopupMenuBar embedded inside the pop-up menu.

virtual CMFCPopupMenuBar* GetMenuBar();

Return Value

A pointer to the embedded CMFCPopupMenuBar.

Remarks

The pop-up menu has an embedded CMFCPopupMenuBar object. You must override this method in a derived class if you are using a different embedded class.

CMFCPopupMenu::GetMenuItem

Returns a pointer to the menu item at the specified index.

CMFCToolBarMenuButton* GetMenuItem(int iIndex) const;

Parameters

iIndex
[in] The zero-based index of a menu item.

Return Value

A pointer to a menu item. NULL if the index is invalid.

Remarks

Menu items are represented by the CMFCToolBarMenuButton Class. When you call this method, it returns a pointer to the appropriate CMFCToolBarMenuButton.

CMFCPopupMenu::GetMenuItemCount

Returns the number of items in a pop-up menu.

int GetMenuItemCount() const;

Return Value

The number of items in the menu.

CMFCPopupMenu::GetMessageWnd

Returns a pointer to the window where the framework routes the pop-up menu messages.

CWnd* GetMessageWnd() const;

Return Value

A pointer to the window that receives the pop-up menu messages; NULL if there is no window.

Remarks

When you use the method CMFCPopupMenu::Create to create a pop-up menu, you specify what window receives the menu messages.

CMFCPopupMenu::GetParentArea

virtual CWnd* GetParentArea(CRect& rectParentBtn);

Parameters

[in] rectParentBtn

Return Value

Remarks

CMFCPopupMenu::GetParentButton

Returns a pointer to the parent toolbar button.

CMFCToolBarMenuButton* GetParentButton() const;

Return Value

A pointer to the parent toolbar button. NULL if the pop-up menu has no parent toolbar button.

Remarks

A CMFCPopupMenu can be associated with a button on the menu. In this scenario, the pop-up menu appears when a user selects the parent toolbar button.

If the pop-up menu is a shortcut menu, it will have no parent toolbar button.

CMFCPopupMenu::GetParentPopupMenu

Returns a pointer to the parent pop-up menu.

CMFCPopupMenu* GetParentPopupMenu() const;

Return Value

A pointer to the parent CMFCPopupMenu object; NULL if there is no parent pop-up menu.

Remarks

A pop-up menu has a parent CMFCPopupMenu object only if it is a submenu.

CMFCPopupMenu::GetParentRibbonElement

CMFCRibbonBaseElement* GetParentRibbonElement() const;

Return Value

Remarks

CMFCPopupMenu::GetParentToolBar

Returns a pointer to the parent toolbar.

CMFCToolBar* GetParentToolBar() const;

Return Value

A pointer to the parent toolbar. NULL if the pop-up menu has no parent toolbar.

Remarks

If the CMFCPopupMenu is a shortcut menu, then it has no parent toolbar.

CMFCPopupMenu::GetQuickCustomizeType

QUICK_CUSTOMIZE_TYPE GetQuickCustomizeType() const;

Return Value

Remarks

CMFCPopupMenu::GetSelItem

Returns a pointer to the currently selected menu command.

CMFCToolBarMenuButton* GetSelItem();

Return Value

A pointer to the currently selected menu command; NULL if no item is selected.

Remarks

The menu commands on a pop-up menu are represented by the CMFCToolBarMenuButton Class, or a class derived from CMFCToolBarMenuButton.

CMFCPopupMenu::HasBeenResized

BOOL HasBeenResized() const;

Return Value

Remarks

CMFCPopupMenu::HideRarelyUsedCommands

Indicates whether the pop-up menu can hide rarely used commands.

BOOL HideRarelyUsedCommands() const;

Return Value

TRUE if the pop-up menu can hide the rarely used commands; otherwise FALSE.

Remarks

This method specifies only whether a pop-up menu can hide rarely used commands, not if that configuration is enabled. A pop-up menu can hide rarely used commands if it has a parent button and the parent window is derived from the CMFCMenuBar Class. Use CMFCMenuBar::SetRecentlyUsedMenus to enable this feature and CMFCMenuBar::IsRecentlyUsedMenus to determine if this feature is currently enabled. You must call both of these methods for the parent window.

CMFCPopupMenu::InCommand

virtual BOOL InCommand();

Return Value

Remarks

CMFCPopupMenu::InsertItem

Inserts a new item into the pop-up menu at the specified location.

int InsertItem(
    const CMFCToolBarMenuButton& button,
    int iInsertA = -1);

Parameters

button
[in] A reference to the menu item to add.

iInsertAt
[in] The zero-based index for the new item. If iInsertAt is -1, the item is added to the end of the menu.

Return Value

The zero-based index of the position where the item was inserted. -1 if the method fails.

Remarks

This method will fail if you provide an invalid value for iInsertAt, such as an integer larger than the number of items currently on the pop-up menu.

CMFCPopupMenu::InsertSeparator

Inserts a separator into the pop-up menu at the specified location.

int InsertSeparator(int iInsertAt = -1);

Parameters

iInsertAt
[in] The zero-based index of the position where this method will insert the separator.

Return Value

The zero-based index of the position where the separator was inserted. -1 if this method fails.

Remarks

A value of -1 for iInsertAt means this method will add the separator to the end of the pop-up menu.

This method fails if iInsertAt is an invalid value.

CMFCPopupMenu::IsAlwaysClose

virtual BOOL IsAlwaysClose() const;

Return Value

Remarks

CMFCPopupMenu::IsAlwaysShowEmptyToolsEntry

static BOOL __stdcall IsAlwaysShowEmptyToolsEntry();

Return Value

Remarks

CMFCPopupMenu::IsCustomizePane

Indicates whether the pop-up menu is functioning as a QuickCustomizePane.

BOOL IsCustomizePane();

Return Value

TRUE if the pop-up is a QuckCustomizePane; otherwise FALSE.

Remarks

Use the QuickCustomizePane to enable the user to directly customize the pop-up menu. The QuickCustomizePane is a CMFCPopupMenu that appears when the user clicks on a toolbar button to edit it directly.

Your application should call this method during CMDIFrameWndEx::OnShowCustomizePane.

CMFCPopupMenu::IsEscClose

BOOL IsEscClose();

Return Value

Remarks

CMFCPopupMenu::IsIdle

Indicates whether a pop-up menu is currently idle.

virtual BOOL IsIdle() const;

Return Value

TRUE if the pop-up menu is in idle mode; otherwise FALSE.

Remarks

By default, a pop-up menu is in idle mode if the display animation is complete and the user is not scrolling the pop-up menu.

CMFCPopupMenu::IsMenuSound

static UINT __stdcall IsMenuSound();

Return Value

Remarks

CMFCPopupMenu::IsQuickCustomize

Determines whether the associated CMFCToolBarMenuButton Class is in QuickCustomize mode.

BOOL IsQuickCustomize();

Return Value

TRUE if the associated menu button is in QuickCustomize mode; otherwise FALSE. This method will also return FALSE if the pop-up menu is not associated with a CMFCToolBarMenuButton.

Remarks

In QuickCustomize mode the user selects a button on a toolbar to customize the button directly.

CMFCPopupMenu::IsResizeble

BOOL IsResizeble() const;

Return Value

Remarks

CMFCPopupMenu::IsRightAlign

Indicates whether the menu is right-aligned or left-aligned.

BOOL IsRightAlign() const;

Return Value

TRUE if the menu is right-aligned; FALSE if the menu left-aligned.

Remarks

You can use CMFCPopupMenu::SetRightAlign to set the menu alignment. By default, pop-up menus use left-alignment.

Menu alignment is not a global setting and can vary between pop-up menus.

CMFCPopupMenu::IsScrollable

BOOL IsScrollable() const;

Return Value

Remarks

CMFCPopupMenu::IsSendMenuSelectMsg

Indicates whether the framework notifies the parent frame when the user selects a command from the pop-up menu.

static BOOL IsSendMenuSelectMsg();

Return Value

TRUE if the framework notifies the parent frame; otherwise FALSE.

Remarks

The framework notifies the parent frame by sending it the WM_MENUSELECT message when a used selects a menu command.

CMFCPopupMenu::IsShown

Indicates whether the pop-up menu is currently visible.

BOOL IsShown() const;

Return Value

TRUE if a pop-up menu is visible; otherwise FALSE.

CMFCPopupMenu::MoveTo

void MoveTo(const CPoint& pt);

Parameters

[in] pt

Remarks

CMFCPopupMenu::OnChangeHot

virtual void OnChangeHot(int nHot);

Parameters

[in] nHot

Remarks

CMFCPopupMenu::OnChooseItem

virtual void OnChooseItem(UINT uidCmdID);

Parameters

[in] uidCmdID

Remarks

CMFCPopupMenu::OnCmdMsg

virtual BOOL OnCmdMsg(
    UINT nID,
    int nCode,
    void* pExtra,
    AFX_CMDHANDLERINFO* pHandlerInfo);

Parameters

[in] nID
[in] nCode
[in] pExtra
[in] pHandlerInfo

Return Value

Remarks

CMFCPopupMenu::PostCommand

BOOL PostCommand(UINT uiCommandID);

Parameters

[in] uiCommandID

Return Value

Remarks

CMFCPopupMenu::PreTranslateMessage

virtual BOOL PreTranslateMessage(MSG* pMsg);

Parameters

[in] pMsg

Return Value

Remarks

CMFCPopupMenu::RecalcLayout

virtual void RecalcLayout(BOOL bNotify = TRUE);

Parameters

[in] bNotify

Remarks

CMFCPopupMenu::RemoveAllItems

Clears all the items from a pop-up menu.

void RemoveAllItems();

CMFCPopupMenu::RemoveItem

Removes the specified item from the pop-up menu.

BOOL RemoveItem(int iIndex);

Parameters

iIndex
[in] The zero-based index of the item to delete.

Return Value

TRUE if the method is successful; otherwise FALSE.

Remarks

This method automatically arranges any separators that are affected by the removal of an item. For more information about how the framework rearranges separators, see CMFCToolBar::RemoveButton.

CMFCPopupMenu::SaveState

virtual void SaveState();

Remarks

CMFCPopupMenu::SetAnimationSpeed

Sets the animation speed for pop-up menus.

static void SetAnimationSpeed(UINT nElapse);

Parameters

nElapse
[in] The new animation speed, in milliseconds.

Remarks

The animation speed is a global value and affects all the pop-up menus in the application. This value specifies how long it takes for the animation for a pop-up menu to finish.

By default, this parameter is set to 30 milliseconds. The range of valid values for nElapse is from 0 to 200.

CMFCPopupMenu::SetAnimationType

Sets the animation type for this pop-up menu.

static void SetAnimationType(CMFCPopupMenu::ANIMATION_TYPE type);

Parameters

type
[in] An enumerated data type that specifies the type of animation.

Remarks

See CMFCPopupMenu::GetAnimationType for a list of valid values for type.

CMFCPopupMenu::SetAutoDestroy

void SetAutoDestroy(BOOL bAutoDestroy = TRUE);

Parameters

[in] bAutoDestroy

Remarks

CMFCPopupMenu::SetDefaultItem

Sets the default command for the pop-up menu.

void SetDefaultItem(UINT uiCmd);

Parameters

uiCmd
[in] The menu command ID of the new default command.

Remarks

The default command in the pop-up menu is the command that is selected when the pop-up menu appears.

CMFCPopupMenu::SetForceMenuFocus

Forces the input focus to return to the menu bar when a pop-up menu is displayed.

static void SetForceMenuFocus(BOOL bValue);

Parameters

bValue
[in] TRUE if you want the framework to force the input focus to the menu bar when a pop-up menu is displayed. FALSE if you want the pop-up menu to retain the focus.

Remarks

This method sets a flag that is global for all pop-up menus in the application. By default, this feature is not enabled.

CMFCPopupMenu::SetForceShadow

Forces the framework to draw menu shadows when pop-up menus appear outside the main frame.

static void SetForceShadow(BOOL bValue);

Parameters

bValue
[in] TRUE if you want the framework to draw menu shadows, FALSE otherwise.

Remarks

When you call this method, it sets a global flag in your application. This flag affects all pop-up menus in your application.

CMFCPopupMenu::SetMaxWidth

Set the maximum width for the pop-up menu.

void SetMaxWidth(int iMaxWidth);

Parameters

iMaxWidth
[in] The maximum width for the pop-up menu, in pixels.

Remarks

If the text associated with a menu command will not fit in the maximum width, it is truncated and the part that does not fit is replaced by three dots.

CMFCPopupMenu::SetMessageWnd

void SetMessageWnd(CWnd* pMsgWnd);

Parameters

[in] pMsgWnd

Remarks

CMFCPopupMenu::SetParentRibbonElement

void SetParentRibbonElement(CMFCRibbonBaseElement* pElem);

Parameters

[in] pElem

Remarks

CMFCPopupMenu::SetQuickCustomizeType

void SetQuickCustomizeType(QUICK_CUSTOMIZE_TYPE Type);

Parameters

[in] Type

Remarks

CMFCPopupMenu::SetQuickMode

void SetQuickMode();

Remarks

CMFCPopupMenu::SetRightAlign

Sets the menu alignment for pop-up menus.

void SetRightAlign(BOOL bRightAlign = TRUE);

Parameters

bRightAlign
[in] A Boolean that indicates the menu alignment. TRUE indicates right alignment, FALSE indicates left alignment.

Remarks

By default, all pop-up menus are left-aligned.

CMFCPopupMenu::SetSendMenuSelectMsg

Sets a flag that controls whether the pop-up menu notifies its parent frame when the user selects a command.

static void SetSendMenuSelectMsg(BOOL bSet = TRUE);

Parameters

bSet
[in] TRUE if the pop-up menu notifies its parent frame, FALSE otherwise.

Remarks

This is a global option for all the pop-up menus in an application. If it is enabled, the pop-up menus will send a WM_MENUSELECT message to the parent frame when the user selects a command.

CMFCPopupMenu::ShowAllCommands

Forces the pop-up menu to display all commands.

void ShowAllCommands();

Remarks

This is not a global setting and affects only the current pop-up menu.

CMFCPopupMenu::TriggerResize

void TriggerResize();

Remarks

CMFCPopupMenu::UpdateAllShadows

Updates the shadows for all opened pop-up menus.

static void UpdateAllShadows(LPRECT lprectScreen = NULL);

Parameters

lprectScreen
[in] A rectangle that specifies the region to update, in screen coordinates.

Remarks

This method is useful when pop-up menus are displayed over animated controls or other windows that have dynamic content.

CMFCPopupMenu::UpdateShadow

Updates the shadow for the pop-up menu.

void UpdateShadow(LPRECT lprectScreen = NULL);

Parameters

lprectScreen
[in] A rectangle, in screen coordinates, that specifies the boundaries of the region to update.

Remarks

Call this method when a pop-up menu that has a shadow overlaps an animated image.

See also

Hierarchy Chart
Classes
CMFCPopupMenuBar Class