using System;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class User32
{
/* Menu Commands
*
WM_COMMAND
WM_CONTEXTMENU
WM_ENTERMENULOOP
WM_EXITMENULOOP
WM_GETTITLEBARINFOEX
WM_MENUCOMMAND
WM_MENUDRAG
WM_MENUGETOBJECT
WM_MENURBUTTONUP
WM_NEXTMENU
WM_UNINITMENUPOPUP
*/
/// Indicates how the GetMenuDefaultItem function should search for menu items.
[PInvokeData("winuser.h")]
public enum GetMenuDefaultItemFlags : uint
{
///
/// The function is to return a default item, even if it is disabled. By default, the function skips disabled or grayed items.
///
GMDI_USEDISABLED = 0x0001,
///
/// If the default item is one that opens a submenu, the function is to search recursively in the corresponding submenu. If the
/// submenu has no default item, the return value identifies the item that opens the submenu. By default, the function returns
/// the first default item on the specified menu, regardless of whether it is an item that opens a submenu.
///
GMDI_GOINTOPOPUPS = 0x0002
}
/// Flags used by various menu functions.
[PInvokeData("winuser.h")]
[Flags]
public enum MenuFlags : uint
{
///
/// Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither
/// the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
MF_BYCOMMAND = 0x00000000,
///
/// Indicates that the uPosition parameter gives the zero-based relative position of the new menu item. If uPosition is -1, the
/// new menu item is appended to the end of the menu.
///
MF_BYPOSITION = 0x00000400,
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
MF_SEPARATOR = 0x00000800,
/// Enables the menu item so that it can be selected, and restores it from its grayed state.
MF_ENABLED = 0x00000000,
/// Disables the menu item and grays it so that it cannot be selected.
MF_GRAYED = 0x00000001,
/// Disables the menu item so that it cannot be selected, but the flag does not gray it.
MF_DISABLED = 0x00000002,
///
/// Does not place a check mark next to the item (default). If the application supplies check-mark bitmaps (see
/// SetMenuItemBitmaps), this flag displays the clear bitmap next to the menu item.
///
MF_UNCHECKED = 0x00000000,
///
/// Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps, this flag
/// displays the check-mark bitmap next to the menu item.
///
MF_CHECKED = 0x00000008,
/// Undocumented.
MF_USECHECKBITMAPS = 0x00000200,
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
MF_STRING = 0x00000000,
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
MF_BITMAP = 0x00000004,
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the
/// menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then
/// sent to the window procedure of the owner window whenever the appearance of the menu item must be updated.
///
MF_OWNERDRAW = 0x00000100,
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down
/// menu or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu,
/// submenu, or shortcut menu.
///
MF_POPUP = 0x00000010,
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column
/// is separated from the old column by a vertical line.
///
MF_MENUBARBREAK = 0x00000020,
///
/// Places the item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
MF_MENUBREAK = 0x00000040,
/// Removes highlighting from the menu item.
MF_UNHILITE = 0x00000000,
/// Highlights the menu item. If this flag is not specified, the highlighting is removed from the item.
MF_HILITE = 0x00000080,
/// Undocumented.
MF_DEFAULT = 0x00001000,
///
/// Item is contained in the window menu. The lParam parameter contains a handle to the menu associated with the message.
///
MF_SYSMENU = 0x00002000,
/// Indicates that the menu item has a vertical separator to its left.
MF_HELP = 0x00004000,
/// Indicates that the menu item has a vertical separator to its left.
MF_RIGHTJUSTIFY = 0x00004000,
/// Item is selected with the mouse.
MF_MOUSESELECT = 0x00008000,
/// Undocumented.
MF_END = 0x00000080,
}
/// Indicates the members to be retrieved or set (except for MIM_APPLYTOSUBMENUS) in .
[PInvokeData("winuser.h", MSDNShortId = "menuinfo.htm")]
[Flags]
public enum MenuInfoMember : uint
{
///
/// Settings apply to the menu and all of its submenus. SetMenuInfo uses this flag and GetMenuInfo ignores this flag
///
MIM_APPLYTOSUBMENUS = 0x80000000,
/// Retrieves or sets the hbrBack member.
MIM_BACKGROUND = 0x00000002,
/// Retrieves or sets the dwContextHelpID member.
MIM_HELPID = 0x00000004,
/// Retrieves or sets the cyMax member.
MIM_MAXHEIGHT = 0x00000001,
/// Retrieves or sets the dwMenuData member.
MIM_MENUDATA = 0x00000008,
/// Retrieves or sets the dwStyle member.
MIM_STYLE = 0x00000010,
}
/// The menu style use by .
[PInvokeData("winuser.h", MSDNShortId = "menuinfo.htm")]
[Flags]
public enum MenuInfoStyle : uint
{
/// Menu automatically ends when mouse is outside the menu for approximately 10 seconds.
MNS_AUTODISMISS = 0x10000000,
///
/// The same space is reserved for the check mark and the bitmap. If the check mark is drawn, the bitmap is not. All checkmarks
/// and bitmaps are aligned. Used for menus where some items use checkmarks and some use bitmaps.
///
MNS_CHECKORBMP = 0x04000000,
/// Menu items are OLE drop targets or drag sources. Menu owner receives WM_MENUDRAG and WM_MENUGETOBJECT messages.
MNS_DRAGDROP = 0x20000000,
/// Menu is modeless; that is, there is no menu modal message loop while the menu is active.
MNS_MODELESS = 0x40000000,
///
/// No space is reserved to the left of an item for a check mark. The item can still be selected, but the check mark will not
/// appear next to the item.
///
MNS_NOCHECK = 0x80000000,
///
/// Menu owner receives a WM_MENUCOMMAND message instead of a WM_COMMAND message when the user makes a selection. MNS_NOTIFYBYPOS
/// is a menu header style and has no effect when applied to individual sub menus.
///
MNS_NOTIFYBYPOS = 0x08000000,
}
/// Indicates the members to be retrieved or set in .
[PInvokeData("winuser.h", MSDNShortId = "menuiteminfo.htm")]
[Flags]
public enum MenuItemInfoMask : uint
{
/// Retrieves or sets the fState member.
MIIM_STATE = 0x00000001,
/// Retrieves or sets the wID member.
MIIM_ID = 0x00000002,
/// Retrieves or sets the hSubMenu member.
MIIM_SUBMENU = 0x00000004,
/// Retrieves or sets the hbmpChecked and hbmpUnchecked members.
MIIM_CHECKMARKS = 0x00000008,
///
/// Retrieves or sets the fType and dwTypeData members.
/// MIIM_TYPE is replaced by MIIM_BITMAP, MIIM_FTYPE, and MIIM_STRING.
///
MIIM_TYPE = 0x00000010,
/// Retrieves or sets the dwItemData member.
MIIM_DATA = 0x00000020,
/// Retrieves or sets the dwTypeData member.
MIIM_STRING = 0x00000040,
/// Retrieves or sets the hbmpItem member.
MIIM_BITMAP = 0x00000080,
/// Retrieves or sets the fType member.
MIIM_FTYPE = 0x00000100,
}
/// The menu item state.
[PInvokeData("winuser.h", MSDNShortId = "menuiteminfo.htm")]
[Flags]
public enum MenuItemState : uint
{
/// Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_DISABLED.
MFS_GRAYED = 0x00000003,
/// Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_GRAYED.
MFS_DISABLED = MFS_GRAYED,
/// Checks the menu item. For more information about selected menu items, see the hbmpChecked member.
MFS_CHECKED = MenuFlags.MF_CHECKED,
/// Highlights the menu item.
MFS_HILITE = MenuFlags.MF_HILITE,
/// Enables the menu item so that it can be selected. This is the default state.
MFS_ENABLED = MenuFlags.MF_ENABLED,
/// Unchecks the menu item. For more information about clear menu items, see the hbmpChecked member.
MFS_UNCHECKED = MenuFlags.MF_UNCHECKED,
/// Removes the highlight from the menu item. This is the default state.
MFS_UNHILITE = MenuFlags.MF_UNHILITE,
///
/// Specifies that the menu item is the default. A menu can contain only one default menu item, which is displayed in bold.
///
MFS_DEFAULT = MenuFlags.MF_DEFAULT,
}
/// The menu item type.
[PInvokeData("winuser.h", MSDNShortId = "menuiteminfo.htm")]
[Flags]
public enum MenuItemType : uint
{
///
/// Displays the menu item using a text string. The dwTypeData member is the pointer to a null-terminated string, and the cch
/// member is the length of the string.
/// MFT_STRING is replaced by MIIM_STRING.
///
MFT_STRING = MenuFlags.MF_STRING,
///
/// Displays the menu item using a bitmap. The low-order word of the dwTypeData member is the bitmap handle, and the cch member
/// is ignored.
/// MFT_BITMAP is replaced by MIIM_BITMAP and hbmpItem.
///
MFT_BITMAP = MenuFlags.MF_BITMAP,
///
/// Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For
/// a drop-down menu, submenu, or shortcut menu, a vertical line separates the new column from the old.
///
MFT_MENUBARBREAK = MenuFlags.MF_MENUBARBREAK,
///
/// Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For
/// a drop-down menu, submenu, or shortcut menu, the columns are not separated by a vertical line.
///
MFT_MENUBREAK = MenuFlags.MF_MENUBREAK,
///
/// Assigns responsibility for drawing the menu item to the window that owns the menu. The window receives a WM_MEASUREITEM
/// message before the menu is displayed for the first time, and a WM_DRAWITEM message whenever the appearance of the menu item
/// must be updated. If this value is specified, the dwTypeData member contains an application-defined value.
///
MFT_OWNERDRAW = MenuFlags.MF_OWNERDRAW,
///
/// Displays selected menu items using a radio-button mark instead of a check mark if the hbmpChecked member is NULL.
///
MFT_RADIOCHECK = 0x00000200,
///
/// Specifies that the menu item is a separator. A menu item separator appears as a horizontal dividing line. The dwTypeData and
/// cch members are ignored. This value is valid only in a drop-down menu, submenu, or shortcut menu.
///
MFT_SEPARATOR = MenuFlags.MF_SEPARATOR,
///
/// Specifies that menus cascade right-to-left (the default is left-to-right). This is used to support right-to-left languages,
/// such as Arabic and Hebrew.
///
MFT_RIGHTORDER = 0x00002000,
///
/// Right-justifies the menu item and any subsequent items. This value is valid only if the menu item is in a menu bar.
///
MFT_RIGHTJUSTIFY = MenuFlags.MF_RIGHTJUSTIFY,
}
/// The position of the mouse cursor with respect to the item indicated by MENUGETOBJECTINFO.uPos.
[PInvokeData("winuser.h", MSDNShortId = "menugetobjectinfo.htm")]
public enum MNGOF
{
/// The mouse is on the bottom of the item indicated by uPos.
MNGOF_BOTTOMGAP = 0x00000002,
/// The mouse is on the top of the item indicated by uPos.
MNGOF_TOPGAP = 0x00000001,
}
///
///
/// Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu. You can use this function to
/// specify the content, appearance, and behavior of the menu item.
///
///
///
/// Type: HMENU
/// A handle to the menu bar, drop-down menu, submenu, or shortcut menu to be changed.
///
///
/// Type: UINT
/// Controls the appearance and behavior of the new menu item. This parameter can be a combination of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps, this flag
/// displays the check-mark bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but the flag does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected, and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so that it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the item (default). If the application supplies check-mark bitmaps (see SetMenuItemBitmaps),
/// this flag displays the clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, a handle to the drop-down menu or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Contains a bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Contains an application-supplied value that can be used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM message sent when the
/// menu is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// Contains a pointer to a null-terminated string.
///
///
///
///
/// Type: BOOL
///
/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error
/// information, call GetLastError.
///
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
///
/// To get keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the WM_MENUCHAR
/// message. For more information, see Owner-Drawn Menus and the WM_MENUCHAR Message.
///
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BITMAP, MF_STRING, and MF_OWNERDRAW
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
///
/// Examples
/// For an example, see Adding Lines and Graphs to a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-appendmenua BOOL AppendMenuA( HMENU hMenu, UINT uFlags,
// UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "appendmenu")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AppendMenu(HMENU hMenu, MenuFlags uFlags, IntPtr uIDNewItem, string lpNewItem);
///
///
/// Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu. You can use this function to
/// specify the content, appearance, and behavior of the menu item.
///
///
///
/// Type: HMENU
/// A handle to the menu bar, drop-down menu, submenu, or shortcut menu to be changed.
///
///
/// Type: UINT
/// Controls the appearance and behavior of the new menu item. This parameter can be a combination of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps, this flag
/// displays the check-mark bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but the flag does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected, and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so that it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the item (default). If the application supplies check-mark bitmaps (see SetMenuItemBitmaps),
/// this flag displays the clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, a handle to the drop-down menu or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Contains a bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Contains an application-supplied value that can be used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM message sent when the
/// menu is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// Contains a pointer to a null-terminated string.
///
///
///
///
/// Type: BOOL
///
/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error
/// information, call GetLastError.
///
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
///
/// To get keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the WM_MENUCHAR
/// message. For more information, see Owner-Drawn Menus and the WM_MENUCHAR Message.
///
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BITMAP, MF_STRING, and MF_OWNERDRAW
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
///
/// Examples
/// For an example, see Adding Lines and Graphs to a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-appendmenua BOOL AppendMenuA( HMENU hMenu, UINT uFlags,
// UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "appendmenu")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AppendMenu(HMENU hMenu, MenuFlags uFlags, IntPtr uIDNewItem, IntPtr lpNewItem);
///
///
/// [ CheckMenuItem is available for use in the operating systems specified in the Requirements section. It may be altered or
/// unavailable in subsequent versions. Instead, use SetMenuItemInfo. ]
///
/// Sets the state of the specified menu item's check-mark attribute to either selected or clear.
///
///
/// Type: HMENU
/// A handle to the menu of interest.
///
///
/// Type: UINT
/// The menu item whose check-mark attribute is to be set, as determined by the uCheck parameter.
///
///
/// Type: UINT
///
/// The flags that control the interpretation of the uIDCheckItem parameter and the state of the menu item's check-mark attribute.
/// This parameter can be a combination of either MF_BYCOMMAND, or MF_BYPOSITION and MF_CHECKED or MF_UNCHECKED.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uIDCheckItem parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default, if neither
/// the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that the uIDCheckItem parameter gives the zero-based relative position of the menu item.
///
/// -
/// MF_CHECKED 0x00000008L
/// Sets the check-mark attribute to the selected state.
///
/// -
/// MF_UNCHECKED 0x00000000L
/// Sets the check-mark attribute to the clear state.
///
///
///
///
/// Type: DWORD
///
/// The return value specifies the previous state of the menu item (either MF_CHECKED or MF_UNCHECKED). If the menu
/// item does not exist, the return value is –1.
///
///
///
/// An item in a menu bar cannot have a check mark.
///
/// The uIDCheckItem parameter identifies a item that opens a submenu or a command item. For a item that opens a submenu, the
/// uIDCheckItem parameter must specify the position of the item. For a command item, the uIDCheckItem parameter can specify either
/// the item's position or its identifier.
///
/// Examples
/// For an example, see Simulating Check Boxes in a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-checkmenuitem DWORD CheckMenuItem( HMENU hMenu, UINT
// uIDCheckItem, UINT uCheck );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "checkmenuitem.htm")]
public static extern uint CheckMenuItem(HMENU hMenu, uint uIDCheckItem, MenuFlags uCheck);
///
///
/// Checks a specified menu item and makes it a radio item. At the same time, the function clears all other menu items in the
/// associated group and clears the radio-item type flag for those items.
///
///
///
/// Type: HMENU
/// A handle to the menu that contains the group of menu items.
///
///
/// Type: UINT
/// The identifier or position of the first menu item in the group.
///
///
/// Type: UINT
/// The identifier or position of the last menu item in the group.
///
///
/// Type: UINT
/// The identifier or position of the menu item to check.
///
///
/// Type: UINT
///
/// Indicates the meaning of idFirst, idLast, and idCheck. If this parameter is MF_BYCOMMAND, the other parameters specify
/// menu item identifiers. If it is MF_BYPOSITION, the other parameters specify the menu item positions.
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
///
///
/// The CheckMenuRadioItem function sets the MFT_RADIOCHECK type flag and the MFS_CHECKED state for the item
/// specified by idCheck and, at the same time, clears both flags for all other items in the group. The selected item is displayed
/// using a bullet bitmap instead of a check-mark bitmap.
///
/// For more information about menu item type and state flags, see the MENUITEMINFO structure.
/// Examples
/// For an example, see Example of Example of Using Custom Checkmark Bitmaps.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-checkmenuradioitem BOOL CheckMenuRadioItem( HMENU hmenu,
// UINT first, UINT last, UINT check, UINT flags );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "checkmenuradioitem.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CheckMenuRadioItem(HMENU hmenu, uint first, uint last, uint check, MenuFlags flags);
///
///
/// Creates a menu. The menu is initially empty, but it can be filled with menu items by using the InsertMenuItem, AppendMenu, and
/// InsertMenu functions.
///
///
///
/// Type: HMENU
/// If the function succeeds, the return value is a handle to the newly created menu.
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
///
///
/// Resources associated with a menu that is assigned to a window are freed automatically. If the menu is not assigned to a window,
/// an application must free system resources associated with the menu before closing. An application frees menu resources by calling
/// the DestroyMenu function.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createmenu HMENU CreateMenu( );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "createmenu.htm")]
public static extern SafeHMENU CreateMenu();
///
///
/// Creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty. You can insert or append menu items by using
/// the InsertMenuItem function. You can also use the InsertMenu function to insert menu items and the AppendMenu function to append
/// menu items.
///
///
///
/// Type: HMENU
/// If the function succeeds, the return value is a handle to the newly created menu.
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
///
///
/// The application can add the new menu to an existing menu, or it can display a shortcut menu by calling the TrackPopupMenuEx or
/// TrackPopupMenu functions.
///
///
/// Resources associated with a menu that is assigned to a window are freed automatically. If the menu is not assigned to a window,
/// an application must free system resources associated with the menu before closing. An application frees menu resources by calling
/// the DestroyMenu function.
///
/// Examples
/// For an example, see Adding Lines and Graphs to a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createpopupmenu HMENU CreatePopupMenu( );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "createpopupmenu.htm")]
public static extern SafeHMENU CreatePopupMenu();
///
///
/// Deletes an item from the specified menu. If the menu item opens a menu or submenu, this function destroys the handle to the menu
/// or submenu and frees the memory used by the menu or submenu.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item to be deleted, as determined by the uFlags parameter.
///
///
/// Type: UINT
/// Indicates how the uPosition parameter is interpreted. This parameter must be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that uPosition gives the identifier of the menu item. The MF_BYCOMMAND flag is the default flag if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uPosition gives the zero-based relative position of the menu item.
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
/// Examples
/// For an example, see Example of a Clipboard Viewer.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-deletemenu BOOL DeleteMenu( HMENU hMenu, UINT uPosition,
// UINT uFlags );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "deletemenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteMenu(HMENU hMenu, uint uPosition, MenuFlags uFlags);
///
/// Destroys the specified menu and frees any memory that the menu occupies.
///
///
/// Type: HMENU
/// A handle to the menu to be destroyed.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// Before closing, an application must use the DestroyMenu function to destroy a menu not assigned to a window. A menu that
/// is assigned to a window is automatically destroyed when the application closes.
///
/// DestroyMenu is recursive, that is, it will destroy the menu and all its submenus.
/// Examples
/// For an example, see Displaying a Shortcut Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-destroymenu BOOL DestroyMenu( HMENU hMenu );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "destroymenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyMenu(HMENU hMenu);
///
///
/// Redraws the menu bar of the specified window. If the menu bar changes after the system has created the window, this function must
/// be called to draw the changed menu bar.
///
///
///
/// Type: HWND
/// A handle to the window whose menu bar is to be redrawn.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-drawmenubar BOOL DrawMenuBar( HWND hWnd );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "drawmenubar.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DrawMenuBar(HWND hWnd);
///
/// Enables, disables, or grays the specified menu item.
///
///
/// Type: HMENU
/// A handle to the menu.
///
///
/// Type: UINT
///
/// The menu item to be enabled, disabled, or grayed, as determined by the uEnable parameter. This parameter specifies an item in a
/// menu bar, menu, or submenu.
///
///
///
/// Type: UINT
///
/// Controls the interpretation of the uIDEnableItem parameter and indicate whether the menu item is enabled, disabled, or grayed.
/// This parameter must be a combination of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that uIDEnableItem gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is
/// specified, the MF_BYCOMMAND flag is the default flag.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uIDEnableItem gives the zero-based relative position of the menu item.
///
/// -
/// MF_DISABLED 0x00000002L
/// Indicates that the menu item is disabled, but not grayed, so it cannot be selected.
///
/// -
/// MF_ENABLED 0x00000000L
/// Indicates that the menu item is enabled and restored from a grayed state so that it can be selected.
///
/// -
/// MF_GRAYED 0x00000001L
/// Indicates that the menu item is disabled and grayed so that it cannot be selected.
///
///
///
///
/// Type: BOOL
///
/// The return value specifies the previous state of the menu item (it is either MF_DISABLED, MF_ENABLED, or
/// MF_GRAYED). If the menu item does not exist, the return value is -1.
///
///
///
///
/// An application must use the MF_BYPOSITION flag to specify the correct menu handle. If the menu handle to the menu bar is
/// specified, the top-level menu item (an item in the menu bar) is affected. To set the state of an item in a drop-down menu or
/// submenu by position, an application must specify a handle to the drop-down menu or submenu.
///
///
/// When an application specifies the MF_BYCOMMAND flag, the system checks all items that open submenus in the menu identified
/// by the specified menu handle. Therefore, unless duplicate menu items are present, specifying the menu handle to the menu bar is sufficient.
///
///
/// The InsertMenu, InsertMenuItem, LoadMenuIndirect, ModifyMenu, and SetMenuItemInfo functions can also set the state (enabled,
/// disabled, or grayed) of a menu item.
///
/// When you change a window menu, the menu bar is not immediately updated. To force the update, call DrawMenuBar.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enablemenuitem BOOL EnableMenuItem( HMENU hMenu, UINT
// uIDEnableItem, UINT uEnable );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "enablemenuitem.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnableMenuItem(HMENU hMenu, uint uIDEnableItem, MenuFlags uEnable);
///
/// Ends the calling thread's active menu.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// If a platform does not support EndMenu, send the owner of the active menu a WM_CANCELMODE message.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-endmenu BOOL EndMenu( );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "endmenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndMenu();
///
/// Retrieves a handle to the menu assigned to the specified window.
///
///
/// Type: HWND
/// A handle to the window whose menu handle is to be retrieved.
///
///
/// Type: HMENU
///
/// The return value is a handle to the menu. If the specified window has no menu, the return value is NULL. If the window is
/// a child window, the return value is undefined.
///
///
///
///
/// GetMenu does not work on floating menu bars. Floating menu bars are custom controls that mimic standard menus; they are
/// not menus. To get the handle on a floating menu bar, use the Active Accessibility APIs.
///
/// Examples
/// For an example, see Adding Lines and Graphs to a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenu HMENU GetMenu( HWND hWnd );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenu.htm")]
public static extern HMENU GetMenu(HWND hWnd);
///
/// Retrieves information about the specified menu bar.
///
///
/// Type: HWND
/// A handle to the window (menu bar) whose information is to be retrieved.
///
///
/// Type: LONG
/// The menu object. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// OBJID_CLIENT ((LONG)0xFFFFFFFC)
/// The popup menu associated with the window.
///
/// -
/// OBJID_MENU ((LONG)0xFFFFFFFD)
/// The menu bar associated with the window (see the GetMenu function).
///
/// -
/// OBJID_SYSMENU ((LONG)0xFFFFFFFF)
/// The system menu associated with the window (see the GetSystemMenu function).
///
///
///
///
/// Type: LONG
///
/// The item for which to retrieve information. If this parameter is zero, the function retrieves information about the menu itself.
/// If this parameter is 1, the function retrieves information about the first item on the menu, and so on.
///
///
///
/// Type: PMENUBARINFO
///
/// A pointer to a MENUBARINFO structure that receives the information. Note that you must set the cbSize member to before
/// calling this function.
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenubarinfo BOOL GetMenuBarInfo( HWND hwnd, LONG
// idObject, LONG idItem, PMENUBARINFO pmbi );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenubarinfo.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMenuBarInfo(HWND hwnd, int idObject, int idItem, ref MENUBARINFO pmbi);
///
///
/// Retrieves the dimensions of the default check-mark bitmap. The system displays this bitmap next to selected menu items. Before
/// calling the SetMenuItemBitmaps function to replace the default check-mark bitmap for a menu item, an application must determine
/// the correct bitmap size by calling GetMenuCheckMarkDimensions.
///
///
/// Note The GetMenuCheckMarkDimensions function is included only for compatibility with 16-bit versions of Windows.
/// Applications should use the GetSystemMetrics function with the CXMENUCHECK and CYMENUCHECK values to retrieve the
/// bitmap dimensions.
///
///
///
/// Type: LONG
///
/// The return value specifies the height and width, in pixels, of the default check-mark bitmap. The high-order word contains the
/// height; the low-order word contains the width.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenucheckmarkdimensions LONG
// GetMenuCheckMarkDimensions( );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenucheckmarkdimensions.htm")]
public static extern int GetMenuCheckMarkDimensions();
/// Retrieves the Help context identifier associated with the specified menu.
///
/// Type: HMENU
/// A handle to the menu for which the Help context identifier is to be retrieved.
///
///
/// Type: DWORD
/// Returns the Help context identifier if the menu has one, or zero otherwise.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenucontexthelpid DWORD GetMenuContextHelpId( HMENU
// Arg1 );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "2b8d3e94-6860-4a75-8373-38afb641eb3b")]
public static extern uint GetMenuContextHelpId(HMENU Arg1);
///
/// Determines the default menu item on the specified menu.
///
///
/// Type: HMENU
/// A handle to the menu for which to retrieve the default menu item.
///
///
/// Type: UINT
///
/// Indicates whether to retrieve the menu item's identifier or its position. If this parameter is FALSE, the identifier is
/// returned. Otherwise, the position is returned.
///
///
///
/// Type: UINT
/// Indicates how the function should search for menu items. This parameter can be zero or more of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// GMDI_GOINTOPOPUPS 0x0002L
///
/// If the default item is one that opens a submenu, the function is to search recursively in the corresponding submenu. If the
/// submenu has no default item, the return value identifies the item that opens the submenu. By default, the function returns the
/// first default item on the specified menu, regardless of whether it is an item that opens a submenu.
///
///
/// -
/// GMDI_USEDISABLED 0x0001L
/// The function is to return a default item, even if it is disabled. By default, the function skips disabled or grayed items.
///
///
///
///
/// Type: UINT
/// If the function succeeds, the return value is the identifier or position of the menu item.
/// If the function fails, the return value is -1. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenudefaultitem UINT GetMenuDefaultItem( HMENU hMenu,
// UINT fByPos, UINT gmdiFlags );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenudefaultitem.htm")]
public static extern uint GetMenuDefaultItem(HMENU hMenu, [MarshalAs(UnmanagedType.Bool)] bool fByPos, GetMenuDefaultItemFlags gmdiFlags);
///
/// Retrieves information about a specified menu.
///
/// A handle on a menu.
///
/// A pointer to a MENUINFO structure containing information for the menu. Note that you must set the cbSize member to
/// sizeof(MENUINFO) before calling this function.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenuinfo BOOL GetMenuInfo( HMENU , LPMENUINFO );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenuinfo.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMenuInfo(HMENU hmenu, ref MENUINFO lpcmi);
///
/// Determines the number of items in the specified menu.
///
///
/// Type: HMENU
/// A handle to the menu to be examined.
///
///
/// Type: int
/// If the function succeeds, the return value specifies the number of items in the menu.
/// If the function fails, the return value is -1. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenuitemcount int GetMenuItemCount( HMENU hMenu );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenuitemcount.htm")]
public static extern int GetMenuItemCount(HMENU hMenu);
///
/// Retrieves the menu item identifier of a menu item located at the specified position in a menu.
///
///
/// Type: HMENU
/// A handle to the menu that contains the item whose identifier is to be retrieved.
///
///
/// Type: int
/// The zero-based relative position of the menu item whose identifier is to be retrieved.
///
///
/// Type: UINT
///
/// The return value is the identifier of the specified menu item. If the menu item identifier is NULL or if the specified
/// item opens a submenu, the return value is -1.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenuitemid UINT GetMenuItemID( HMENU hMenu, int nPos );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenuitemid.htm")]
public static extern uint GetMenuItemID(HMENU hMenu, int nPos);
///
/// Retrieves information about a menu item.
///
///
/// Type: HMENU
/// A handle to the menu that contains the menu item.
///
///
/// Type: UINT
///
/// The identifier or position of the menu item to get information about. The meaning of this parameter depends on the value of fByPosition.
///
///
///
/// Type: BOOL
///
/// The meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position.
/// See Accessing Menu Items Programmatically for more information.
///
///
///
/// Type: LPMENUITEMINFO
///
/// A pointer to a MENUITEMINFO structure that specifies the information to retrieve and receives information about the menu item.
/// Note that you must set the cbSize member to before calling this function.
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
///
///
/// To retrieve a menu item of type MFT_STRING, first find the size of the string by setting the dwTypeData member of
/// MENUITEMINFO to NULL and then calling GetMenuItemInfo. The value of cch+1 is the size needed. Then allocate
/// a buffer of this size, place the pointer to the buffer in dwTypeData, increment cch by one, and then call
/// GetMenuItemInfo once again to fill the buffer with the string.
///
///
/// If the retrieved menu item is of some other type, then GetMenuItemInfo sets the dwTypeData member to a value whose
/// type is specified by the fTypefType member and sets cch to 0.
///
/// Examples
/// For an example, see Example of Owner-Drawn Menu Items.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenuiteminfoa BOOL GetMenuItemInfoA( HMENU hmenu, UINT
// item, BOOL fByPosition, LPMENUITEMINFOA lpmii );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "getmenuiteminfo.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMenuItemInfo(HMENU hmenu, uint item, [MarshalAs(UnmanagedType.Bool)] bool fByPosition, ref MENUITEMINFO lpmii);
///
/// Retrieves the bounding rectangle for the specified menu item.
///
///
/// Type: HWND
/// A handle to the window containing the menu.
/// If this value is NULL and the hMenu parameter represents a popup menu, the function will find the menu window.
///
///
/// Type: HMENU
/// A handle to a menu.
///
///
/// Type: UINT
/// The zero-based position of the menu item.
///
///
/// Type: LPRECT
/// A pointer to a RECT structure that receives the bounding rectangle of the specified menu item expressed in screen coordinates.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
///
///
/// In order for the returned rectangle to be meaningful, the menu must be popped up if a popup menu or attached to a window if a
/// menu bar. Menu item positions are not determined until the menu is displayed.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenuitemrect BOOL GetMenuItemRect( HWND hWnd, HMENU
// hMenu, UINT uItem, LPRECT lprcItem );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenuitemrect.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMenuItemRect(HWND hWnd, HMENU hMenu, uint uItem, out RECT lprcItem);
///
///
/// Retrieves the menu flags associated with the specified menu item. If the menu item opens a submenu, this function also returns
/// the number of items in the submenu.
///
///
/// Note The GetMenuState function has been superseded by the GetMenuItemInfo. You can still use GetMenuState,
/// however, if you do not need any of the extended features of GetMenuItemInfo.
///
///
///
/// Type: HMENU
/// A handle to the menu that contains the menu item whose flags are to be retrieved.
///
///
/// Type: UINT
/// The menu item for which the menu flags are to be retrieved, as determined by the uFlags parameter.
///
///
/// Type: UINT
/// Indicates how the uId parameter is interpreted. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uId parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that the uId parameter gives the zero-based relative position of the menu item.
///
///
///
///
/// Type: UINT
/// If the specified item does not exist, the return value is -1.
///
/// If the menu item opens a submenu, the low-order byte of the return value contains the menu flags associated with the item, and
/// the high-order byte contains the number of items in the submenu opened by the item.
///
///
/// Otherwise, the return value is a mask (Bitwise OR) of the menu flags. Following are the menu flags associated with the menu item.
///
///
///
/// Return code/value
/// Description
///
/// -
/// MF_CHECKED 0x00000008L
/// A check mark is placed next to the item (for drop-down menus, submenus, and shortcut menus only).
///
/// -
/// MF_DISABLED 0x00000002L
/// The item is disabled.
///
/// -
/// MF_GRAYED 0x00000001L
/// The item is disabled and grayed.
///
/// -
/// MF_HILITE 0x00000080L
/// The item is highlighted.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// This is the same as the MF_MENUBREAK flag, except for drop-down menus, submenus, and shortcut menus, where the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// The item is placed on a new line (for menu bars) or in a new column (for drop-down menus, submenus, and shortcut menus) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
/// The item is owner-drawn.
///
/// -
/// MF_POPUP 0x00000010L
/// Menu item is a submenu.
///
/// -
/// MF_SEPARATOR 0x00000800L
/// There is a horizontal dividing line (for drop-down menus, submenus, and shortcut menus only).
///
///
///
///
///
/// It is possible to test an item for a flag value of MF_ENABLED, MF_STRING, MF_UNCHECKED, or
/// MF_UNHILITE. However, since these values equate to zero you must use an expression to test for them.
///
///
///
/// Flag
/// Expression to test for the flag
///
/// -
/// MF_ENABLED
///
///
/// -
/// MF_STRING
///
///
/// -
/// MF_UNCHECKED
///
///
/// -
/// MF_UNHILITE
///
///
///
/// Examples
/// For an example, see Simulating Check Boxes in a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenustate UINT GetMenuState( HMENU hMenu, UINT uId,
// UINT uFlags );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getmenustate.htm")]
public static extern uint GetMenuState(HMENU hMenu, uint uId, MenuFlags uFlags);
///
/// Copies the text string of the specified menu item into the specified buffer.
///
/// Note The GetMenuString function has been superseded. Use the GetMenuItemInfo function to retrieve the menu item text.
///
///
///
/// Type: HMENU
/// A handle to the menu.
///
///
/// Type: UINT
/// The menu item to be changed, as determined by the uFlag parameter.
///
///
/// Type: LPTSTR
///
/// The buffer that receives the null-terminated string. If the string is as long or longer than lpString, the string is truncated
/// and the terminating null character is added. If lpString is NULL, the function returns the length of the menu string.
///
///
///
/// Type: int
///
/// The maximum length, in characters, of the string to be copied. If the string is longer than the maximum specified in the
/// nMaxCount parameter, the extra characters are truncated. If nMaxCount is 0, the function returns the length of the menu string.
///
///
///
/// Type: UINT
/// Indicates how the uIDItem parameter is interpreted. This parameter must be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that uIDItem gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified,
/// the MF_BYCOMMAND flag is the default flag.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uIDItem gives the zero-based relative position of the menu item.
///
///
///
///
/// Type: int
///
/// If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating
/// null character.
///
/// If the function fails, the return value is zero.
/// If the specified item is not of type MIIM_STRING or MFT_STRING, then the return value is zero.
///
///
///
/// The nMaxCount parameter must be one larger than the number of characters in the text string to accommodate the terminating null character.
///
/// If nMaxCount is 0, the function returns the length of the menu string.
/// Security Warning
///
/// The lpString parameter is a TCHAR buffer, and nMaxCount is the length of the menu string in characters. Sizing these
/// parameters incorrectly can cause truncation of the string, leading to possible loss of data.
///
/// Examples
/// For an example, see Creating User Editable Accelerators.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmenustringa int GetMenuStringA( HMENU hMenu, UINT
// uIDItem, LPSTR lpString, int cchMax, UINT flags );
[DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "getmenustring.htm")]
public static extern int GetMenuString(HMENU hMenu, uint uIDItem, StringBuilder lpString, int cchMax, MenuFlags flags);
///
/// Retrieves a handle to the drop-down menu or submenu activated by the specified menu item.
///
///
/// Type: HMENU
/// A handle to the menu.
///
///
/// Type: int
/// The zero-based relative position in the specified menu of an item that activates a drop-down menu or submenu.
///
///
/// Type: HMENU
///
/// If the function succeeds, the return value is a handle to the drop-down menu or submenu activated by the menu item. If the menu
/// item does not activate a drop-down menu or submenu, the return value is NULL.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsubmenu HMENU GetSubMenu( HMENU hMenu, int nPos );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getsubmenu.htm")]
public static extern HMENU GetSubMenu(HMENU hMenu, int nPos);
///
///
/// Enables the application to access the window menu (also known as the system menu or the control menu) for copying and modifying.
///
///
///
/// Type: HWND
/// A handle to the window that will own a copy of the window menu.
///
///
/// Type: BOOL
///
/// The action to be taken. If this parameter is FALSE, GetSystemMenu returns a handle to the copy of the window menu
/// currently in use. The copy is initially identical to the window menu, but it can be modified. If this parameter is TRUE,
/// GetSystemMenu resets the window menu back to the default state. The previous window menu, if any, is destroyed.
///
///
///
/// Type: HMENU
///
/// If the bRevert parameter is FALSE, the return value is a handle to a copy of the window menu. If the bRevert parameter is
/// TRUE, the return value is NULL.
///
///
///
///
/// Any window that does not use the GetSystemMenu function to make its own copy of the window menu receives the standard
/// window menu.
///
///
/// The window menu initially contains items with various identifier values, such as SC_CLOSE, SC_MOVE, and SC_SIZE.
///
/// Menu items on the window menu send WM_SYSCOMMAND messages.
///
/// All predefined window menu items have identifier numbers greater than 0xF000. If an application adds commands to the window menu,
/// it should use identifier numbers less than 0xF000.
///
///
/// The system automatically grays items on the standard window menu, depending on the situation. The application can perform its own
/// checking or graying by responding to the WM_INITMENU message that is sent before any menu is displayed.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemmenu HMENU GetSystemMenu( HWND hWnd, BOOL bRevert );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "getsystemmenu.htm")]
public static extern HMENU GetSystemMenu(HWND hWnd, [MarshalAs(UnmanagedType.Bool)] bool bRevert);
///
/// Adds or removes highlighting from an item in a menu bar.
///
///
/// Type: HWND
/// A handle to the window that contains the menu.
///
///
/// Type: HMENU
/// A handle to the menu bar that contains the item.
///
///
/// Type: UINT
///
/// The menu item. This parameter is either the identifier of the menu item or the offset of the menu item in the menu bar, depending
/// on the value of the uHilite parameter.
///
///
///
/// Type: UINT
///
/// Controls the interpretation of the uItemHilite parameter and indicates whether the menu item is highlighted. This parameter must
/// be a combination of either MF_BYCOMMAND or MF_BYPOSITION and MF_HILITE or MF_UNHILITE.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
/// Indicates that uItemHilite gives the identifier of the menu item.
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uItemHilite gives the zero-based relative position of the menu item.
///
/// -
/// MF_HILITE 0x00000080L
/// Highlights the menu item. If this flag is not specified, the highlighting is removed from the item.
///
/// -
/// MF_UNHILITE 0x00000000L
/// Removes highlighting from the menu item.
///
///
///
///
/// Type: BOOL
/// If the menu item is set to the specified highlight state, the return value is nonzero.
/// If the menu item is not set to the specified highlight state, the return value is zero.
///
///
///
/// The MF_HILITE and MF_UNHILITE flags can be used only with the HiliteMenuItem function; they cannot be used
/// with the ModifyMenu function.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-hilitemenuitem BOOL HiliteMenuItem( HWND hWnd, HMENU
// hMenu, UINT uIDHiliteItem, UINT uHilite );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "hilitemenuitem.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool HiliteMenuItem(HWND hWnd, HMENU hMenu, uint uIDHiliteItem, MenuFlags uHilite);
///
/// Inserts a new menu item into a menu, moving other items down the menu.
///
/// Note The InsertMenu function has been superseded by the InsertMenuItem function. You can still use
/// InsertMenu, however, if you do not need any of the extended features of InsertMenuItem.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item before which the new menu item is to be inserted, as determined by the uFlags parameter.
///
///
/// Type: UINT
///
/// Controls the interpretation of the uPosition parameter and the content, appearance, and behavior of the new menu item. This
/// parameter must include one of the following required values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
///
/// Indicates that the uPosition parameter gives the zero-based relative position of the new menu item. If uPosition is -1, the new
/// menu item is appended to the end of the menu.
///
///
///
/// The parameter must also include at least one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps), this flag
/// displays the check-mark bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the menu item (default). If the application supplies check-mark bitmaps (see the
/// SetMenuItemBitmaps function), this flag displays the clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the new menu item or, if the uFlags parameter has the MF_POPUP flag set, a handle to the drop-down menu
/// or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the
/// MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag, as follows.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Contains a bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Contains an application-supplied value that can be used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM message sent when the
/// menu item is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// Contains a pointer to a null-terminated string (the default).
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BYCOMMAND and MF_BYPOSITION
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-insertmenua BOOL InsertMenuA( HMENU hMenu, UINT uPosition,
// UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "insertmenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InsertMenu(HMENU hMenu, uint uPosition, MenuFlags uFlags, IntPtr uIDNewItem, IntPtr lpNewItem);
///
/// Inserts a new menu item into a menu, moving other items down the menu.
///
/// Note The InsertMenu function has been superseded by the InsertMenuItem function. You can still use
/// InsertMenu, however, if you do not need any of the extended features of InsertMenuItem.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item before which the new menu item is to be inserted, as determined by the uFlags parameter.
///
///
/// Type: UINT
///
/// Controls the interpretation of the uPosition parameter and the content, appearance, and behavior of the new menu item. This
/// parameter must include one of the following required values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
///
/// Indicates that the uPosition parameter gives the zero-based relative position of the new menu item. If uPosition is -1, the new
/// menu item is appended to the end of the menu.
///
///
///
/// The parameter must also include at least one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps), this flag
/// displays the check-mark bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the menu item (default). If the application supplies check-mark bitmaps (see the
/// SetMenuItemBitmaps function), this flag displays the clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the new menu item or, if the uFlags parameter has the MF_POPUP flag set, a handle to the drop-down menu
/// or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the
/// MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag, as follows.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Contains a bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Contains an application-supplied value that can be used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM message sent when the
/// menu item is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// Contains a pointer to a null-terminated string (the default).
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BYCOMMAND and MF_BYPOSITION
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-insertmenua BOOL InsertMenuA( HMENU hMenu, UINT uPosition,
// UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "insertmenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InsertMenu(HMENU hMenu, uint uPosition, MenuFlags uFlags, IntPtr uIDNewItem, string lpNewItem);
///
/// Inserts a new menu item at the specified position in a menu.
///
///
/// Type: HMENU
/// A handle to the menu in which the new menu item is inserted.
///
///
/// Type: UINT
///
/// The identifier or position of the menu item before which to insert the new item. The meaning of this parameter depends on the
/// value of fByPosition.
///
///
///
/// Type: BOOL
///
/// Controls the meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item
/// position. See Accessing Menu Items Programmatically for more information.
///
///
///
/// Type: LPCMENUITEMINFO
/// A pointer to a MENUITEMINFO structure that contains information about the new menu item.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
///
/// In order for keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the
/// WM_MENUCHAR message. See Owner-Drawn Menus and the WM_MENUCHAR Message for more information.
///
/// Examples
/// For an example, see Example of Menu-Item Bitmaps.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-insertmenuitema BOOL InsertMenuItemA( HMENU hmenu, UINT
// item, BOOL fByPosition, LPCMENUITEMINFOA lpmi );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "insertmenuitem.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InsertMenuItem(HMENU hmenu, uint item, [MarshalAs(UnmanagedType.Bool)] bool fByPosition, ref MENUITEMINFO lpmi);
///
/// Determines whether a handle is a menu handle.
///
///
/// Type: HMENU
/// A handle to be tested.
///
///
/// Type: BOOL
/// If the handle is a menu handle, the return value is nonzero.
/// If the handle is not a menu handle, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-ismenu BOOL IsMenu( HMENU hMenu );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "ismenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsMenu(HMENU hMenu);
///
/// Loads the specified menu resource from the executable (.exe) file associated with an application instance.
///
///
/// Type: HINSTANCE
/// A handle to the module containing the menu resource to be loaded.
///
///
/// Type: LPCTSTR
///
/// The name of the menu resource. Alternatively, this parameter can consist of the resource identifier in the low-order word and
/// zero in the high-order word. To create this value, use the MAKEINTRESOURCE macro.
///
///
///
/// Type: HMENU
/// If the function succeeds, the return value is a handle to the menu resource.
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
///
///
/// The DestroyMenu function is used, before an application closes, to destroy the menu and free memory that the loaded menu occupied.
///
/// Examples
/// For an example, see Displaying a Shortcut Menu
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-loadmenua HMENU LoadMenuA( HINSTANCE hInstance, LPCSTR
// lpMenuName );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "loadmenu.htm")]
public static extern SafeHMENU LoadMenu(HINSTANCE hInstance, SafeResourceId lpMenuName);
///
/// Loads the specified menu template in memory.
///
///
/// Type: const MENUTEMPLATE*
///
/// A pointer to a menu template or an extended menu template. A menu template consists of a MENUITEMTEMPLATEHEADER structure
/// followed by one or more contiguous MENUITEMTEMPLATE structures. An extended menu template consists of a MENUEX_TEMPLATE_HEADER
/// structure followed by one or more contiguous MENUEX_TEMPLATE_ITEM structures.
///
///
///
/// Type: HMENU
/// If the function succeeds, the return value is a handle to the menu.
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
///
///
/// For both the ANSI and the Unicode version of this function, the strings in the MENUITEMTEMPLATE structure must be Unicode strings.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-loadmenuindirecta HMENU LoadMenuIndirectA( CONST
// MENUTEMPLATEA *lpMenuTemplate );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "loadmenuindirect.htm")]
public static extern SafeHMENU LoadMenuIndirect(IntPtr lpMenuTemplate);
///
/// Determines which menu item, if any, is at the specified location.
///
///
/// Type: HWND
///
/// A handle to the window containing the menu. If this value is NULL and the hMenu parameter represents a popup menu, the
/// function will find the menu window.
///
///
///
/// Type: HMENU
/// A handle to the menu containing the menu items to hit test.
///
///
/// Type: POINT
///
/// A structure that specifies the location to test. If hMenu specifies a menu bar, this parameter is in window coordinates.
/// Otherwise, it is in client coordinates.
///
///
///
/// Type: int
/// Returns the zero-based position of the menu item at the specified location or -1 if no menu item is at the specified location.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-menuitemfrompoint int MenuItemFromPoint( HWND hWnd, HMENU
// hMenu, POINT ptScreen );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "menuitemfrompoint.htm")]
public static extern int MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen);
///
/// Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.
///
/// Note The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use
/// ModifyMenu, however, if you do not need any of the extended features of SetMenuItemInfo.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item to be changed, as determined by the uFlags parameter.
///
///
/// Type: UINT
///
/// Controls the interpretation of the uPosition parameter and the content, appearance, and behavior of the menu item. This parameter
/// must include one of the following required values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that the uPosition parameter gives the zero-based relative position of the menu item.
///
///
/// The parameter must also include at least one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the item. If your application provides check-mark bitmaps (see the SetMenuItemBitmaps function), this
/// flag displays a selected bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but this flag does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so that it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the item (the default). If your application supplies check-mark bitmaps (see the
/// SetMenuItemBitmaps function), this flag displays a clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the modified menu item or, if the uFlags parameter has the MF_POPUP flag set, a handle to the drop-down
/// menu or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The contents of the changed menu item. The interpretation of this parameter depends on whether the uFlags parameter includes the
/// MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// A bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// A value supplied by an application that is used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM messages sent when the
/// menu item is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// A pointer to a null-terminated string (the default).
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// If ModifyMenu replaces a menu item that opens a drop-down menu or submenu, the function destroys the old drop-down menu or
/// submenu and frees the memory used by it.
///
///
/// In order for keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the
/// WM_MENUCHAR message. See Owner-Drawn Menus and the WM_MENUCHAR Message for more information.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window. To change
/// the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions.
///
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BYCOMMAND and MF_BYPOSITION
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
///
/// Examples
/// For an example, see Setting Fonts for Menu-Item Text Strings.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-modifymenua BOOL ModifyMenuA( HMENU hMnu, UINT uPosition,
// UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "modifymenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ModifyMenu(HMENU hMnu, uint uPosition, MenuFlags uFlags, IntPtr uIDNewItem, IntPtr lpNewItem);
///
/// Changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.
///
/// Note The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use
/// ModifyMenu, however, if you do not need any of the extended features of SetMenuItemInfo.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item to be changed, as determined by the uFlags parameter.
///
///
/// Type: UINT
///
/// Controls the interpretation of the uPosition parameter and the content, appearance, and behavior of the menu item. This parameter
/// must include one of the following required values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the
/// MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that the uPosition parameter gives the zero-based relative position of the menu item.
///
///
/// The parameter must also include at least one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// Uses a bitmap as the menu item. The lpNewItem parameter contains a handle to the bitmap.
///
/// -
/// MF_CHECKED 0x00000008L
///
/// Places a check mark next to the item. If your application provides check-mark bitmaps (see the SetMenuItemBitmaps function), this
/// flag displays a selected bitmap next to the menu item.
///
///
/// -
/// MF_DISABLED 0x00000002L
/// Disables the menu item so that it cannot be selected, but this flag does not gray it.
///
/// -
/// MF_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected and restores it from its grayed state.
///
/// -
/// MF_GRAYED 0x00000001L
/// Disables the menu item and grays it so that it cannot be selected.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
///
/// Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is
/// separated from the old column by a vertical line.
///
///
/// -
/// MF_MENUBREAK 0x00000040L
///
/// Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without
/// separating columns.
///
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu
/// receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the
/// window procedure of the owner window whenever the appearance of the menu item must be updated.
///
///
/// -
/// MF_POPUP 0x00000010L
///
/// Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu
/// or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu,
/// or shortcut menu.
///
///
/// -
/// MF_SEPARATOR 0x00000800L
///
/// Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be
/// grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
///
///
/// -
/// MF_STRING 0x00000000L
/// Specifies that the menu item is a text string; the lpNewItem parameter is a pointer to the string.
///
/// -
/// MF_UNCHECKED 0x00000000L
///
/// Does not place a check mark next to the item (the default). If your application supplies check-mark bitmaps (see the
/// SetMenuItemBitmaps function), this flag displays a clear bitmap next to the menu item.
///
///
///
///
///
/// Type: UINT_PTR
///
/// The identifier of the modified menu item or, if the uFlags parameter has the MF_POPUP flag set, a handle to the drop-down
/// menu or submenu.
///
///
///
/// Type: LPCTSTR
///
/// The contents of the changed menu item. The interpretation of this parameter depends on whether the uFlags parameter includes the
/// MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_BITMAP 0x00000004L
/// A bitmap handle.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// A value supplied by an application that is used to maintain additional data related to the menu item. The value is in the
/// itemData member of the structure pointed to by the lParam parameter of the WM_MEASUREITEM or WM_DRAWITEM messages sent when the
/// menu item is created or its appearance is updated.
///
///
/// -
/// MF_STRING 0x00000000L
/// A pointer to a null-terminated string (the default).
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// If ModifyMenu replaces a menu item that opens a drop-down menu or submenu, the function destroys the old drop-down menu or
/// submenu and frees the memory used by it.
///
///
/// In order for keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the
/// WM_MENUCHAR message. See Owner-Drawn Menus and the WM_MENUCHAR Message for more information.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window. To change
/// the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions.
///
/// The following groups of flags cannot be used together:
///
/// -
/// MF_BYCOMMAND and MF_BYPOSITION
///
/// -
/// MF_DISABLED, MF_ENABLED, and MF_GRAYED
///
/// -
/// MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
///
/// -
/// MF_MENUBARBREAK and MF_MENUBREAK
///
/// -
/// MF_CHECKED and MF_UNCHECKED
///
///
/// Examples
/// For an example, see Setting Fonts for Menu-Item Text Strings.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-modifymenua BOOL ModifyMenuA( HMENU hMnu, UINT uPosition,
// UINT uFlags, UINT_PTR uIDNewItem, LPCSTR lpNewItem );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "modifymenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ModifyMenu(HMENU hMnu, uint uPosition, MenuFlags uFlags, IntPtr uIDNewItem, string lpNewItem);
///
///
/// Deletes a menu item or detaches a submenu from the specified menu. If the menu item opens a drop-down menu or submenu,
/// RemoveMenu does not destroy the menu or its handle, allowing the menu to be reused. Before this function is called, the
/// GetSubMenu function should retrieve a handle to the drop-down menu or submenu.
///
///
///
/// Type: HMENU
/// A handle to the menu to be changed.
///
///
/// Type: UINT
/// The menu item to be deleted, as determined by the uFlags parameter.
///
///
/// Type: UINT
/// Indicates how the uPosition parameter is interpreted. This parameter must be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that uPosition gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified,
/// the MF_BYCOMMAND flag is the default flag.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uPosition gives the zero-based relative position of the menu item.
///
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-removemenu BOOL RemoveMenu( HMENU hMenu, UINT uPosition,
// UINT uFlags );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "removemenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RemoveMenu(HMENU hMenu, uint uPosition, MenuFlags uFlags);
///
/// Assigns a new menu to the specified window.
///
///
/// Type: HWND
/// A handle to the window to which the menu is to be assigned.
///
///
/// Type: HMENU
/// A handle to the new menu. If this parameter is NULL, the window's current menu is removed.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
/// The window is redrawn to reflect the menu change. A menu can be assigned to any window that is not a child window.
///
/// The SetMenu function replaces the previous menu, if any, but it does not destroy it. An application should call the
/// DestroyMenu function to accomplish this task.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenu BOOL SetMenu( HWND hWnd, HMENU hMenu );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "setmenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenu(HWND hWnd, HMENU hMenu);
/// Associates a Help context identifier with a menu.
///
/// Type: HMENU
/// A handle to the menu with which to associate the Help context identifier.
///
///
/// Type: DWORD
/// The help context identifier.
///
///
/// Type: BOOL
/// Returns nonzero if successful, or zero otherwise.
/// To retrieve extended error information, call GetLastError.
///
/// All items in the menu share this identifier. Help context identifiers can't be attached to individual menu items.
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenucontexthelpid
// BOOL SetMenuContextHelpId( HMENU , DWORD );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "55d944db-d889-468a-991a-b9779c90b44f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenuContextHelpId(HMENU arg1, uint arg2);
///
/// Sets the default menu item for the specified menu.
///
///
/// Type: HMENU
/// A handle to the menu to set the default item for.
///
///
/// Type: UINT
///
/// The identifier or position of the new default menu item or -1 for no default item. The meaning of this parameter depends on the
/// value of fByPos.
///
///
///
/// Type: UINT
///
/// The meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position.
/// See About Menus for more information.
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenudefaultitem BOOL SetMenuDefaultItem( HMENU hMenu,
// UINT uItem, UINT fByPos );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "setmenudefaultitem.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenuDefaultItem(HMENU hMenu, uint uItem, [MarshalAs(UnmanagedType.Bool)] bool fByPos);
///
/// Sets information for a specified menu.
///
/// A handle to a menu.
/// A pointer to a MENUINFO structure for the menu.
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenuinfo BOOL SetMenuInfo( HMENU , LPCMENUINFO );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "setmenuinfo.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenuInfo(HMENU hMenu, in MENUINFO lpcmi);
///
///
/// Associates the specified bitmap with a menu item. Whether the menu item is selected or clear, the system displays the appropriate
/// bitmap next to the menu item.
///
///
///
/// Type: HMENU
/// A handle to the menu containing the item to receive new check-mark bitmaps.
///
///
/// Type: UINT
/// The menu item to be changed, as determined by the uFlags parameter.
///
///
/// Type: UINT
/// Specifies how the uPosition parameter is to be interpreted. The uFlags parameter must be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MF_BYCOMMAND 0x00000000L
///
/// Indicates that uPosition gives the identifier of the menu item. If neither MF_BYCOMMAND nor MF_BYPOSITION is specified,
/// MF_BYCOMMAND is the default flag.
///
///
/// -
/// MF_BYPOSITION 0x00000400L
/// Indicates that uPosition gives the zero-based relative position of the menu item.
///
///
///
///
/// Type: HBITMAP
/// A handle to the bitmap displayed when the menu item is not selected.
///
///
/// Type: HBITMAP
/// A handle to the bitmap displayed when the menu item is selected.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// If either the hBitmapUnchecked or hBitmapChecked parameter is NULL, the system displays nothing next to the menu item for
/// the corresponding check state. If both parameters are NULL, the system displays the default check-mark bitmap when the
/// item is selected, and removes the bitmap when the item is not selected.
///
/// When the menu is destroyed, these bitmaps are not destroyed; it is up to the application to destroy them.
///
/// The selected and clear bitmaps should be monochrome. The system uses the Boolean AND operator to combine bitmaps with the menu so
/// that the white part becomes transparent and the black part becomes the menu-item color. If you use color bitmaps, the results may
/// be undesirable.
///
/// Use the GetSystemMetrics function with the CXMENUCHECK and CYMENUCHECK values to retrieve the bitmap dimensions.
/// Examples
/// For an example, see Simulating Check Boxes in a Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenuitembitmaps BOOL SetMenuItemBitmaps( HMENU hMenu,
// UINT uPosition, UINT uFlags, HBITMAP hBitmapUnchecked, HBITMAP hBitmapChecked );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "setmenuitembitmaps.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenuItemBitmaps(HMENU hMenu, uint uPosition, MenuFlags uFlags, HBITMAP hBitmapUnchecked, HBITMAP hBitmapChecked);
///
/// Changes information about a menu item.
///
///
/// Type: HMENU
/// A handle to the menu that contains the menu item.
///
///
/// Type: UINT
/// The identifier or position of the menu item to change. The meaning of this parameter depends on the value of fByPosition.
///
///
/// Type: BOOL
///
/// The meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position.
/// See About Menus for more information.
///
///
///
/// Type: LPMENUITEMINFO
///
/// A pointer to a MENUITEMINFO structure that contains information about the menu item and specifies which menu item attributes to change.
///
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, use the GetLastError function.
///
///
/// The application must call the DrawMenuBar function whenever a menu changes, whether the menu is in a displayed window.
///
/// In order for keyboard accelerators to work with bitmap or owner-drawn menu items, the owner of the menu must process the
/// WM_MENUCHAR message. See Owner-Drawn Menus and the WM_MENUCHAR Message for more information.
///
/// Examples
/// For an example, see Example of Owner-Drawn Menu Items.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setmenuiteminfoa BOOL SetMenuItemInfoA( HMENU hmenu, UINT
// item, BOOL fByPositon, LPCMENUITEMINFOA lpmii );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "setmenuiteminfo.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetMenuItemInfo(HMENU hmenu, uint item, [MarshalAs(UnmanagedType.Bool)] bool fByPositon, in MENUITEMINFO lpmii);
///
///
/// Displays a shortcut menu at the specified location and tracks the selection of items on the menu. The shortcut menu can appear
/// anywhere on the screen.
///
///
///
/// Type: HMENU
///
/// A handle to the shortcut menu to be displayed. The handle can be obtained by calling CreatePopupMenu to create a new shortcut
/// menu, or by calling GetSubMenu to retrieve a handle to a submenu associated with an existing menu item.
///
///
///
/// Type: UINT
/// Use zero of more of these flags to specify function options.
/// Use one of the following flags to specify how the function positions the shortcut menu horizontally.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_CENTERALIGN 0x0004L
/// Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter.
///
/// -
/// TPM_LEFTALIGN 0x0000L
/// Positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter.
///
/// -
/// TPM_RIGHTALIGN 0x0008L
/// Positions the shortcut menu so that its right side is aligned with the coordinate specified by the x parameter.
///
///
/// Use one of the following flags to specify how the function positions the shortcut menu vertically.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_BOTTOMALIGN 0x0020L
/// Positions the shortcut menu so that its bottom side is aligned with the coordinate specified by the y parameter.
///
/// -
/// TPM_TOPALIGN 0x0000L
/// Positions the shortcut menu so that its top side is aligned with the coordinate specified by the y parameter.
///
/// -
/// TPM_VCENTERALIGN 0x0010L
/// Centers the shortcut menu vertically relative to the coordinate specified by the y parameter.
///
///
/// Use the following flags to control discovery of the user selection without having to set up a parent window for the menu.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_NONOTIFY 0x0080L
/// The function does not send notification messages when the user clicks a menu item.
///
/// -
/// TPM_RETURNCMD 0x0100L
/// The function returns the menu item identifier of the user's selection in the return value.
///
///
/// Use one of the following flags to specify which mouse button the shortcut menu tracks.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_LEFTBUTTON 0x0000L
/// The user can select menu items with only the left mouse button.
///
/// -
/// TPM_RIGHTBUTTON 0x0002L
/// The user can select menu items with both the left and right mouse buttons.
///
///
///
/// Use any reasonable combination of the following flags to modify the animation of a menu. For example, by selecting a horizontal
/// and a vertical flag, you can achieve diagonal animation.
///
///
///
/// Value
/// Meaning
///
/// -
/// TPM_HORNEGANIMATION 0x0800L
/// Animates the menu from right to left.
///
/// -
/// TPM_HORPOSANIMATION 0x0400L
/// Animates the menu from left to right.
///
/// -
/// TPM_NOANIMATION 0x4000L
/// Displays menu without animation.
///
/// -
/// TPM_VERNEGANIMATION 0x2000L
/// Animates the menu from bottom to top.
///
/// -
/// TPM_VERPOSANIMATION 0x1000L
/// Animates the menu from top to bottom.
///
///
///
/// For any animation to occur, the SystemParametersInfo function must set SPI_SETMENUANIMATION. Also, all the TPM_*ANIMATION
/// flags, except TPM_NOANIMATION, are ignored if menu fade animation is on. For more information, see the
/// SPI_GETMENUFADE flag in SystemParametersInfo.
///
///
/// Use the TPM_RECURSE flag to display a menu when another menu is already displayed. This is intended to support context
/// menus within a menu.
///
/// For right-to-left text layout, use TPM_LAYOUTRTL. By default, the text layout is left-to-right.
///
///
/// Type: int
/// The horizontal location of the shortcut menu, in screen coordinates.
///
///
/// Type: int
/// The vertical location of the shortcut menu, in screen coordinates.
///
///
/// Type: int
/// Reserved; must be zero.
///
///
/// Type: HWND
///
/// A handle to the window that owns the shortcut menu. This window receives all messages from the menu. The window does not receive
/// a WM_COMMAND message from the menu until the function returns. If you specify TPM_NONOTIFY in the uFlags parameter, the function
/// does not send messages to the window identified by hWnd. However, you must still pass a window handle in hWnd. It can be any
/// window handle from your application.
///
///
///
/// Type: const RECT*
/// Ignored.
///
///
/// Type: BOOL
///
/// If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item identifier of the item that the
/// user selected. If the user cancels the menu without making a selection, or if an error occurs, the return value is zero.
///
///
/// If you do not specify TPM_RETURNCMD in the uFlags parameter, the return value is nonzero if the function succeeds and zero
/// if it fails. To get extended error information, call GetLastError.
///
///
///
///
/// Call GetSystemMetrics with SM_MENUDROPALIGNMENT to determine the correct horizontal alignment flag ( TPM_LEFTALIGN
/// or TPM_RIGHTALIGN) and/or horizontal animation direction flag ( TPM_HORPOSANIMATION or TPM_HORNEGANIMATION)
/// to pass to TrackPopupMenu or TrackPopupMenuEx. This is essential for creating an optimal user experience, especially when
/// developing Microsoft Tablet PC applications.
///
/// To specify an area of the screen that the menu should not overlap, use the TrackPopupMenuEx function
///
/// To display a context menu for a notification icon, the current window must be the foreground window before the application calls
/// TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the
/// window that created the menu (if it is visible). If the current window is a child window, you must set the (top-level) parent
/// window as the foreground window.
///
///
/// However, when the current window is the foreground window, the second time this menu is displayed, it appears and then
/// immediately disappears. To correct this, you must force a task switch to the application that called TrackPopupMenu. This
/// is done by posting a benign message to the window or thread, as shown in the following code sample:
///
/// Examples
/// For an example, see Displaying a Shortcut Menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-trackpopupmenu BOOL TrackPopupMenu( HMENU hMenu, UINT
// uFlags, int x, int y, int nReserved, HWND hWnd, CONST RECT *prcRect );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "trackpopupmenu.htm")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool TrackPopupMenu(HMENU hMenu, TrackPopupMenuFlags uFlags, int x, int y, [Optional] int nReserved, HWND hWnd, [Optional] PRECT prcRect);
///
///
/// Displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. The shortcut menu can
/// appear anywhere on the screen.
///
///
///
/// Type: HMENU
///
/// A handle to the shortcut menu to be displayed. This handle can be obtained by calling the CreatePopupMenu function to create a
/// new shortcut menu or by calling the GetSubMenu function to retrieve a handle to a submenu associated with an existing menu item.
///
///
///
/// Type: UINT
/// Specifies function options.
/// Use one of the following flags to specify how the function positions the shortcut menu horizontally.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_CENTERALIGN 0x0004L
/// Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter.
///
/// -
/// TPM_LEFTALIGN 0x0000L
/// Positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter.
///
/// -
/// TPM_RIGHTALIGN 0x0008L
/// Positions the shortcut menu so that its right side is aligned with the coordinate specified by the x parameter.
///
///
/// Use one of the following flags to specify how the function positions the shortcut menu vertically.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_BOTTOMALIGN 0x0020L
/// Positions the shortcut menu so that its bottom side is aligned with the coordinate specified by the y parameter.
///
/// -
/// TPM_TOPALIGN 0x0000L
/// Positions the shortcut menu so that its top side is aligned with the coordinate specified by the y parameter.
///
/// -
/// TPM_VCENTERALIGN 0x0010L
/// Centers the shortcut menu vertically relative to the coordinate specified by the y parameter.
///
///
/// Use the following flags to control discovery of the user selection without having to set up a parent window for the menu.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_NONOTIFY 0x0080L
/// The function does not send notification messages when the user clicks a menu item.
///
/// -
/// TPM_RETURNCMD 0x0100L
/// The function returns the menu item identifier of the user's selection in the return value.
///
///
/// Use one of the following flags to specify which mouse button the shortcut menu tracks.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_LEFTBUTTON 0x0000L
/// The user can select menu items with only the left mouse button.
///
/// -
/// TPM_RIGHTBUTTON 0x0002L
/// The user can select menu items with both the left and right mouse buttons.
///
///
///
/// Use any reasonable combination of the following flags to modify the animation of a menu. For example, by selecting a horizontal
/// and a vertical flag, you can achieve diagonal animation.
///
///
///
/// Value
/// Meaning
///
/// -
/// TPM_HORNEGANIMATION 0x0800L
/// Animates the menu from right to left.
///
/// -
/// TPM_HORPOSANIMATION 0x0400L
/// Animates the menu from left to right.
///
/// -
/// TPM_NOANIMATION 0x4000L
/// Displays menu without animation.
///
/// -
/// TPM_VERNEGANIMATION 0x2000L
/// Animates the menu from bottom to top.
///
/// -
/// TPM_VERPOSANIMATION 0x1000L
/// Animates the menu from top to bottom.
///
///
///
/// For any animation to occur, the SystemParametersInfo function must set SPI_SETMENUANIMATION. Also, all the
/// TPM_*ANIMATION flags, except TPM_NOANIMATION, are ignored if menu fade animation is on. For more information, see
/// the SPI_GETMENUFADE flag in SystemParametersInfo.
///
///
/// Use the TPM_RECURSE flag to display a menu when another menu is already displayed. This is intended to support context
/// menus within a menu.
///
/// Use one of the following flags to specify whether to accommodate horizontal or vertical alignment.
///
///
/// Value
/// Meaning
///
/// -
/// TPM_HORIZONTAL 0x0000L
///
/// If the menu cannot be shown at the specified location without overlapping the excluded rectangle, the system tries to accommodate
/// the requested horizontal alignment before the requested vertical alignment.
///
///
/// -
/// TPM_VERTICAL 0x0040L
///
/// If the menu cannot be shown at the specified location without overlapping the excluded rectangle, the system tries to accommodate
/// the requested vertical alignment before the requested horizontal alignment.
///
///
///
/// The excluded rectangle is a portion of the screen that the menu should not overlap; it is specified by the lptpm parameter.
/// For right-to-left text layout, use TPM_LAYOUTRTL. By default, the text layout is left-to-right.
///
///
/// Type: int
/// The horizontal location of the shortcut menu, in screen coordinates.
///
///
/// Type: int
/// The vertical location of the shortcut menu, in screen coordinates.
///
///
/// Type: HWND
///
/// A handle to the window that owns the shortcut menu. This window receives all messages from the menu. The window does not receive
/// a WM_COMMAND message from the menu until the function returns. If you specify TPM_NONOTIFY in the fuFlags parameter, the function
/// does not send messages to the window identified by hwnd. However, you must still pass a window handle in hwnd. It can be any
/// window handle from your application.
///
///
///
/// Type: LPTPMPARAMS
///
/// A pointer to a TPMPARAMS structure that specifies an area of the screen the menu should not overlap. This parameter can be NULL.
///
///
///
/// Type: BOOL
///
/// If you specify TPM_RETURNCMD in the fuFlags parameter, the return value is the menu-item identifier of the item that the
/// user selected. If the user cancels the menu without making a selection, or if an error occurs, the return value is zero.
///
///
/// If you do not specify TPM_RETURNCMD in the fuFlags parameter, the return value is nonzero if the function succeeds and
/// zero if it fails. To get extended error information, call GetLastError.
///
///
///
///
/// Call GetSystemMetrics with SM_MENUDROPALIGNMENT to determine the correct horizontal alignment flag ( TPM_LEFTALIGN
/// or TPM_RIGHTALIGN) and/or horizontal animation direction flag ( TPM_HORPOSANIMATION or TPM_HORNEGANIMATION)
/// to pass to TrackPopupMenu or TrackPopupMenuEx. This is essential for creating an optimal user experience, especially when
/// developing Microsoft Tablet PC applications.
///
///
/// To display a context menu for a notification icon, the current window must be the foreground window before the application calls
/// TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the
/// window that created the menu (if it is visible). If the current window is a child window, you must set the (top-level) parent
/// window as the foreground window.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-trackpopupmenuex BOOL TrackPopupMenuEx( HMENU hMenu, UINT
// uFlags, int x, int y, HWND hwnd, LPTPMPARAMS lptpm );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "trackpopupmenuex.htm")]
public static extern uint TrackPopupMenuEx(HMENU hMenu, TrackPopupMenuFlags uFlags, int x, int y, HWND hwnd, [In, Optional] TPMPARAMS lptpm);
///
/// Contains information about the menu to be activated.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmdinextmenu typedef struct tagMDINEXTMENU { HMENU
// hmenuIn; HMENU hmenuNext; HWND hwndNext; } MDINEXTMENU, *PMDINEXTMENU, *LPMDINEXTMENU;
[PInvokeData("winuser.h", MSDNShortId = "mdinextmenu.htm")]
[StructLayout(LayoutKind.Sequential)]
public struct MDINEXTMENU
{
///
/// Type: HMENU
/// A handle to the current menu.
///
public HMENU hmenuIn;
///
/// Type: HMENU
/// A handle to the menu to be activated.
///
public HMENU hmenuNext;
///
/// Type: HWND
/// A handle to the window to receive the menu notification messages.
///
public HWND hwndNext;
}
///
/// Contains menu bar information.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmenubarinfo typedef struct tagMENUBARINFO { DWORD
// cbSize; RECT rcBar; HMENU hMenu; HWND hwndMenu; BOOL fBarFocused : 1; BOOL fFocused : 1; } MENUBARINFO, *PMENUBARINFO, *LPMENUBARINFO;
[PInvokeData("winuser.h", MSDNShortId = "menubarinfo.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MENUBARINFO
{
///
/// Type: DWORD
/// The size of the structure, in bytes. The caller must set this to .
///
public uint cbSize;
///
/// Type: RECT
/// The coordinates of the menu bar, popup menu, or menu item.
///
public RECT rcBar;
///
/// Type: HMENU
/// A handle to the menu bar or popup menu.
///
public HMENU hMenu;
///
/// Type: HWND
/// A handle to the submenu.
///
public HWND hwndMenu;
private uint uFlags;
///
/// Type: BOOL
/// If the menu bar or popup menu has the focus, this member is TRUE. Otherwise, the member is FALSE.
///
public bool fBarFocused { get => BitHelper.GetBit(uFlags, 0); set => BitHelper.SetBit(ref uFlags, 0, value); }
///
/// Type: BOOL
/// If the menu item has the focus, this member is TRUE. Otherwise, the member is FALSE.
///
public bool fFocused { get => BitHelper.GetBit(uFlags, 1); set => BitHelper.SetBit(ref uFlags, 1, value); }
}
///
///
/// Defines the header for an extended menu template. This structure definition is for explanation only; it is not present in any
/// standard header file.
///
///
///
///
/// An extended menu template consists of a MENUEX_TEMPLATE_HEADER structure followed by one or more contiguous
/// MENUEX_TEMPLATE_ITEM structures. The MENUEX_TEMPLATE_ITEM structures, which are variable in length, are aligned on
/// DWORD boundaries. To create a menu from an extended menu template in memory, use the LoadMenuIndirect function.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/menurc/menuex-template-header typedef struct { WORD wVersion; WORD wOffset; DWORD
// dwHelpId; } MENUEX_TEMPLATE_HEADER;
[PInvokeData("winuser.h", MSDNShortId = "df763349-7127-482e-8613-74e68addde5d")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MENUEX_TEMPLATE_HEADER
{
/// The template version number. This member must be 1 for extended menu templates.
public ushort wVersion;
///
/// The offset to the first MENUEX_TEMPLATE_ITEM structure, relative to the end of this structure member. If the first item
/// definition immediately follows the dwHelpId member, this member should be 4.
///
public ushort wOffset;
/// The help identifier of menu bar.
public uint dwHelpId;
}
///
///
/// Defines a menu item in an extended menu template. This structure definition is for explanation only; it is not present in any
/// standard header file.
///
///
///
///
/// An extended menu template consists of a MENUEX_TEMPLATE_HEADER structure followed by one or more contiguous
/// MENUEX_TEMPLATE_ITEM structures. The MENUEX_TEMPLATE_ITEM structures, which are variable in length, are aligned on
/// DWORD boundaries. To create a menu from an extended menu template in memory, use the LoadMenuIndirect function.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/menurc/menuex-template-item typedef struct { DWORD dwHelpId; DWORD dwType; DWORD
// dwState; DWORD menuId; WORD bResInfo; WCHAR szText; DWORD dwHelpId; } MENUEX_TEMPLATE_ITEM;
[PInvokeData("winuser.h", MSDNShortId = "f6e2fd0a-16b8-48e3-8597-341085a7adbd")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MENUEX_TEMPLATE_ITEM
{
///
/// The menu item type. This member can be a combination of the type (beginning with MFT) values listed with the MENUITEMINFO structure.
///
public MenuItemType dwType;
///
/// The menu item state. This member can be a combination of the state (beginning with MFS) values listed with the MENUITEMINFO structure.
///
public MenuItemState dwState;
///
/// The menu item identifier. This is an application-defined value that identifies the menu item. In an extended menu resource,
/// items that open drop-down menus or submenus as well as command items can have identifiers.
///
public uint menuId;
///
/// Specifies whether the menu item is the last item in the menu bar, drop-down menu, submenu, or shortcut menu and whether it is
/// an item that opens a drop-down menu or submenu. This member can be zero or more of these values. For 32-bit applications,
/// this member is a word; for 16-bit applications, it is a byte.
///
public ushort bResInfo;
///
/// The menu item text. This member is a null-terminated Unicode string, aligned on a word boundary. The size of the menu item
/// definition varies depending on the length of this string.
///
public string szText;
///
/// The help identifier for a drop-down menu or submenu. This member, which is included only for items that open drop-down menus
/// or submenus, is located at the first DWORD boundary following the variable-length szText member.
///
public uint dwHelpId;
}
///
/// Contains information about the menu that the mouse cursor is on.
///
///
///
/// The MENUGETOBJECTINFO structure is used only in drag-and-drop menus. When the WM_MENUGETOBJECT message is sent, lParam is
/// a pointer to this structure.
///
/// To create a drag-and-drop menu, call SetMenuInfo with MNS_DRAGDROP set.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmenugetobjectinfo typedef struct tagMENUGETOBJECTINFO {
// DWORD dwFlags; UINT uPos; HMENU hmenu; PVOID riid; PVOID pvObj; } MENUGETOBJECTINFO, *PMENUGETOBJECTINFO;
[PInvokeData("winuser.h", MSDNShortId = "menugetobjectinfo.htm")]
[StructLayout(LayoutKind.Sequential)]
public struct MENUGETOBJECTINFO
{
///
/// Type: DWORD
///
/// The position of the mouse cursor with respect to the item indicated by uPos. It is a bitmask of the following values:
///
///
///
/// Value
/// Meaning
///
/// -
/// MNGOF_BOTTOMGAP 0x00000002
/// The mouse is on the bottom of the item indicated by uPos.
///
/// -
/// MNGOF_TOPGAP 0x00000001
/// The mouse is on the top of the item indicated by uPos.
///
///
/// If neither MNGOF_BOTTOMGAP nor MNGOF_TOPGAP is set, then the mouse is directly on the item indicated by uPos.
///
public MNGOF dwFlags;
///
/// Type: UINT
/// The position of the item the mouse cursor is on.
///
public uint uPos;
///
/// Type: HMENU
/// A handle to the menu the mouse cursor is on.
///
public HMENU hmenu;
///
/// Type: PVOID
/// The identifier of the requested interface. Currently it can only be IDropTarget.
///
public IntPtr riid;
///
/// Type: PVOID
///
/// A pointer to the interface corresponding to the riid member. This pointer is to be returned by the application when
/// processing the message.
///
///
public IntPtr pvObj;
}
///
/// Contains information about a menu.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmenuinfo typedef struct tagMENUINFO { DWORD cbSize;
// DWORD fMask; DWORD dwStyle; UINT cyMax; HBRUSH hbrBack; DWORD dwContextHelpID; ULONG_PTR dwMenuData; } MENUINFO, *LPMENUINFO;
[PInvokeData("winuser.h", MSDNShortId = "menuinfo.htm")]
[StructLayout(LayoutKind.Sequential)]
public struct MENUINFO
{
///
/// Type: DWORD
/// The size of the structure, in bytes. The caller must set this member to .
///
public uint cbSize;
///
/// Type: DWORD
///
/// Indicates the members to be retrieved or set (except for MIM_APPLYTOSUBMENUS). This member can be one or more of the
/// following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// MIM_APPLYTOSUBMENUS 0x80000000
/// Settings apply to the menu and all of its submenus. SetMenuInfo uses this flag and GetMenuInfo ignores this flag
///
/// -
/// MIM_BACKGROUND 0x00000002
/// Retrieves or sets the hbrBack member.
///
/// -
/// MIM_HELPID 0x00000004
/// Retrieves or sets the dwContextHelpID member.
///
/// -
/// MIM_MAXHEIGHT 0x00000001
/// Retrieves or sets the cyMax member.
///
/// -
/// MIM_MENUDATA 0x00000008
/// Retrieves or sets the dwMenuData member.
///
/// -
/// MIM_STYLE 0x00000010
/// Retrieves or sets the dwStyle member.
///
///
///
public MenuInfoMember fMask;
///
/// Type: DWORD
/// The menu style. This member can be one or more of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MNS_AUTODISMISS 0x10000000
/// Menu automatically ends when mouse is outside the menu for approximately 10 seconds.
///
/// -
/// MNS_CHECKORBMP 0x04000000
///
/// The same space is reserved for the check mark and the bitmap. If the check mark is drawn, the bitmap is not. All checkmarks
/// and bitmaps are aligned. Used for menus where some items use checkmarks and some use bitmaps.
///
///
/// -
/// MNS_DRAGDROP 0x20000000
/// Menu items are OLE drop targets or drag sources. Menu owner receives WM_MENUDRAG and WM_MENUGETOBJECT messages.
///
/// -
/// MNS_MODELESS 0x40000000
/// Menu is modeless; that is, there is no menu modal message loop while the menu is active.
///
/// -
/// MNS_NOCHECK 0x80000000
///
/// No space is reserved to the left of an item for a check mark. The item can still be selected, but the check mark will not
/// appear next to the item.
///
///
/// -
/// MNS_NOTIFYBYPOS 0x08000000
///
/// Menu owner receives a WM_MENUCOMMAND message instead of a WM_COMMAND message when the user makes a selection. MNS_NOTIFYBYPOS
/// is a menu header style and has no effect when applied to individual sub menus.
///
///
///
///
public MenuInfoStyle dwStyle;
///
/// Type: UINT
///
/// The maximum height of the menu in pixels. When the menu items exceed the space available, scroll bars are automatically used.
/// The default (0) is the screen height.
///
///
public uint cyMax;
///
/// Type: HBRUSH
/// A handle to the brush to be used for the menu's background.
///
public HBRUSH hbrBack;
///
/// Type: DWORD
/// The context help identifier. This is the same value used in the GetMenuContextHelpId and SetMenuContextHelpId functions.
///
public uint dwContextHelpID;
///
/// Type: ULONG_PTR
/// An application-defined value.
///
public IntPtr dwMenuData;
}
///
/// Contains information about a menu item.
///
///
/// The MENUITEMINFO structure is used with the GetMenuItemInfo, InsertMenuItem, and SetMenuItemInfo functions.
/// The menu can display items using text, bitmaps, or both.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmenuiteminfoa typedef struct tagMENUITEMINFOA { UINT
// cbSize; UINT fMask; UINT fType; UINT fState; UINT wID; HMENU hSubMenu; HBITMAP hbmpChecked; HBITMAP hbmpUnchecked; ULONG_PTR
// dwItemData; LPSTR dwTypeData; UINT cch; HBITMAP hbmpItem; } MENUITEMINFOA, *LPMENUITEMINFOA;
[PInvokeData("winuser.h", MSDNShortId = "menuiteminfo.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MENUITEMINFO
{
///
/// Type: UINT
/// The size of the structure, in bytes. The caller must set this member to .
///
public uint cbSize;
///
/// Type: UINT
/// Indicates the members to be retrieved or set. This member can be one or more of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// MIIM_BITMAP 0x00000080
/// Retrieves or sets the hbmpItem member.
///
/// -
/// MIIM_CHECKMARKS 0x00000008
/// Retrieves or sets the hbmpChecked and hbmpUnchecked members.
///
/// -
/// MIIM_DATA 0x00000020
/// Retrieves or sets the dwItemData member.
///
/// -
/// MIIM_FTYPE 0x00000100
/// Retrieves or sets the fType member.
///
/// -
/// MIIM_ID 0x00000002
/// Retrieves or sets the wID member.
///
/// -
/// MIIM_STATE 0x00000001
/// Retrieves or sets the fState member.
///
/// -
/// MIIM_STRING 0x00000040
/// Retrieves or sets the dwTypeData member.
///
/// -
/// MIIM_SUBMENU 0x00000004
/// Retrieves or sets the hSubMenu member.
///
/// -
/// MIIM_TYPE 0x00000010
/// Retrieves or sets the fType and dwTypeData members. MIIM_TYPE is replaced by MIIM_BITMAP, MIIM_FTYPE, and MIIM_STRING.
///
///
///
public MenuItemInfoMask fMask;
///
/// Type: UINT
/// The menu item type. This member can be one or more of the following values.
///
/// The MFT_BITMAP, MFT_SEPARATOR, and MFT_STRING values cannot be combined with one another. Set
/// fMask to MIIM_TYPE to use fType.
///
/// fType is used only if fMask has a value of MIIM_FTYPE.
///
///
/// Value
/// Meaning
///
/// -
/// MFT_BITMAP 0x00000004L
///
/// Displays the menu item using a bitmap. The low-order word of the dwTypeData member is the bitmap handle, and the cch member
/// is ignored. MFT_BITMAP is replaced by MIIM_BITMAP and hbmpItem.
///
///
/// -
/// MFT_MENUBARBREAK 0x00000020L
///
/// Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For
/// a drop-down menu, submenu, or shortcut menu, a vertical line separates the new column from the old.
///
///
/// -
/// MFT_MENUBREAK 0x00000040L
///
/// Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For
/// a drop-down menu, submenu, or shortcut menu, the columns are not separated by a vertical line.
///
///
/// -
/// MFT_OWNERDRAW 0x00000100L
///
/// Assigns responsibility for drawing the menu item to the window that owns the menu. The window receives a WM_MEASUREITEM
/// message before the menu is displayed for the first time, and a WM_DRAWITEM message whenever the appearance of the menu item
/// must be updated. If this value is specified, the dwTypeData member contains an application-defined value.
///
///
/// -
/// MFT_RADIOCHECK 0x00000200L
/// Displays selected menu items using a radio-button mark instead of a check mark if the hbmpChecked member is NULL.
///
/// -
/// MFT_RIGHTJUSTIFY 0x00004000L
/// Right-justifies the menu item and any subsequent items. This value is valid only if the menu item is in a menu bar.
///
/// -
/// MFT_RIGHTORDER 0x00002000L
///
/// Specifies that menus cascade right-to-left (the default is left-to-right). This is used to support right-to-left languages,
/// such as Arabic and Hebrew.
///
///
/// -
/// MFT_SEPARATOR 0x00000800L
///
/// Specifies that the menu item is a separator. A menu item separator appears as a horizontal dividing line. The dwTypeData and
/// cch members are ignored. This value is valid only in a drop-down menu, submenu, or shortcut menu.
///
///
/// -
/// MFT_STRING 0x00000000L
///
/// Displays the menu item using a text string. The dwTypeData member is the pointer to a null-terminated string, and the cch
/// member is the length of the string. MFT_STRING is replaced by MIIM_STRING.
///
///
///
///
public MenuItemType fType;
///
/// Type: UINT
///
/// The menu item state. This member can be one or more of these values. Set fMask to MIIM_STATE to use fState.
///
///
///
/// Value
/// Meaning
///
/// -
/// MFS_CHECKED 0x00000008L
/// Checks the menu item. For more information about selected menu items, see the hbmpChecked member.
///
/// -
/// MFS_DEFAULT 0x00001000L
///
/// Specifies that the menu item is the default. A menu can contain only one default menu item, which is displayed in bold.
///
///
/// -
/// MFS_DISABLED 0x00000003L
/// Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_GRAYED.
///
/// -
/// MFS_ENABLED 0x00000000L
/// Enables the menu item so that it can be selected. This is the default state.
///
/// -
/// MFS_GRAYED 0x00000003L
/// Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_DISABLED.
///
/// -
/// MFS_HILITE 0x00000080L
/// Highlights the menu item.
///
/// -
/// MFS_UNCHECKED 0x00000000L
/// Unchecks the menu item. For more information about clear menu items, see the hbmpChecked member.
///
/// -
/// MFS_UNHILITE 0x00000000L
/// Removes the highlight from the menu item. This is the default state.
///
///
///
public MenuItemState fState;
///
/// Type: UINT
/// An application-defined value that identifies the menu item. Set fMask to MIIM_ID to use wID.
///
public uint wID;
///
/// Type: HMENU
///
/// A handle to the drop-down menu or submenu associated with the menu item. If the menu item is not an item that opens a
/// drop-down menu or submenu, this member is NULL. Set fMask to MIIM_SUBMENU to use hSubMenu.
///
///
public HMENU hSubMenu;
///
/// Type: HBITMAP
///
/// A handle to the bitmap to display next to the item if it is selected. If this member is NULL, a default bitmap is
/// used. If the MFT_RADIOCHECK type value is specified, the default bitmap is a bullet. Otherwise, it is a check mark.
/// Set fMask to MIIM_CHECKMARKS to use hbmpChecked.
///
///
public HBITMAP hbmpChecked;
///
/// Type: HBITMAP
///
/// A handle to the bitmap to display next to the item if it is not selected. If this member is NULL, no bitmap is used.
/// Set fMask to MIIM_CHECKMARKS to use hbmpUnchecked.
///
///
public HBITMAP hbmpUnchecked;
///
/// Type: ULONG_PTR
/// An application-defined value associated with the menu item. Set fMask to MIIM_DATA to use dwItemData.
///
public IntPtr dwItemData;
///
/// Type: LPTSTR
///
/// The contents of the menu item. The meaning of this member depends on the value of fType and is used only if the
/// MIIM_TYPE flag is set in the fMask member.
///
///
/// To retrieve a menu item of type MFT_STRING, first find the size of the string by setting the dwTypeData member
/// of MENUITEMINFO to NULL and then calling GetMenuItemInfo. The value of cch+1 is the size needed. Then
/// allocate a buffer of this size, place the pointer to the buffer in dwTypeData, increment cch, and call
/// GetMenuItemInfo once again to fill the buffer with the string. If the retrieved menu item is of some other type, then
/// GetMenuItemInfo sets the dwTypeData member to a value whose type is specified by the fType member.
///
///
/// When using with the SetMenuItemInfo function, this member should contain a value whose type is specified by the fType member.
///
/// dwTypeData is used only if the MIIM_STRING flag is set in the fMask member
///
public StrPtrAuto dwTypeData;
///
/// Type: UINT
///
/// The length of the menu item text, in characters, when information is received about a menu item of the MFT_STRING
/// type. However, cch is used only if the MIIM_TYPE flag is set in the fMask member and is zero otherwise.
/// Also, cch is ignored when the content of a menu item is set by calling SetMenuItemInfo.
///
///
/// Note that, before calling GetMenuItemInfo, the application must set cch to the length of the buffer pointed to by the
/// dwTypeData member. If the retrieved menu item is of type MFT_STRING (as indicated by the fType member),
/// then GetMenuItemInfo changes cch to the length of the menu item text. If the retrieved menu item is of some
/// other type, GetMenuItemInfo sets the cch field to zero.
///
/// The cch member is used when the MIIM_STRING flag is set in the fMask member.
///
public uint cch;
///
/// Type: HBITMAP
///
/// A handle to the bitmap to be displayed, or it can be one of the values in the following table. It is used when the
/// MIIM_BITMAP flag is set in the fMask member.
///
///
///
/// Value
/// Meaning
///
/// -
/// HBMMENU_CALLBACK ((HBITMAP) -1)
///
/// A bitmap that is drawn by the window that owns the menu. The application must process the WM_MEASUREITEM and WM_DRAWITEM messages.
///
///
/// -
/// HBMMENU_MBAR_CLOSE ((HBITMAP) 5)
/// Close button for the menu bar.
///
/// -
/// HBMMENU_MBAR_CLOSE_D ((HBITMAP) 6)
/// Disabled close button for the menu bar.
///
/// -
/// HBMMENU_MBAR_MINIMIZE ((HBITMAP) 3)
/// Minimize button for the menu bar.
///
/// -
/// HBMMENU_MBAR_MINIMIZE_D ((HBITMAP) 7)
/// Disabled minimize button for the menu bar.
///
/// -
/// HBMMENU_MBAR_RESTORE ((HBITMAP) 2)
/// Restore button for the menu bar.
///
/// -
/// HBMMENU_POPUP_CLOSE ((HBITMAP) 8)
/// Close button for the submenu.
///
/// -
/// HBMMENU_POPUP_MAXIMIZE ((HBITMAP) 10)
/// Maximize button for the submenu.
///
/// -
/// HBMMENU_POPUP_MINIMIZE ((HBITMAP) 11)
/// Minimize button for the submenu.
///
/// -
/// HBMMENU_POPUP_RESTORE ((HBITMAP) 9)
/// Restore button for the submenu.
///
/// -
/// HBMMENU_SYSTEM ((HBITMAP) 1)
/// Windows icon or the icon of the window specified in dwItemData.
///
///
///
public HBITMAP hbmpItem;
/// Initializes a new instance of the struct.
/// An application-defined value that identifies the menu item.
/// The menu type.
/// The menu state.
///
/// A handle to the drop-down menu or submenu associated with the menu item. If the menu item is not an item that opens a
/// drop-down menu or submenu, this member is .
///
public MENUITEMINFO(uint id, MenuItemType type = MenuItemType.MFT_STRING, MenuItemState state = MenuItemState.MFS_ENABLED, HMENU subMenu = default) : this()
{
cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO));
wID = id;
fMask = MenuItemInfoMask.MIIM_ID;
fType = type;
if (type != 0) fMask |= MenuItemInfoMask.MIIM_TYPE;
fState = state;
if (state != 0) fMask |= MenuItemInfoMask.MIIM_STATE;
hSubMenu = subMenu;
if (subMenu != default) fMask |= MenuItemInfoMask.MIIM_SUBMENU;
}
}
///
/// Defines a menu item in a menu template.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-menuitemtemplate typedef struct MENUITEMTEMPLATE { WORD
// mtOption; WORD mtID; WCHAR mtString[1]; } *PMENUITEMTEMPLATE;
[PInvokeData("winuser.h", MSDNShortId = "menuitemtemplate.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 2, Size = 6)]
public struct MENUITEMTEMPLATE
{
///
/// Type: WORD
///
/// One or more of the following predefined menu options that control the appearance of the menu item as shown in the following table.
///
///
///
/// Value
/// Meaning
///
/// -
/// MF_CHECKED 0x00000008L
/// Indicates that the menu item has a check mark next to it.
///
/// -
/// MF_GRAYED 0x00000001L
/// Indicates that the menu item is initially inactive and drawn with a gray effect.
///
/// -
/// MF_HELP 0x00004000L
/// Indicates that the menu item has a vertical separator to its left.
///
/// -
/// MF_MENUBARBREAK 0x00000020L
/// Indicates that the menu item is placed in a new column. The old and new columns are separated by a bar.
///
/// -
/// MF_MENUBREAK 0x00000040L
/// Indicates that the menu item is placed in a new column.
///
/// -
/// MF_OWNERDRAW 0x00000100L
///
/// Indicates that the owner window of the menu is responsible for drawing all visual aspects of the menu item, including
/// highlighted, selected, and inactive states. This option is not valid for an item in a menu bar.
///
///
/// -
/// MF_POPUP 0x00000010L
/// Indicates that the item is one that opens a drop-down menu or submenu.
///
///
///
public ushort mtOption;
///
/// Type: WORD
///
/// The menu item identifier of a command item; a command item sends a command message to its owner window. The
/// MENUITEMTEMPLATE structure for an item that opens a drop-down menu or submenu does not contain the mtID member.
///
///
public ushort mtID;
///
/// Type: WCHAR[1]
/// The menu item.
///
public ushort mtString;
}
///
/// Defines the header for a menu template. A complete menu template consists of a header and one or more menu item lists.
///
///
/// One or more MENUITEMTEMPLATE structures are combined to form the menu item list.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-menuitemtemplateheader typedef struct
// MENUITEMTEMPLATEHEADER { WORD versionNumber; WORD offset; } *PMENUITEMTEMPLATEHEADER;
[PInvokeData("winuser.h", MSDNShortId = "menuitemtemplateheader.htm")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 2)]
public struct MENUITEMTEMPLATEHEADER
{
///
/// Type: WORD
/// The version number. This member must be zero.
///
public ushort versionNumber;
///
/// Type: WORD
///
/// The offset, in bytes, from the end of the header. The menu item list begins at this offset. Usually, this member is zero, and
/// the menu item list follows immediately after the header.
///
///
public ushort offset;
}
/// Provides a for that is disposed using .
public class SafeHMENU : SafeHANDLE, IUserHandle
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHMENU(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHMENU() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HMENU(SafeHMENU h) => h.handle;
///
protected override bool InternalReleaseHandle() => DestroyMenu(this);
}
///
/// Contains extended parameters for the TrackPopupMenuEx function.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagtpmparams typedef struct tagTPMPARAMS { UINT cbSize;
// RECT rcExclude; } TPMPARAMS;
[PInvokeData("winuser.h", MSDNShortId = "tpmparams.htm")]
[StructLayout(LayoutKind.Sequential)]
public class TPMPARAMS
{
///
/// Type: UINT
/// The size of structure, in bytes.
///
public uint cbSize;
///
/// Type: RECT
/// The rectangle to be excluded when positioning the window, in screen coordinates.
///
public RECT rcExclude;
///
/// Initializes a new instance of the class.
///
/// The rectangle to exclude.
public TPMPARAMS(RECT rExclude)
{
cbSize = (uint)Marshal.SizeOf(typeof(TPMPARAMS));
rcExclude = rExclude;
}
}
}
}