Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Add several menu-related methods #445

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/User32.Tests/User32Facts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using PInvoke;
using Xunit;
Expand Down Expand Up @@ -147,4 +148,13 @@ public void SetWindowLongPtr_Test()
}
}
}

[Fact]
public void MENUBARINFO_MarshalSizeAsExpected()
{
MENUBARINFO info = default;
int expectedSize = IntPtr.Size == 4 ? 0x20 : 0x30;
Assert.Equal(expectedSize, Marshal.SizeOf(info));
Assert.Equal(expectedSize, MENUBARINFO.Create().cbSize);
}
}
6 changes: 3 additions & 3 deletions src/User32/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ PInvoke.User32.MENUITEMINFO.MENUITEMINFO() -> void
PInvoke.User32.MENUITEMINFO.cbSize -> int
PInvoke.User32.MENUITEMINFO.cch -> int
PInvoke.User32.MENUITEMINFO.dwItemData -> System.IntPtr
PInvoke.User32.MENUITEMINFO.dwTypeData -> string
PInvoke.User32.MENUITEMINFO.dwTypeData -> char*
PInvoke.User32.MENUITEMINFO.fMask -> PInvoke.User32.MenuMembersMask
PInvoke.User32.MENUITEMINFO.fState -> PInvoke.User32.MenuItemState
PInvoke.User32.MENUITEMINFO.fType -> PInvoke.User32.MenuItemType
Expand Down Expand Up @@ -1884,7 +1884,7 @@ static extern PInvoke.User32.GetCursorPos(out PInvoke.POINT lpPoint) -> bool
static extern PInvoke.User32.GetDesktopWindow() -> System.IntPtr
static extern PInvoke.User32.GetForegroundWindow() -> System.IntPtr
static extern PInvoke.User32.GetKeyState(int nVirtKey) -> short
static extern PInvoke.User32.GetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, ref PInvoke.User32.MENUITEMINFO lpmii) -> bool
static extern PInvoke.User32.GetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, PInvoke.User32.MENUITEMINFO* lpmii) -> bool
static extern PInvoke.User32.GetMessage(PInvoke.User32.MSG* lpMsg, System.IntPtr hWnd, PInvoke.User32.WindowMessage wMsgFilterMin, PInvoke.User32.WindowMessage wMsgFilterMax) -> int
static extern PInvoke.User32.GetMonitorInfo(System.IntPtr hMonitor, PInvoke.User32.MONITORINFO* lpmi) -> bool
static extern PInvoke.User32.GetMonitorInfoEx(System.IntPtr hMonitor, PInvoke.User32.MONITORINFOEX* lpmi) -> bool
Expand Down Expand Up @@ -1957,7 +1957,7 @@ static extern PInvoke.User32.SetCapture(System.IntPtr hWnd) -> System.IntPtr
static extern PInvoke.User32.SetClipboardData(int uFormat, void* hMem) -> void*
static extern PInvoke.User32.SetCursorPos(int X, int Y) -> bool
static extern PInvoke.User32.SetForegroundWindow(System.IntPtr hWnd) -> bool
static extern PInvoke.User32.SetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, ref PInvoke.User32.MENUITEMINFO lpmii) -> bool
static extern PInvoke.User32.SetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, PInvoke.User32.MENUITEMINFO* lpmii) -> bool
static extern PInvoke.User32.SetParent(System.IntPtr hWndChild, System.IntPtr hWndNewParent) -> System.IntPtr
static extern PInvoke.User32.SetProcessDPIAware() -> bool
static extern PInvoke.User32.SetProcessWindowStation(PInvoke.User32.SafeWindowStationHandle hWinSta) -> bool
Expand Down
71 changes: 70 additions & 1 deletion src/User32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ PInvoke.User32.DPI_HOSTING_BEHAVIOR
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_DEFAULT = 0 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_INVALID = -1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
PInvoke.User32.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_MIXED = 1 -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
PInvoke.User32.GetMenuDefaultItemFlags
PInvoke.User32.GetMenuDefaultItemFlags.GMDI_GOINTOPOPUPS = 2 -> PInvoke.User32.GetMenuDefaultItemFlags
PInvoke.User32.GetMenuDefaultItemFlags.GMDI_USEDISABLED = 1 -> PInvoke.User32.GetMenuDefaultItemFlags
PInvoke.User32.GetMenuStateFlags
PInvoke.User32.GetMenuStateFlags.MF_BYCOMMAND = 0 -> PInvoke.User32.GetMenuStateFlags
PInvoke.User32.GetMenuStateFlags.MF_BYPOSITION = 1024 -> PInvoke.User32.GetMenuStateFlags
PInvoke.User32.GetNextWindowCommands
PInvoke.User32.GetNextWindowCommands.GW_HWNDNEXT = 2 -> PInvoke.User32.GetNextWindowCommands
PInvoke.User32.GetNextWindowCommands.GW_HWNDPREV = 3 -> PInvoke.User32.GetNextWindowCommands
Expand All @@ -68,6 +74,46 @@ PInvoke.User32.LoadImageFlags.LR_LOADTRANSPARENT = 32 -> PInvoke.User32.LoadImag
PInvoke.User32.LoadImageFlags.LR_MONOCHROME = 1 -> PInvoke.User32.LoadImageFlags
PInvoke.User32.LoadImageFlags.LR_SHARED = 32768 -> PInvoke.User32.LoadImageFlags
PInvoke.User32.LoadImageFlags.LR_VGACOLOR = 128 -> PInvoke.User32.LoadImageFlags
PInvoke.User32.MENUBARINFO
PInvoke.User32.MENUBARINFO.MENUBARINFO() -> void
PInvoke.User32.MENUBARINFO.cbSize -> int
PInvoke.User32.MENUBARINFO.fBarFocused.get -> bool
PInvoke.User32.MENUBARINFO.fBarFocused.set -> void
PInvoke.User32.MENUBARINFO.fFocused.get -> bool
PInvoke.User32.MENUBARINFO.fFocused.set -> void
PInvoke.User32.MENUBARINFO.hMenu -> System.IntPtr
PInvoke.User32.MENUBARINFO.hwndMenu -> System.IntPtr
PInvoke.User32.MENUBARINFO.rcBar -> PInvoke.RECT
PInvoke.User32.MENUINFO
PInvoke.User32.MENUINFO.Create() -> PInvoke.User32.MENUINFO
PInvoke.User32.MENUINFO.MENUINFO() -> void
PInvoke.User32.MENUINFO.cbSize -> int
PInvoke.User32.MENUINFO.cyMax -> uint
PInvoke.User32.MENUINFO.dwContextHelpID -> uint
PInvoke.User32.MENUINFO.dwMenuData -> System.UIntPtr
PInvoke.User32.MENUINFO.dwStyle -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MENUINFO.fMask -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MENUINFO.hbrBack -> System.IntPtr
PInvoke.User32.MENUITEMINFO.dwTypeData_IntPtr.get -> System.IntPtr
PInvoke.User32.MENUITEMINFO.dwTypeData_IntPtr.set -> void
PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_APPLYTOSUBMENUS = 2147483648 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_BACKGROUND = 2 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_HELPID = 4 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_MAXHEIGHT = 1 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_MENUDATA = 8 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoMask.MIM_STYLE = 16 -> PInvoke.User32.MenuInfoMask
PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_AUTODISMISS = 268435456 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_CHECKORBMP = 67108864 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_DRAGDROP = 536870912 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_MODELESS = 1073741824 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_NOCHECK = 2147483648 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuInfoStyle.MNS_NOTIFYBYPOS = 134217728 -> PInvoke.User32.MenuInfoStyle
PInvoke.User32.MenuObject
PInvoke.User32.MenuObject.OBJID_CLIENT = 4294967292 -> PInvoke.User32.MenuObject
PInvoke.User32.MenuObject.OBJID_MENU = 4294967293 -> PInvoke.User32.MenuObject
PInvoke.User32.MenuObject.OBJID_SYSMENU = 4294967295 -> PInvoke.User32.MenuObject
PInvoke.User32.SafeCursorHandle
PInvoke.User32.SafeCursorHandle.SafeCursorHandle() -> void
PInvoke.User32.SafeCursorHandle.SafeCursorHandle(System.IntPtr preexistingHandle, bool ownsHandle = true) -> void
Expand Down Expand Up @@ -107,11 +153,21 @@ static PInvoke.User32.CreateWindowEx(PInvoke.User32.WindowStylesEx dwExStyle, sh
static PInvoke.User32.CreateWindowEx(PInvoke.User32.WindowStylesEx dwExStyle, short lpClassName, string lpWindowName, PInvoke.User32.WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, System.IntPtr hWndParent, System.IntPtr hMenu, System.IntPtr hInstance, void* lpParam) -> System.IntPtr
static PInvoke.User32.GetCursorInfo(System.IntPtr pci) -> bool
static PInvoke.User32.GetCursorInfo(out PInvoke.User32.CURSORINFO pci) -> bool
static PInvoke.User32.GetMenuBarInfo(System.IntPtr hwnd, PInvoke.User32.MenuObject idObject, int idItem, System.IntPtr pmbi) -> bool
static PInvoke.User32.GetMenuInfo(System.IntPtr hMenu, System.IntPtr lpMenuInfo) -> bool
static PInvoke.User32.GetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, System.IntPtr lpmii) -> bool
static PInvoke.User32.GetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, ref PInvoke.User32.MENUITEMINFO lpmii) -> bool
static PInvoke.User32.GetMenuItemRect(System.IntPtr hWnd, System.IntPtr hMenu, uint uItem, System.IntPtr lprcItem) -> bool
static PInvoke.User32.GetMenuString(System.IntPtr hMenu, uint uIDItem, System.IntPtr lpString, int cchMax, PInvoke.User32.GetMenuStateFlags flags) -> int
static PInvoke.User32.GetMenuString(System.IntPtr hMenu, uint uIDItem, char[] lpString, int cchMax, PInvoke.User32.GetMenuStateFlags flags) -> int
static PInvoke.User32.GetNextWindow(System.IntPtr hWnd, PInvoke.User32.GetNextWindowCommands wCmd) -> System.IntPtr
static PInvoke.User32.LoadCursor(System.IntPtr hInstance, System.IntPtr lpCursorName) -> PInvoke.User32.SafeCursorHandle
static PInvoke.User32.LoadCursor(System.IntPtr hInstance, char[] lpCursorName) -> PInvoke.User32.SafeCursorHandle
static PInvoke.User32.LoadImage(System.IntPtr hInst, System.IntPtr name, PInvoke.User32.ImageType type, int cx, int cy, PInvoke.User32.LoadImageFlags fuLoad) -> System.IntPtr
static PInvoke.User32.LoadImage(System.IntPtr hInst, char[] name, PInvoke.User32.ImageType type, int cx, int cy, PInvoke.User32.LoadImageFlags fuLoad) -> System.IntPtr
static PInvoke.User32.MENUBARINFO.Create() -> PInvoke.User32.MENUBARINFO
static PInvoke.User32.SetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, PInvoke.User32.MENUITEMINFO lpmii) -> bool
static PInvoke.User32.SetMenuItemInfo(System.IntPtr hMenu, uint uItem, bool fByPosition, System.IntPtr lpmii) -> bool
static PInvoke.User32.SetWindowLongPtr(System.IntPtr hWnd, PInvoke.User32.WindowLongIndexFlags nIndex, System.IntPtr dwNewLong) -> System.IntPtr
static PInvoke.User32.SetWindowLongPtr(System.IntPtr hWnd, PInvoke.User32.WindowLongIndexFlags nIndex, void* dwNewLong) -> void*
static PInvoke.User32.SystemParametersInfoForDpi(PInvoke.User32.SystemParametersInfoAction uiAction, int uiParam, System.IntPtr pvParam, PInvoke.User32.SystemParametersInfoFlags fWinIni, int dpi) -> bool
Expand All @@ -130,6 +186,18 @@ static extern PInvoke.User32.GetDialogDpiChangeBehavior(System.IntPtr hDlg) -> P
static extern PInvoke.User32.GetDpiForSystem() -> int
static extern PInvoke.User32.GetDpiForWindow(System.IntPtr hwnd) -> int
static extern PInvoke.User32.GetDpiFromDpiAwarenessContext(System.IntPtr dpiAwarenessContext) -> int
static extern PInvoke.User32.GetMenu(System.IntPtr hWnd) -> System.IntPtr
static extern PInvoke.User32.GetMenuBarInfo(System.IntPtr hwnd, PInvoke.User32.MenuObject idObject, int idItem, PInvoke.User32.MENUBARINFO* pmbi) -> bool
static extern PInvoke.User32.GetMenuCheckMarkDimensions() -> int
static extern PInvoke.User32.GetMenuContextHelpId(System.IntPtr hMenu) -> uint
static extern PInvoke.User32.GetMenuDefaultItem(System.IntPtr hMenu, uint fByPos, PInvoke.User32.GetMenuDefaultItemFlags gmdiFlags) -> uint
static extern PInvoke.User32.GetMenuInfo(System.IntPtr hMenu, PInvoke.User32.MENUINFO* lpMenuInfo) -> bool
static extern PInvoke.User32.GetMenuItemCount(System.IntPtr hMenu) -> int
static extern PInvoke.User32.GetMenuItemId(System.IntPtr hMenu, int nPos) -> uint
static extern PInvoke.User32.GetMenuItemRect(System.IntPtr hWnd, System.IntPtr hMenu, uint uItem, PInvoke.RECT* lprcItem) -> bool
static extern PInvoke.User32.GetMenuState(System.IntPtr hMenu, uint uId, PInvoke.User32.GetMenuStateFlags uFlags) -> uint
static extern PInvoke.User32.GetMenuString(System.IntPtr hMenu, uint uIDItem, char* lpString, int cchMax, PInvoke.User32.GetMenuStateFlags flags) -> int
static extern PInvoke.User32.GetSubMenu(System.IntPtr hMenu, int nPos) -> System.IntPtr
static extern PInvoke.User32.GetSystemDpiForProcess(PInvoke.Kernel32.SafeObjectHandle hProcess) -> int
static extern PInvoke.User32.GetSystemMetricsForDpi(int nIndex, int dpi) -> int
static extern PInvoke.User32.GetThreadDpiAwarenessContext() -> System.IntPtr
Expand All @@ -146,6 +214,7 @@ static extern PInvoke.User32.SetCursor(PInvoke.User32.SafeCursorHandle hCursor)
static extern PInvoke.User32.SetDialogControlDpiChangeBehavior(System.IntPtr hwnd, PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS mask, PInvoke.User32.DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS values) -> bool
static extern PInvoke.User32.SetDialogDpiChangeBehavior(System.IntPtr hDlg, PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS mask, PInvoke.User32.DIALOG_DPI_CHANGE_BEHAVIORS values) -> bool
static extern PInvoke.User32.SetLastErrorEx(uint dwErrCode, uint dwType) -> void
static extern PInvoke.User32.SetMenuContextHelpId(System.IntPtr hMenu, uint helpId) -> uint
static extern PInvoke.User32.SetProcessDpiAwarenessContext(System.IntPtr dpiAWarenessContext) -> bool
static extern PInvoke.User32.SetThreadDpiAwarenessContext(System.IntPtr dpiContext) -> System.IntPtr
static extern PInvoke.User32.SetThreadDpiHostingBehavior(PInvoke.User32.DPI_HOSTING_BEHAVIOR dpiHostingBehavior) -> PInvoke.User32.DPI_HOSTING_BEHAVIOR
Expand All @@ -157,4 +226,4 @@ static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE -> System
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 -> System.IntPtr
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE -> System.IntPtr
static readonly PInvoke.User32.DPI_AWARENESS_CONTEXT_UNAWARE -> System.IntPtr
static readonly PInvoke.User32.SafeCursorHandle.Null -> PInvoke.User32.SafeCursorHandle
static readonly PInvoke.User32.SafeCursorHandle.Null -> PInvoke.User32.SafeCursorHandle
30 changes: 30 additions & 0 deletions src/User32/User32+GetMenuDefaultItemFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;

