Skip to content

Commit

Permalink
Minor updates and additions to User32
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hall committed Jan 31, 2025
1 parent 3d13aa2 commit 39d5e2b
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 166 deletions.
30 changes: 12 additions & 18 deletions PInvoke/Shared/WinDef/POINTS.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
namespace Vanara.PInvoke;

/// <summary>The POINTS structure defines the coordinates of a point.</summary>
/// <remarks>Initializes a new instance of the <see cref="POINTS"/> struct.</remarks>
/// <param name="x">The x-coordinate.</param>
/// <param name="y">The y-coordinate.</param>
[PInvokeData("windef.h")]
[StructLayout(LayoutKind.Sequential), Serializable]
public struct POINTS : IEquatable<POINTS>
public struct POINTS(short x, short y) : IEquatable<POINTS>
{
/// <summary>The x-coordinate of the point.</summary>
public short x;
public short x = x;

/// <summary>The y-coordinate of the point.</summary>
public short y;

/// <summary>Initializes a new instance of the <see cref="POINTS"/> struct.</summary>
/// <param name="x">The x-coordinate.</param>
/// <param name="y">The y-coordinate.</param>
public POINTS(short x, short y)
{
this.x = x;
this.y = y;
}
public short y = y;

/// <summary>Gets a value indicating whether this instance is empty.</summary>
/// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
public bool IsEmpty => x == 0 && y == 0;
public readonly bool IsEmpty => x == 0 && y == 0;

/// <summary>Tests whether two <see cref="POINTS"/> structures are equal.</summary>
/// <param name="pt1">The <see cref="POINTS"/> structure on the left side of the equality operator.</param>
Expand All @@ -39,7 +33,7 @@ public POINTS(short x, short y)
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.</returns>
public bool Equals(POINTS other) => x == other.x || y == other.y;
public readonly bool Equals(POINTS other) => x == other.x || y == other.y;

/// <summary>Determines whether the specified <see cref="object"/>, is equal to this instance.</summary>
/// <param name="obj">The <see cref="object"/> to compare with this instance.</param>
Expand All @@ -57,7 +51,7 @@ public POINTS(short x, short y)

/// <summary>Converts this structure to a <see cref="POINT"/> structure.</summary>
/// <returns>An equivalent <see cref="POINT"/> structure.</returns>
public POINT ToPoint() => this;
public readonly POINT ToPoint() => new(x, y);

/// <summary>Returns a <see cref="string"/> that represents this instance.</summary>
/// <returns>A <see cref="string"/> that represents this instance.</returns>
Expand All @@ -66,7 +60,7 @@ public POINTS(short x, short y)
/// <summary>Performs an implicit conversion from <see cref="POINTS"/> to <see cref="POINT"/>.</summary>
/// <param name="p">The <see cref="POINTS"/>.</param>
/// <returns>The <see cref="POINT"/> result of the conversion.</returns>
public static implicit operator POINT(POINTS p) => new(p.x, p.y);
public static implicit operator POINT(POINTS p) => p.ToPoint();

/// <summary>Performs an implicit conversion from <see cref="POINT"/> to <see cref="POINTS"/>.</summary>
/// <param name="p">The <see cref="POINT"/>.</param>
Expand All @@ -76,10 +70,10 @@ public POINTS(short x, short y)
/// <summary>Performs an explicit conversion from <see cref="IntPtr"/> to <see cref="POINTS"/>.</summary>
/// <param name="p">The pointer.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator POINTS(IntPtr p) => new(unchecked((short)Macros.LOWORD(p)), unchecked((short)Macros.HIWORD(p)));
public static explicit operator POINTS(IntPtr p) => new(unchecked((short)(long)p), unchecked((short)((long)p >> 16)));

/// <summary>Performs an implicit conversion from <see cref="POINTS"/> to <see cref="IntPtr"/>.</summary>
/// <param name="p">The <see cref="POINTS"/>.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator IntPtr(POINTS p) => Macros.MAKELPARAM(p.x, p.y);
public static implicit operator IntPtr(POINTS p) => Macros.MAKELPARAM(unchecked((ushort)p.x), unchecked((ushort)p.y));
}
110 changes: 103 additions & 7 deletions PInvoke/User32/User32_WindowMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12607,6 +12607,23 @@ public enum WM_ICON_WPARAM
ICON_SMALL2 = 2,
}

