public bool AppendMenu( int id, MenuItemFlag flag, string text, EventHandler menuClickEvent) { if ((flag & MenuItemFlag.MF_SEPARATOR) != MenuItemFlag.MF_SEPARATOR && !ValidateID(id)) { throw new ArgumentOutOfRangeException( "id", string.Format( "菜单ID只能在{0}-{1}之间取值。", 0, 0xF000)); } bool sucess = Win32API.AppendMenu( _hMenu, (int)flag, id, text); if (sucess && menuClickEvent != null) { MenuClickEventList.Add(id, menuClickEvent); } return(sucess); }
public static bool AddMenuItem(IntPtr hWnd, Win32API.MenuItemInfoType uFlags, uint uIDNewItem, string lpNewItem) { var hSysMenu = Win32API.GetSystemMenu(hWnd, false); if (hSysMenu != IntPtr.Zero) { return(Win32API.AppendMenu(hSysMenu, uFlags, uIDNewItem, lpNewItem)); } return(false); }