/// <content>
/// Contains the <see cref="GetMenuDefaultItemFlags"/> nested type.
/// </content>
public partial class User32
{
/// <summary>
/// Flags to be passed into the <see cref="GetMenuDefaultItem(IntPtr, uint, GetMenuDefaultItemFlags)"/> method.
/// </summary>
[Flags]
public enum GetMenuDefaultItemFlags
{
/// <summary>
/// The function is to return a default item, even if it is disabled. By default, the function skips disabled or grayed items.
/// </summary>
GMDI_USEDISABLED = 0x0001,

/// <summary>
/// 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.
/// </summary>
GMDI_GOINTOPOPUPS = 0x0002,
}
}
}
26 changes: 26 additions & 0 deletions src/User32/User32+GetMenuStateFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
/// <content>
/// Contains the <see cref="GetMenuStateFlags"/> nested type.
/// </content>
public partial class User32
{
/// <summary>Flags passed to the <see cref="GetMenuStateFlags"/> method.</summary>
public enum GetMenuStateFlags
{
/// <summary>
/// Indicates that the uId parameter gives the identifier of the menu item.
/// The <see cref="MF_BYCOMMAND"/> flag is the default if neither the <see cref="MF_BYCOMMAND"/> nor <see cref="MF_BYPOSITION"/> flag is specified.
/// </summary>
MF_BYCOMMAND = MenuItemFlags.MF_BYCOMMAND,

/// <summary>
/// Indicates that the uId parameter gives the zero-based relative position of the menu item.
/// </summary>
MF_BYPOSITION = MenuItemFlags.MF_BYPOSITION,
}
}
}
103 changes: 103 additions & 0 deletions src/User32/User32+MENUBARINFO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;
using System.Runtime.InteropServices;