/// <summary>The high-order word of the return value from WM_MENUCHAR.</summary>
[PInvokeData("winuser.h")]
public enum WM_MENUCHAR_RETURN : ushort
{
/// <summary>Do not activate the window.</summary>
MNC_IGNORE = 0,

/// <summary>Activate the window and do not send the message.</summary>
MNC_CLOSE = 1,

/// <summary>Activate the window and send the message.</summary>
MNC_EXECUTE = 2,

/// <summary>Activate the window and send the message to the window procedure.</summary>
MNC_SELECT = 3,
}

/// <summary>Return value for WM_MOUSEACTIVATE.</summary>
[PInvokeData("winuser.h")]
public enum WM_MOUSEACTIVATE_RETURN : int
Expand Down Expand Up @@ -12733,6 +12750,65 @@ public enum WTS
WTS_SESSION_TERMINATE = 0xB,
}

/// <summary>Return codes for <see cref="WindowMessage.WM_NCCALCSIZE"/>.</summary>
[PInvokeData("winuser.h")]
[Flags]
public enum WVR : int
{
/// <summary>
/// Specifies that the client area of the window is to be preserved and aligned with the bottom of the new position of the window.
/// For example, to align the client area to the top-left corner, return the WVR_ALIGNTOP and <c>WVR_ALIGNLEFT</c> values.
/// </summary>
WVR_ALIGNBOTTOM = 0x0040,

/// <summary>
/// Specifies that the client area of the window is to be preserved and aligned with the left side of the new position of the
/// window. For example, to align the client area to the lower-left corner, return the <c>WVR_ALIGNLEFT</c> and
/// <c>WVR_ALIGNBOTTOM</c> values.
/// </summary>
WVR_ALIGNLEFT = 0x0020,

/// <summary>
/// Specifies that the client area of the window is to be preserved and aligned with the right side of the new position of the
/// window. For example, to align the client area to the lower-right corner, return the <c>WVR_ALIGNRIGHT</c> and WVR_ALIGNBOTTOM values.
/// </summary>
WVR_ALIGNRIGHT = 0x0080,

/// <summary>
/// Specifies that the client area of the window is to be preserved and aligned with the top of the new position of the window. For
/// example, to align the client area to the upper-left corner, return the WVR_ALIGNTOP and <c>WVR_ALIGNLEFT</c> values.
/// </summary>
WVR_ALIGNTOP = 0x0010,

/// <summary>
/// Used in combination with any other values, except <c>WVR_VALIDRECTS</c>, causes the window to be completely redrawn if the
/// client rectangle changes size horizontally. This value is similar to CS_HREDRAW class style
/// </summary>
WVR_HREDRAW = 0x0100,

/// <summary>
/// This value causes the entire window to be redrawn. It is a combination of <c>WVR_HREDRAW</c> and <c>WVR_VREDRAW</c> values.
/// </summary>
WVR_REDRAW = 0x0300,

/// <summary>
/// This value indicates that, upon return from <c>WM_NCCALCSIZE</c>, the rectangles specified by the <c>rgrc</c>[1] and
/// <c>rgrc</c>[2] members of the <c>NCCALCSIZE_PARAMS</c> structure contain valid destination and source area rectangles,
/// respectively. The system combines these rectangles to calculate the area of the window to be preserved. The system copies any
/// part of the window image that is within the source rectangle and clips the image to the destination rectangle. Both rectangles
/// are in parent-relative or screen-relative coordinates. This flag cannot be combined with any other flags. This return value
/// allows an application to implement more elaborate client-area preservation strategies, such as centering or preserving a subset
/// of the client area.
/// </summary>
WVR_VALIDRECTS = 0x400,

/// <summary>
/// Used in combination with any other values, except <c>WVR_VALIDRECTS</c>, causes the window to be completely redrawn if the
/// client rectangle changes size vertically. This value is similar to CS_VREDRAW class style
/// </summary>
WVR_VREDRAW = 0x0200,
}

