A windows menu. Encapsulates an MFC CMenu
class
-
Appends a new item to the end of a menu. Python can specify the state of the menu item by setting values in nFlags.
-
Deletes the specified menu item.
-
Enables, disables, or dims a menu item.
-
Returns the menu object's underlying hMenu.
-
Determines the number of items in a menu.
-
Returns the item ID for the specified item in a pop-up menu.
-
Returns the string for a specified menu item.
-
Returns a submenu.
-
Inserts an item into a menu.
-
Modify an item in a menu.
-
Creates a popup menu anywhere on the screen.
PyCMenu.AppendMenu
AppendMenu(flags, id, value) Appends a new item to the end of a menu. Python can specify the state of the menu item by setting values in nFlags.
-
flags : int
Specifies information about the state of the new menu item when it is added to the menu. May be a combination of the win32con.MF_* values.
-
id=0 : int
Specifies either the command ID of the new menu item.
-
value=None : string/None
Specifies the content of the new menu item. If used, flags must contain win32con.MF_STRING.
PyCMenu.DeleteMenu
string = DeleteMenu(id, flags
) Deletes the specified menu item.
-
id : int
The id of the item being deleted.
-
flags : int
Specifies how the id parameter is interpreted. It must be one of win32con.MF_BYCOMMAND or win32con.MF_BYPOSITION.
PyCMenu.EnableMenuItem
int = EnableMenuItem(id, flags
) Enables, disables, or dims a menu item.
-
id : int
Specifies the command ID of the menu item. This parameter can specify pop-up menu items as well as standard menu items.
-
flags : int
Specifies the action to take. It can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION
The PyCMenu::CreateMenu
, PyCMenu::InsertMenu, PyCMenu::ModifyMenu,
and PyCMenu::LoadMenuIndirect
member functions can also set the state
(enabled, disabled, or dimmed) of a menu item.
PyCMenu.GetHandle
int = GetHandle() Returns the menu object's underlying hMenu.
PyCMenu.GetMenuItemCount
int = GetMenuItemCount() Determines the number of items in a menu.
The number of items in the menu if the function is successful; otherwise -1.
PyCMenu.GetMenuItemID
int = GetMenuItemID(pos) Returns the item ID for the specified item in a pop-up menu.
-
pos : int
The position (zero-based) of the menu item whose ID is being retrieved.
If the specified item is a pop-up menu (as opposed to an item within the pop-up menu),
the return value is -1. If nPos corresponds to a SEPARATOR menu item,
the return value is 0.
PyCMenu.GetMenuString
string = GetMenuString(id, flags
) Returns the string for a specified menu item.
-
id : int
The id of the item being requested.
-
flags=win32con.MF_BYCOMMAND : int
Specifies how the id parameter is interpreted. It must be one of win32con.MF_BYCOMMAND or win32con.MF_BYPOSITION.
PyCMenu.GetSubMenu
PyCMenu = GetSubMenu(pos) Returns a submenu.
-
pos : int
The position (zero-based) of the menu item being retrieved.
PyCMenu.InsertMenu
InsertMenu(pos, flags, id, value) Inserts an item into a menu.
-
pos : int
The position (zero-based) the item should be inserted.
-
flags : int
Flags for the new item.
-
id=0 : int/PyCMenu
The ID for a new menu item, or handle to a submenu
-
value=None : string/None
A string for the menu item.
PyCMenu.ModifyMenu
ModifyMenu(pos, flags, id, value) Modify an item in a menu.
-
pos : int
The position (zero-based) the item to be changed.
-
flags : int
Flags for the item.
-
id=0 : int
The ID for the item.
-
value=None : string/None
A string for the menu item.
PyCMenu.TrackPopupMenu
TrackPopupMenu((x,y), flags, owner) Creates a popup menu anywhere on the screen.
-
(x,y) : (int, int)
The position for the menu..
-
flags=win32con.TPM_LEFTALIGN|win32con.TPM_LEFTBUTTON|win32con.TPM_RIGHTBUTTON : int
Flags for the menu.
-
owner=(main application frame) : PyCWnd
The owner of the menu.
The TrackPopupMenu function displays a floating pop-up menu at the
specified location and tracks the selection of items on the pop-up menu.
The floating pop-up menu can appear anywhere on the screen.
If the underlying MFC function fails, but TPM_RETURNCMD is set in the flags parameter, then None is returned instead of the normal exception.