#pragma warning disable SA1300 // Naming matches .h file
#pragma warning disable SA1303 // Const field names must begin with upper-case letter
#pragma warning disable SA1623 // Docs match Microsoft published text.

/// <content>
/// Contains the <see cref="MENUBARINFO"/> nested type.
/// </content>
public partial class User32
{
/// <summary>
/// Contains menu bar information.
/// </summary>
public struct MENUBARINFO
{
/// <summary>
/// The size of the structure, in bytes. The caller must set this to sizeof(MENUBARINFO).
/// </summary>
public int cbSize;

/// <summary>
/// The coordinates of the menu bar, popup menu, or menu item.
/// </summary>
public RECT rcBar;

/// <summary>
/// A handle to the menu bar or popup menu.
/// </summary>
public IntPtr hMenu;

/// <summary>
/// A handle to the submenu.
/// </summary>
public IntPtr hwndMenu;

private const int fFocusedMask = 1 << 0;

private const int fBarFocusedMask = 1 << 1;

/// <summary>
/// The integer sized location where <see cref="fBarFocused"/> and <see cref="fFocused"/> are stored as bit flags.
/// </summary>
private int flags;

/// <summary>
/// If the menu bar or popup menu has the focus, this member is TRUE. Otherwise, the member is FALSE.
/// </summary>
public bool fBarFocused
{
get => (this.flags & fBarFocusedMask) == fBarFocusedMask;
set
{
if (value)
{
this.flags |= fBarFocusedMask;
}
else
{
this.flags &= ~fBarFocusedMask;
}
}
}

/// <summary>
/// If the menu item has the focus, this member is TRUE. Otherwise, the member is FALSE.
/// </summary>
public bool fFocused
{
get => (this.flags & fFocusedMask) == fFocusedMask;
set
{
if (value)
{
this.flags |= fFocusedMask;
}
else
{
this.flags &= ~fFocusedMask;
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="MENUBARINFO"/> struct
/// with the <see cref="cbSize"/> preset as required.
/// </summary>
/// <returns>The newly initialized instance.</returns>
public static MENUBARINFO Create()
{
var result = default(MENUBARINFO);
result.cbSize = Marshal.SizeOf(result);
return result;
}
}
}
}
Loading