/// <summary>Retrieves the application command from the specified <c>LPARAM</c> value.</summary>
/// <param name="lParam">The value to be converted.</param>
/// <returns>None</returns>
Expand Down Expand Up @@ -12988,7 +13064,7 @@ public readonly struct MOUSEWHEEL(short distance, MouseButtonState state)

/// <summary>Initializes a new instance of the <see cref="MOUSEWHEEL"/> struct.</summary>
/// <param name="lParam">The lParam value from *UISTATE*.</param>
public MOUSEWHEEL(IntPtr lParam) : this(unchecked((short)Macros.HIWORD(unchecked((uint)lParam.ToInt32()))), (MouseButtonState)Macros.LOWORD(unchecked((uint)lParam.ToInt32()))) { }
public MOUSEWHEEL(IntPtr lParam) : this(unchecked((short)Macros.HIWORD(unchecked((uint)lParam.ToInt64()))), (MouseButtonState)Macros.LOWORD(unchecked((uint)lParam.ToInt64()))) { }

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="MOUSEWHEEL"/>.</summary>
/// <param name="p">The wParam.</param>
Expand Down Expand Up @@ -13068,7 +13144,7 @@ public readonly struct UISTATE
/// <summary>Initializes a new instance of the <see cref="UISTATE"/> struct.</summary>
/// <param name="lParam">The lParam value from *UISTATE*.</param>
public UISTATE(IntPtr lParam)
{ action = (UIS)Macros.LOWORD(unchecked((uint)lParam.ToInt32())); state = (UISF)Macros.HIWORD(unchecked((uint)lParam.ToInt32())); }
{ action = (UIS)Macros.LOWORD(unchecked((uint)lParam.ToInt64())); state = (UISF)Macros.HIWORD(unchecked((uint)lParam.ToInt64())); }

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="UISTATE"/>.</summary>
/// <param name="p">The wParam.</param>
Expand All @@ -13092,7 +13168,7 @@ public readonly struct WM_HOTKEY_LPARAM
/// <summary>Initializes a new instance of the <see cref="WM_HOTKEY_LPARAM"/> struct.</summary>
/// <param name="lParam">The lParam value from *UISTATE*.</param>
public WM_HOTKEY_LPARAM(IntPtr lParam)
{ _Modifiers = Macros.LOWORD(unchecked((uint)lParam.ToInt32())); _VirtualKeyCode = Macros.HIWORD(unchecked((uint)lParam.ToInt32())); }
{ _Modifiers = Macros.LOWORD(unchecked((uint)lParam.ToInt64())); _VirtualKeyCode = Macros.HIWORD(unchecked((uint)lParam.ToInt64())); }

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="WM_HOTKEY_LPARAM"/>.</summary>
/// <param name="p">The wParam.</param>
Expand Down Expand Up @@ -13133,7 +13209,7 @@ public readonly struct WM_KEY_LPARAM

/// <summary>Initializes a new instance of the <see cref="WM_KEY_LPARAM"/> struct.</summary>
/// <param name="lParam">The lParam value from WM_KEYxx.</param>
public WM_KEY_LPARAM(IntPtr lParam) => lp = unchecked((uint)lParam.ToInt32());
public WM_KEY_LPARAM(IntPtr lParam) => lp = unchecked((uint)(long)lParam);

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="WM_KEY_LPARAM"/>.</summary>
/// <param name="p">The lParam.</param>
Expand All @@ -13146,6 +13222,26 @@ public readonly struct WM_KEY_LPARAM
public static implicit operator IntPtr(WM_KEY_LPARAM lp) => (IntPtr)unchecked((int)(lp.lp));
}

/// <summary>Result value for <see cref="WindowMessage.WM_MENUCHAR"/>.</summary>
[PInvokeData("winuser.h")]
[StructLayout(LayoutKind.Sequential)]
public struct WM_MENUCHAR_LRESULT(WM_MENUCHAR_RETURN code, ushort value)
{
private IntPtr lResult = Macros.MAKELPARAM((ushort)code, value);

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="WM_MENUCHAR_LRESULT"/>.</summary>
/// <param name="p">The lParam.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator WM_MENUCHAR_LRESULT(IntPtr p) => new() { lResult = p };

/// <summary>
/// Performs an implicit conversion from <see cref="Vanara.PInvoke.User32.WM_MENUCHAR_LRESULT"/> to <see cref="System.IntPtr"/>.
/// </summary>
/// <param name="lr">The LRESULT struct.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator IntPtr(WM_MENUCHAR_LRESULT lr) => lr.lResult;
}

/// <summary>The state specified in the wParam value of WM_*MOUSEWHEEL* commands.</summary>
[PInvokeData("winuser.h")]
[StructLayout(LayoutKind.Sequential)]
Expand All @@ -13162,7 +13258,7 @@ public readonly struct WM_SCROLL_LPARAM
/// <summary>Initializes a new instance of the <see cref="WM_SCROLL_LPARAM"/> struct.</summary>
/// <param name="lParam">The lParam value from *UISTATE*.</param>
public WM_SCROLL_LPARAM(IntPtr lParam)
{ _scrollbarEvent = Macros.LOWORD(unchecked((uint)lParam.ToInt32())); scrollPosition = Macros.HIWORD(unchecked((uint)lParam.ToInt32())); }
{ _scrollbarEvent = Macros.LOWORD(unchecked((uint)lParam.ToInt64())); scrollPosition = Macros.HIWORD(unchecked((uint)lParam.ToInt64())); }

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="WM_SCROLL_LPARAM"/>.</summary>
/// <param name="p">The wParam.</param>
Expand All @@ -13178,13 +13274,13 @@ public struct WM_SETCURSOR_LPARAM
private IntPtr lp;

/// <summary>Specifies the hit-test result for the cursor position.</summary>
public HitTestValues HitTestResult => (HitTestValues)Macros.LOWORD(lp);
public readonly HitTestValues HitTestResult => (HitTestValues)Macros.LOWORD(lp);

/// <summary>
/// Specifies the mouse window message which triggered this event, such as WM_MOUSEMOVE. When the window enters menu mode, this value
/// is zero.
/// </summary>
public WindowMessage MouseWindowMessage => (WindowMessage)Macros.HIWORD(lp);
public readonly WindowMessage MouseWindowMessage => (WindowMessage)Macros.HIWORD(lp);

/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="WM_SETCURSOR_LPARAM"/>.</summary>
/// <param name="lparam">The lparam value.</param>
Expand Down
2 changes: 1 addition & 1 deletion PInvoke/User32/VisibleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public string Text
if (len > 0)
{
StringBuilder sb = new(len + 1);
if (GetWindowText(Handle, sb, len) > 0)
if (GetWindowText(Handle, sb, sb.Capacity) > 0)
{
return sb.ToString();
}
Expand Down
2 changes: 1 addition & 1 deletion PInvoke/User32/WinUser.Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7472,7 +7472,7 @@ public static extern bool SetAdditionalForegroundBoostProcesses(HWND topLevelWin
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "setwindowtext")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowText(HWND hWnd, string lpString);
public static extern bool SetWindowText(HWND hWnd, [MarshalAs(UnmanagedType.LPTStr)] string lpString);

/// <summary>
/// <para>Shows or hides all pop-up windows owned by the specified window.</para>
Expand Down
Loading

0 comments on commit 39d5e2b

Please sign in to comment.