diff --git a/PInvoke/Shared/WinDef/POINTS.cs b/PInvoke/Shared/WinDef/POINTS.cs
index 0d89d11ad..2eef456ef 100644
--- a/PInvoke/Shared/WinDef/POINTS.cs
+++ b/PInvoke/Shared/WinDef/POINTS.cs
@@ -1,28 +1,22 @@
namespace Vanara.PInvoke;
/// The POINTS structure defines the coordinates of a point.
+/// Initializes a new instance of the struct.
+/// The x-coordinate.
+/// The y-coordinate.
[PInvokeData("windef.h")]
[StructLayout(LayoutKind.Sequential), Serializable]
-public struct POINTS : IEquatable
+public struct POINTS(short x, short y) : IEquatable
{
/// The x-coordinate of the point.
- public short x;
+ public short x = x;
/// The y-coordinate of the point.
- public short y;
-
- /// Initializes a new instance of the struct.
- /// The x-coordinate.
- /// The y-coordinate.
- public POINTS(short x, short y)
- {
- this.x = x;
- this.y = y;
- }
+ public short y = y;
/// Gets a value indicating whether this instance is empty.
/// true if this instance is empty; otherwise, false.
- public bool IsEmpty => x == 0 && y == 0;
+ public readonly bool IsEmpty => x == 0 && y == 0;
/// Tests whether two structures are equal.
/// The structure on the left side of the equality operator.
@@ -39,7 +33,7 @@ public POINTS(short x, short y)
/// Indicates whether the current object is equal to another object of the same type.
/// An object to compare with this object.
/// true if the current object is equal to the parameter; otherwise, false.
- public bool Equals(POINTS other) => x == other.x || y == other.y;
+ public readonly bool Equals(POINTS other) => x == other.x || y == other.y;
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
@@ -57,7 +51,7 @@ public POINTS(short x, short y)
/// Converts this structure to a structure.
/// An equivalent structure.
- public POINT ToPoint() => this;
+ public readonly POINT ToPoint() => new(x, y);
/// Returns a that represents this instance.
/// A that represents this instance.
@@ -66,7 +60,7 @@ public POINTS(short x, short y)
/// Performs an implicit conversion from to .
/// The .
/// The result of the conversion.
- public static implicit operator POINT(POINTS p) => new(p.x, p.y);
+ public static implicit operator POINT(POINTS p) => p.ToPoint();
/// Performs an implicit conversion from to .
/// The .
@@ -76,10 +70,10 @@ public POINTS(short x, short y)
/// Performs an explicit conversion from to .
/// The pointer.
/// The result of the conversion.
- 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)));
/// Performs an implicit conversion from to .
/// The .
/// The result of the conversion.
- 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));
}
\ No newline at end of file
diff --git a/PInvoke/User32/User32_WindowMessage.cs b/PInvoke/User32/User32_WindowMessage.cs
index 391883a32..5574bf0fb 100644
--- a/PInvoke/User32/User32_WindowMessage.cs
+++ b/PInvoke/User32/User32_WindowMessage.cs
@@ -12607,6 +12607,23 @@ public enum WM_ICON_WPARAM
ICON_SMALL2 = 2,
}
+ /// The high-order word of the return value from WM_MENUCHAR.
+ [PInvokeData("winuser.h")]
+ public enum WM_MENUCHAR_RETURN : ushort
+ {
+ /// Do not activate the window.
+ MNC_IGNORE = 0,
+
+ /// Activate the window and do not send the message.
+ MNC_CLOSE = 1,
+
+ /// Activate the window and send the message.
+ MNC_EXECUTE = 2,
+
+ /// Activate the window and send the message to the window procedure.
+ MNC_SELECT = 3,
+ }
+
/// Return value for WM_MOUSEACTIVATE.
[PInvokeData("winuser.h")]
public enum WM_MOUSEACTIVATE_RETURN : int
@@ -12733,6 +12750,65 @@ public enum WTS
WTS_SESSION_TERMINATE = 0xB,
}
+ /// Return codes for .
+ [PInvokeData("winuser.h")]
+ [Flags]
+ public enum WVR : int
+ {
+ ///
+ /// 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 WVR_ALIGNLEFT values.
+ ///
+ WVR_ALIGNBOTTOM = 0x0040,
+
+ ///
+ /// 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 WVR_ALIGNLEFT and
+ /// WVR_ALIGNBOTTOM values.
+ ///
+ WVR_ALIGNLEFT = 0x0020,
+
+ ///
+ /// 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 WVR_ALIGNRIGHT and WVR_ALIGNBOTTOM values.
+ ///
+ WVR_ALIGNRIGHT = 0x0080,
+
+ ///
+ /// 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 WVR_ALIGNLEFT values.
+ ///
+ WVR_ALIGNTOP = 0x0010,
+
+ ///
+ /// Used in combination with any other values, except WVR_VALIDRECTS, causes the window to be completely redrawn if the
+ /// client rectangle changes size horizontally. This value is similar to CS_HREDRAW class style
+ ///
+ WVR_HREDRAW = 0x0100,
+
+ ///
+ /// This value causes the entire window to be redrawn. It is a combination of WVR_HREDRAW and WVR_VREDRAW values.
+ ///
+ WVR_REDRAW = 0x0300,
+
+ ///
+ /// This value indicates that, upon return from WM_NCCALCSIZE, the rectangles specified by the rgrc[1] and
+ /// rgrc[2] members of the NCCALCSIZE_PARAMS 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.
+ ///
+ WVR_VALIDRECTS = 0x400,
+
+ ///
+ /// Used in combination with any other values, except WVR_VALIDRECTS, causes the window to be completely redrawn if the
+ /// client rectangle changes size vertically. This value is similar to CS_VREDRAW class style
+ ///
+ WVR_VREDRAW = 0x0200,
+ }
+
/// Retrieves the application command from the specified LPARAM value.
/// The value to be converted.
/// None
@@ -12988,7 +13064,7 @@ public readonly struct MOUSEWHEEL(short distance, MouseButtonState state)
/// Initializes a new instance of the struct.
/// The lParam value from *UISTATE*.
- 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()))) { }
/// Performs an implicit conversion from to .
/// The wParam.
@@ -13068,7 +13144,7 @@ public readonly struct UISTATE
/// Initializes a new instance of the struct.
/// The lParam value from *UISTATE*.
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())); }
/// Performs an implicit conversion from to .
/// The wParam.
@@ -13092,7 +13168,7 @@ public readonly struct WM_HOTKEY_LPARAM
/// Initializes a new instance of the struct.
/// The lParam value from *UISTATE*.
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())); }
/// Performs an implicit conversion from to .
/// The wParam.
@@ -13133,7 +13209,7 @@ public readonly struct WM_KEY_LPARAM
/// Initializes a new instance of the struct.
/// The lParam value from WM_KEYxx.
- public WM_KEY_LPARAM(IntPtr lParam) => lp = unchecked((uint)lParam.ToInt32());
+ public WM_KEY_LPARAM(IntPtr lParam) => lp = unchecked((uint)(long)lParam);
/// Performs an implicit conversion from to .
/// The lParam.
@@ -13146,6 +13222,26 @@ public readonly struct WM_KEY_LPARAM
public static implicit operator IntPtr(WM_KEY_LPARAM lp) => (IntPtr)unchecked((int)(lp.lp));
}
+ /// Result value for .
+ [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);
+
+ /// Performs an implicit conversion from to .
+ /// The lParam.
+ /// The result of the conversion.
+ public static implicit operator WM_MENUCHAR_LRESULT(IntPtr p) => new() { lResult = p };
+
+ ///
+ /// Performs an implicit conversion from to .
+ ///
+ /// The LRESULT struct.
+ /// The result of the conversion.
+ public static implicit operator IntPtr(WM_MENUCHAR_LRESULT lr) => lr.lResult;
+ }
+
/// The state specified in the wParam value of WM_*MOUSEWHEEL* commands.
[PInvokeData("winuser.h")]
[StructLayout(LayoutKind.Sequential)]
@@ -13162,7 +13258,7 @@ public readonly struct WM_SCROLL_LPARAM
/// Initializes a new instance of the struct.
/// The lParam value from *UISTATE*.
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())); }
/// Performs an implicit conversion from to .
/// The wParam.
@@ -13178,13 +13274,13 @@ public struct WM_SETCURSOR_LPARAM
private IntPtr lp;
/// Specifies the hit-test result for the cursor position.
- public HitTestValues HitTestResult => (HitTestValues)Macros.LOWORD(lp);
+ public readonly HitTestValues HitTestResult => (HitTestValues)Macros.LOWORD(lp);
///
/// Specifies the mouse window message which triggered this event, such as WM_MOUSEMOVE. When the window enters menu mode, this value
/// is zero.
///
- public WindowMessage MouseWindowMessage => (WindowMessage)Macros.HIWORD(lp);
+ public readonly WindowMessage MouseWindowMessage => (WindowMessage)Macros.HIWORD(lp);
/// Performs an implicit conversion from to .
/// The lparam value.
diff --git a/PInvoke/User32/VisibleWindow.cs b/PInvoke/User32/VisibleWindow.cs
index 9deb0a20e..61201ca93 100644
--- a/PInvoke/User32/VisibleWindow.cs
+++ b/PInvoke/User32/VisibleWindow.cs
@@ -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();
}
diff --git a/PInvoke/User32/WinUser.Window.cs b/PInvoke/User32/WinUser.Window.cs
index ccc09fb5e..69f1846d0 100644
--- a/PInvoke/User32/WinUser.Window.cs
+++ b/PInvoke/User32/WinUser.Window.cs
@@ -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);
///
/// Shows or hides all pop-up windows owned by the specified window.
diff --git a/PInvoke/User32/WindowsX.cs b/PInvoke/User32/WindowsX.cs
index bd47301fa..e8870938d 100644
--- a/PInvoke/User32/WindowsX.cs
+++ b/PInvoke/User32/WindowsX.cs
@@ -79,7 +79,7 @@ public static void FORWARD_WM_COPY(HWND hwnd, Func fn)
=> (BOOL)fn(hwnd, (int)WindowMessage.WM_COPYDATA, (WPARAM)hwndFrom, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(pcds));
- public static unsafe bool FORWARD_WM_CREATE(HWND hwnd, in CREATESTRUCT lpCreateStruct, Func fn)
+ public static bool FORWARD_WM_CREATE(HWND hwnd, in CREATESTRUCT lpCreateStruct, Func fn)
=> (BOOL)fn(hwnd, (int)WindowMessage.WM_CREATE, IntPtr.Zero, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpCreateStruct));
public static HBRUSH FORWARD_WM_CTLCOLORBTN(HWND hwnd, HDC hdc, HWND hwndChild, Func fn)
@@ -154,8 +154,8 @@ public static bool FORWARD_WM_ERASEBKGND(HWND hwnd, HDC hdc, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);
- public static uint FORWARD_WM_GETDLGCODE(HWND hwnd, in MSG? lpmsg, Func fn)
- => (uint)fn(hwnd, (int)WindowMessage.WM_GETDLGCODE, lpmsg.HasValue ? lpmsg.Value.wParam : IntPtr.Zero, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpmsg));
+ public static DLGC FORWARD_WM_GETDLGCODE(HWND hwnd, in MSG? lpmsg, Func fn)
+ => (DLGC)fn(hwnd, (int)WindowMessage.WM_GETDLGCODE, lpmsg.HasValue ? lpmsg.Value.wParam : IntPtr.Zero, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpmsg));
public static HFONT FORWARD_WM_GETFONT(HWND hwnd, Func fn)
=> (HFONT)fn(hwnd, (int)WindowMessage.WM_GETFONT, IntPtr.Zero, IntPtr.Zero);
@@ -253,14 +253,14 @@ public static bool FORWARD_WM_MDITILE(HWND hwnd, uint cmd, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_MEASUREITEM, (WPARAM)lpMeasureItem.CtlID, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpMeasureItem));
- public static uint FORWARD_WM_MENUCHAR(HWND hwnd, uint ch, uint flags, HMENU hmenu, Func fn)
- => (uint)fn(hwnd, (int)WindowMessage.WM_MENUCHAR, MAKELPARAM(flags, ch), (LPARAM)hmenu);
+ public static WM_MENUCHAR_RETURN FORWARD_WM_MENUCHAR(HWND hwnd, char ch, MenuFlags flags, HMENU hmenu, Func fn)
+ => (WM_MENUCHAR_RETURN)fn(hwnd, (int)WindowMessage.WM_MENUCHAR, MAKELPARAM(flags, ch), (LPARAM)hmenu);
- public static void FORWARD_WM_MENUSELECT(HWND hwnd, HMENU hmenu, int item, HMENU hmenuPopup, uint flags, Func fn)
+ public static void FORWARD_WM_MENUSELECT(HWND hwnd, HMENU hmenu, int item, HMENU hmenuPopup, MenuFlags flags, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_MENUSELECT, MAKELPARAM(item, flags), (LPARAM)((hmenu != HMENU.NULL) ? hmenu : hmenuPopup));
- public static int FORWARD_WM_MOUSEACTIVATE(HWND hwnd, HWND hwndTopLevel, uint codeHitTest, uint msg, Func fn)
- => (int)fn(hwnd, (int)WindowMessage.WM_MOUSEACTIVATE, (WPARAM)hwndTopLevel, MAKELPARAM(codeHitTest, msg));
+ public static MouseActivateCode FORWARD_WM_MOUSEACTIVATE(HWND hwnd, HWND hwndTopLevel, HitTestValues codeHitTest, uint msg, Func fn)
+ => (MouseActivateCode)fn(hwnd, (int)WindowMessage.WM_MOUSEACTIVATE, (WPARAM)hwndTopLevel, MAKELPARAM(codeHitTest, msg));
public static void FORWARD_WM_MOUSEMOVE(HWND hwnd, MouseButtonState state, POINTS pt, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_MOUSEMOVE, (WPARAM)state, pt);
@@ -274,41 +274,41 @@ public static void FORWARD_WM_MOVE(HWND hwnd, POINTS pt, Func fn)
=> (BOOL)fn(hwnd, (int)WindowMessage.WM_NCACTIVATE, (WPARAM)(BOOL)fActive, IntPtr.Zero);
- public static uint FORWARD_WM_NCCALCSIZE(HWND hwnd, bool fCalcValidRects, in NCCALCSIZE_PARAMS lpcsp, Func fn)
- => (uint)fn(hwnd, (int)WindowMessage.WM_NCCALCSIZE, (WPARAM)(BOOL)fCalcValidRects, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpcsp));
+ public static WVR FORWARD_WM_NCCALCSIZE(HWND hwnd, bool fCalcValidRects, in NCCALCSIZE_PARAMS lpcsp, Func fn)
+ => (WVR)fn(hwnd, (int)WindowMessage.WM_NCCALCSIZE, (WPARAM)(BOOL)fCalcValidRects, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpcsp));
- public static unsafe bool FORWARD_WM_NCCREATE(HWND hwnd, in CREATESTRUCT lpCreateStruct, Func fn)
+ public static bool FORWARD_WM_NCCREATE(HWND hwnd, in CREATESTRUCT lpCreateStruct, Func fn)
=> (BOOL)fn(hwnd, (int)WindowMessage.WM_NCCREATE, IntPtr.Zero, (LPARAM)SafeCoTaskMemHandle.CreateFromStructure(lpCreateStruct));
public static void FORWARD_WM_NCDESTROY(HWND hwnd, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_NCDESTROY, IntPtr.Zero, IntPtr.Zero);
- public static uint FORWARD_WM_NCHITTEST(HWND hwnd, int x, int y, Func fn)
- => (uint)fn(hwnd, (int)WindowMessage.WM_NCHITTEST, IntPtr.Zero, MAKELPARAM(x, y));
+ public static HitTestValues FORWARD_WM_NCHITTEST(HWND hwnd, short x, short y, Func fn)
+ => (HitTestValues)fn(hwnd, (int)WindowMessage.WM_NCHITTEST, IntPtr.Zero, new POINTS(x, y));
- public static void FORWARD_WM_NCLBUTTONDOWN(HWND hwnd, bool fDoubleClick, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCLBUTTONDBLCLK : (uint)WindowMessage.WM_NCLBUTTONDOWN, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCLBUTTONDOWN(HWND hwnd, bool fDoubleClick, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCLBUTTONDBLCLK : (uint)WindowMessage.WM_NCLBUTTONDOWN, (WPARAM)codeHitTest, new POINTS(x, y));
- public static void FORWARD_WM_NCLBUTTONUP(HWND hwnd, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, (int)WindowMessage.WM_NCLBUTTONUP, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCLBUTTONUP(HWND hwnd, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, (int)WindowMessage.WM_NCLBUTTONUP, (WPARAM)codeHitTest, new POINTS(x, y));
- public static void FORWARD_WM_NCMBUTTONDOWN(HWND hwnd, bool fDoubleClick, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCMBUTTONDBLCLK : (uint)WindowMessage.WM_NCMBUTTONDOWN, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCMBUTTONDOWN(HWND hwnd, bool fDoubleClick, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCMBUTTONDBLCLK : (uint)WindowMessage.WM_NCMBUTTONDOWN, (WPARAM)codeHitTest, new POINTS(x, y));
- public static void FORWARD_WM_NCMBUTTONUP(HWND hwnd, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, (int)WindowMessage.WM_NCMBUTTONUP, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCMBUTTONUP(HWND hwnd, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, (int)WindowMessage.WM_NCMBUTTONUP, (WPARAM)codeHitTest, new POINTS(x, y));
- public static void FORWARD_WM_NCMOUSEMOVE(HWND hwnd, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, (int)WindowMessage.WM_NCMOUSEMOVE, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCMOUSEMOVE(HWND hwnd, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, (int)WindowMessage.WM_NCMOUSEMOVE, (WPARAM)codeHitTest, new POINTS(x, y));
public static void FORWARD_WM_NCPAINT(HWND hwnd, HRGN hrgn, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_NCPAINT, (WPARAM)hrgn, IntPtr.Zero);
- public static void FORWARD_WM_NCRBUTTONDOWN(HWND hwnd, bool fDoubleClick, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCRBUTTONDBLCLK : (uint)WindowMessage.WM_NCRBUTTONDOWN, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCRBUTTONDOWN(HWND hwnd, bool fDoubleClick, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, fDoubleClick ? (uint)WindowMessage.WM_NCRBUTTONDBLCLK : (uint)WindowMessage.WM_NCRBUTTONDOWN, (WPARAM)codeHitTest, new POINTS(x, y));
- public static void FORWARD_WM_NCRBUTTONUP(HWND hwnd, int x, int y, uint codeHitTest, Func fn)
- => fn(hwnd, (int)WindowMessage.WM_NCRBUTTONUP, (WPARAM)codeHitTest, MAKELPARAM(x, y));
+ public static void FORWARD_WM_NCRBUTTONUP(HWND hwnd, short x, short y, HitTestValues codeHitTest, Func fn)
+ => fn(hwnd, (int)WindowMessage.WM_NCRBUTTONUP, (WPARAM)codeHitTest, new POINTS(x, y));
public static HWND FORWARD_WM_NEXTDLGCTL(HWND hwnd, HWND hwndSetFocus, bool fNext, Func fn)
=> (HWND)fn(hwnd, (int)WindowMessage.WM_NEXTDLGCTL, (WPARAM)hwndSetFocus, (LPARAM)(BOOL)fNext);
@@ -364,7 +364,7 @@ public static void FORWARD_WM_RENDERALLFORMATS(HWND hwnd, Func fn)
=> (HANDLE)fn(hwnd, (int)WindowMessage.WM_RENDERFORMAT, (WPARAM)fmt, IntPtr.Zero);
- public static bool FORWARD_WM_SETCURSOR(HWND hwnd, HWND hwndCursor, uint codeHitTest, uint msg, Func fn)
+ public static bool FORWARD_WM_SETCURSOR(HWND hwnd, HWND hwndCursor, HitTestValues codeHitTest, uint msg, Func fn)
=> (BOOL)fn(hwnd, (int)WindowMessage.WM_SETCURSOR, (WPARAM)hwndCursor, MAKELPARAM(codeHitTest, msg));
public static void FORWARD_WM_SETFOCUS(HWND hwnd, HWND hwndOldFocus, Func fn)
@@ -400,7 +400,7 @@ public static void FORWARD_WM_SYSCHAR(HWND hwnd, char ch, WM_KEY_LPARAM klp, Fun
public static void FORWARD_WM_SYSCOLORCHANGE(HWND hwnd, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_SYSCOLORCHANGE, IntPtr.Zero, IntPtr.Zero);
- public static void FORWARD_WM_SYSCOMMAND(HWND hwnd, uint cmd, int x, int y, Func fn)
+ public static void FORWARD_WM_SYSCOMMAND(HWND hwnd, uint cmd, short x, short y, Func fn)
=> fn(hwnd, (int)WindowMessage.WM_SYSCOMMAND, (WPARAM)cmd, MAKELPARAM(x, y));
public static void FORWARD_WM_SYSDEADCHAR(HWND hwnd, char ch, ushort cRepeat, Func fn)
@@ -515,7 +515,7 @@ public static void FORWARD_WM_WININICHANGE(HWND hwnd, string lpszSectionName, Fu
public static (WPARAM wp, LPARAM lp) GET_WM_MDISETMENU_MPS(HMENU hmenuF, HMENU hmenuW) => ((WPARAM)hmenuF, (LPARAM)hmenuW);
- public static ushort GET_WM_MENUCHAR_CHAR(WPARAM wp, LPARAM lp) => LOWORD(wp);
+ public static char GET_WM_MENUCHAR_CHAR(WPARAM wp, LPARAM lp) => WPARAM_TO_CHARCODE(wp);
public static bool GET_WM_MENUCHAR_FMENU(WPARAM wp, LPARAM lp) => (BOOL)(uint)HIWORD(wp);
@@ -543,7 +543,7 @@ public static void FORWARD_WM_WININICHANGE(HWND hwnd, string lpszSectionName, Fu
public static int GET_WM_PARENTNOTIFY_Y(WPARAM wp, LPARAM lp) => (short)HIWORD(lp);
- public static (WPARAM wp, LPARAM lp) GET_WM_PARENTNOTIFY2_MPS(ushort msg, int x, int y) => (MAKELPARAM(0, msg), MAKELPARAM(x, y));
+ public static (WPARAM wp, LPARAM lp) GET_WM_PARENTNOTIFY2_MPS(ushort msg, short x, short y) => (MAKELPARAM(0, msg), MAKELPARAM(x, y));
public static int GET_WM_VKEYTOITEM_CODE(WPARAM wp, LPARAM lp) => (short)LOWORD(wp);
@@ -563,10 +563,6 @@ public static void FORWARD_WM_WININICHANGE(HWND hwnd, string lpszSectionName, Fu
public static WPARAM GET_WPARAM(WPARAM wp, LPARAM lp) => wp;
- public static int GET_X_LPARAM(LPARAM lp) => (short)LOWORD(lp);
-
- public static int GET_Y_LPARAM(LPARAM lp) => (short)HIWORD(lp);
-
public static LRESULT HANDLE_WM_ACTIVATE(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
fn(hwnd, LOWORD(wParam), (HWND)lParam, (BOOL)(uint)HIWORD(wParam));
@@ -599,7 +595,7 @@ public static LRESULT HANDLE_WM_CHANGECBCHAIN(HWND hwnd, WPARAM wParam, LPARAM l
public static LRESULT HANDLE_WM_CHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (char)(int)wParam, new WM_KEY_LPARAM(lParam));
+ fn(hwnd, WPARAM_TO_CHARCODE(wParam), new WM_KEY_LPARAM(lParam));
return IntPtr.Zero;
}
@@ -695,7 +691,7 @@ public static LRESULT HANDLE_WM_CUT(HWND hwnd, WPARAM wParam, LPARAM lParam, Act
public static LRESULT HANDLE_WM_DEADCHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (char)(int)wParam, new WM_KEY_LPARAM(lParam));
+ fn(hwnd, WPARAM_TO_CHARCODE(wParam), new WM_KEY_LPARAM(lParam));
return IntPtr.Zero;
}
@@ -849,39 +845,39 @@ public static LRESULT HANDLE_WM_KILLFOCUS(HWND hwnd, WPARAM wParam, LPARAM lPara
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_LBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_LBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_LBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_LBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_LBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_LBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_MBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_MBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_MBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_MBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_MBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_MBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
@@ -939,17 +935,17 @@ public static LRESULT HANDLE_WM_MEASUREITEM(HWND hwnd, WPARAM wParam, LPARAM lPa
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_MENUCHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
- => (LRESULT)fn(hwnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
+ public static LRESULT HANDLE_WM_MENUCHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
+ => (LRESULT)fn(hwnd, WPARAM_TO_CHARCODE(wParam), (MenuFlags)HIWORD(wParam), (HMENU)lParam);
- public static LRESULT HANDLE_WM_MENUSELECT(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_MENUSELECT(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (HMENU)lParam, ((HIWORD(wParam) & (int)MenuFlags.MF_POPUP) != 0) ? 0 : LOWORD(wParam), ((HIWORD(wParam) & (int)MenuFlags.MF_POPUP) != 0) ? GetSubMenu((HMENU)lParam, LOWORD(wParam)) : HMENU.NULL, ((short)HIWORD(wParam) == -1) ? 0xFFFFFFFF : HIWORD(wParam));
+ fn(hwnd, (HMENU)lParam, ((HIWORD(wParam) & (int)MenuFlags.MF_POPUP) != 0) ? 0 : LOWORD(wParam), ((HIWORD(wParam) & (int)MenuFlags.MF_POPUP) != 0) ? GetSubMenu((HMENU)lParam, LOWORD(wParam)) : HMENU.NULL, (MenuFlags)HIWORD(wParam));
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_MOUSEACTIVATE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
- => (LRESULT)(uint)fn(hwnd, (HWND)wParam, LOWORD(lParam), HIWORD(lParam));
+ public static LRESULT HANDLE_WM_MOUSEACTIVATE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
+ => (LRESULT)fn(hwnd, (HWND)wParam, (HitTestValues)LOWORD(lParam), HIWORD(lParam));
public static LRESULT HANDLE_WM_MOUSEMOVE(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
@@ -972,7 +968,7 @@ public static LRESULT HANDLE_WM_MOVE(HWND hwnd, WPARAM wParam, LPARAM lParam, Ac
public static LRESULT HANDLE_WM_NCACTIVATE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
=> (LRESULT)(BOOL)fn(hwnd, (BOOL)wParam, HWND.NULL, false);
- public static LRESULT HANDLE_WM_NCCALCSIZE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
+ public static LRESULT HANDLE_WM_NCCALCSIZE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
=> (LRESULT)fn(hwnd, (BOOL)wParam, lParam.ToStructure());
public static unsafe LRESULT HANDLE_WM_NCCREATE(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
@@ -984,48 +980,48 @@ public static LRESULT HANDLE_WM_NCDESTROY(HWND hwnd, WPARAM wParam, LPARAM lPara
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCHITTEST(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
- => (LRESULT)fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam));
+ public static LRESULT HANDLE_WM_NCHITTEST(HWND hwnd, WPARAM wParam, LPARAM lParam, Func fn)
+ => (LRESULT)fn(hwnd, (POINTS)lParam);
- public static LRESULT HANDLE_WM_NCLBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCLBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCLBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCLBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCLBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCLBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCMBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCMBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCMBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCMBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCMBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCMBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCMOUSEMOVE(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCMOUSEMOVE(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
@@ -1035,21 +1031,21 @@ public static LRESULT HANDLE_WM_NCPAINT(HWND hwnd, WPARAM wParam, LPARAM lParam,
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCRBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCRBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCRBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCRBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_NCRBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_NCRBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (POINTS)lParam, (HitTestValues)wParam);
return IntPtr.Zero;
}
@@ -1123,21 +1119,21 @@ public static LRESULT HANDLE_WM_QUIT(HWND hwnd, WPARAM wParam, LPARAM lParam, Ac
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_RBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_RBUTTONDBLCLK(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, true, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, true, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_RBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_RBUTTONDOWN(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, false, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, false, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
- public static LRESULT HANDLE_WM_RBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
+ public static LRESULT HANDLE_WM_RBUTTONUP(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (uint)wParam);
+ fn(hwnd, (MouseButtonState)wParam, (POINTS)lParam);
return IntPtr.Zero;
}
@@ -1204,7 +1200,7 @@ public static LRESULT HANDLE_WM_SPOOLERSTATUS(HWND hwnd, WPARAM wParam, LPARAM l
public static LRESULT HANDLE_WM_SYSCHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (char)(int)wParam, new WM_KEY_LPARAM(lParam));
+ fn(hwnd, WPARAM_TO_CHARCODE(wParam), new WM_KEY_LPARAM(lParam));
return IntPtr.Zero;
}
@@ -1222,7 +1218,7 @@ public static LRESULT HANDLE_WM_SYSCOMMAND(HWND hwnd, WPARAM wParam, LPARAM lPar
public static LRESULT HANDLE_WM_SYSDEADCHAR(HWND hwnd, WPARAM wParam, LPARAM lParam, Action fn)
{
- fn(hwnd, (char)(int)wParam, new WM_KEY_LPARAM(lParam));
+ fn(hwnd, WPARAM_TO_CHARCODE(wParam), new WM_KEY_LPARAM(lParam));
return IntPtr.Zero;
}
diff --git a/UnitTests/PInvoke/User32/User32Tests.cs b/UnitTests/PInvoke/User32/User32Tests.cs
index 4fcab1c9b..934af179b 100644
--- a/UnitTests/PInvoke/User32/User32Tests.cs
+++ b/UnitTests/PInvoke/User32/User32Tests.cs
@@ -105,13 +105,28 @@ public void CreateDialogTest()
int WriteStr(string o) { StringHelper.Write(o + '\0', lpdt.DangerousGetHandle().Offset(lpw), out var nchar, true, CharSet.Unicode, lpdt.Size - lpw); return nchar; }
}
- [Test()]
+ [Test]
+ public void CreateWindowExTest()
+ {
+ WindowClass wc = new("MyWindowClass");
+ SafeCoTaskMemHandle mem = new(128);
+ SafeHWND wnd = new(IntPtr.Zero, false);
+ Assert.That(wnd = CreateWindowEx(0, wc.ClassName, "1234567890", WindowStyles.WS_OVERLAPPEDWINDOW, lpParam: mem), ResultIs.ValidHandle);
+ Assert.That(GetWindowTextLength(wnd), Is.EqualTo(10));
+ Assert.That(SetWindowText(wnd, "Hello, World!\0"));
+ Assert.That(GetWindowTextLength(wnd), Is.EqualTo(13));
+ StringBuilder sb = new(256);
+ Assert.That(GetWindowText(wnd, sb, sb.Capacity), Is.EqualTo(13));
+ Assert.That(sb.ToString(), Is.EqualTo("Hello, World!"));
+ }
+
+ [Test]
public void DrawTextTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ExitWindowsExTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void GetClientRectTest() => throw new NotImplementedException();
[Test]
@@ -147,43 +162,45 @@ public void GetRawInputDeviceInfoTest()
}
}
- [Test()]
- public void GetWindowLong32Test() => throw new NotImplementedException();
-
- [Test()]
- public void GetWindowLongPtrTest() => throw new NotImplementedException();
-
- [Test()]
- public void GetWindowLongTest() => throw new NotImplementedException();
+ [Test]
+ public void GetSetWindowLongTest()
+ {
+ var s = WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPSIBLINGS;
+ WindowClass wc = new("MyWindowClass");
+ SafeHWND wnd = CreateWindowEx(0, wc.ClassName, "1234567890", s);
+ Assert.That(GetWindowLong(wnd, WindowLongFlags.GWL_STYLE), Is.EqualTo(s));
+ SetWindowLong(wnd, WindowLongFlags.GWL_STYLE, (int)(s | WindowStyles.WS_DISABLED));
+ Assert.That(GetWindowLong(wnd, WindowLongFlags.GWL_STYLE), Is.EqualTo(s | WindowStyles.WS_DISABLED));
+ }
- [Test()]
+ [Test]
public void GetWindowRectTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void InvalidateRectTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void LoadImageTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void LoadStringTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void LoadStringTest1() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void LockWorkStationTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void MapWindowPointsTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void MapWindowPointsTest1() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void MapWindowPointsTest2() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void MB_GetStringTest()
{
Assert.That((string?)MB_GetString(1), Is.Not.Null);
@@ -305,19 +322,19 @@ public void MgdDlgTemplateExReadWriteTest()
Assert.That(dlg.controls[1].title.name, Is.EqualTo(dlg2!.controls[1].title.name));
}
- [Test()]
+ [Test]
public void RealGetWindowClassTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void RegisterHotKeyTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void RegisterWindowMessageTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ScreenToClientTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SendMessageTest()
{
// WM_ERASEBKGND
@@ -356,7 +373,7 @@ public void SendMessageTest()
SendMessage(default, ButtonMessage.BCM_SETDROPDOWNSTATE, true);
}
- [Test()]
+ [Test]
public void SendMessageTest1()
{
var length = 256;
@@ -365,45 +382,40 @@ public void SendMessageTest1()
TestContext.WriteLine(sb);
}
- //public static IntPtr SendMessage(HWND hwnd, TMsg msg, THandle wParam) where TMsg : struct, IConvertible where THandle : IHandle
- // => SendMessage(hwnd, Convert.ToUInt32(msg), (IntPtr)wParam, IntPtr.Zero);
- [Test()]
+ [Test]
public void SendMessageTest2() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SendMessageTest3() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SendMessageTest4() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SendMessageTest5() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SendMessageTest6() => throw new NotImplementedException();
- [Test()]
- public void SetWindowLongTest() => throw new NotImplementedException();
-
- [Test()]
+ [Test]
public void SetWindowPosTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SetWindowsHookExTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void SetWindowTextTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ShutdownBlockReasonCreateTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ShutdownBlockReasonDestroyTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ShutdownBlockReasonQueryTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void ShutdownBlockReasonQueryTest1() => throw new NotImplementedException();
[Test]
@@ -545,13 +557,13 @@ public void SystemParametersInfoSetTest()
Assert.That(SystemParametersInfo(SPI.SPI_SETDESKWALLPAPER, (uint)sb.Length, sb.ToString(), SPIF.SPIF_SENDCHANGE));
}
- [Test()]
+ [Test]
public void UnhookWindowsHookExTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void UnregisterHotKeyTest() => throw new NotImplementedException();
- [Test()]
+ [Test]
public void WindowFromPointTest() => throw new NotImplementedException();
[Test]
diff --git a/UnitTests/PInvoke/User32/WrapperTests.cs b/UnitTests/PInvoke/User32/WrapperTests.cs
index 1ee4450c6..511fea96d 100644
--- a/UnitTests/PInvoke/User32/WrapperTests.cs
+++ b/UnitTests/PInvoke/User32/WrapperTests.cs
@@ -17,14 +17,16 @@ public void WindowClassCtorTest()
Assert.That(wc.Unregister());
Assert.DoesNotThrow(() => wc = new("MyCustomName"));
- Assert.That(wc.ClassName, Is.EqualTo("MyCustomName"));
+ Assert.That(GetClassInfoEx(wc.wc.hInstance, wc.ClassName, out var wcex));
+ Assert.That(wcex.lpszClassName, Is.EqualTo("MyCustomName"));
Assert.That(wc.Unregister());
Assert.DoesNotThrow(() => wc = WindowClass.MakeVisibleWindowClass("MyWindowClass", DefWindowProc));
- Assert.That(wc.ClassName, Is.EqualTo("MyWindowClass"));
- Assert.That(wc.wc.hIcon, Is.Not.EqualTo(HICON.NULL));
- Assert.That(wc.wc.hCursor, Is.Not.EqualTo(HCURSOR.NULL));
- Assert.That(wc.wc.hbrBackground, Is.Not.EqualTo(HBRUSH.NULL));
+ Assert.That(GetClassInfoEx(wc.wc.hInstance, wc.ClassName, out wcex));
+ Assert.That(wcex.lpszClassName, Is.EqualTo("MyWindowClass"));
+ Assert.That(wcex.hIcon, Is.Not.EqualTo(HICON.NULL));
+ Assert.That(wcex.hCursor, Is.Not.EqualTo(HCURSOR.NULL));
+ Assert.That(wcex.hbrBackground, Is.Not.EqualTo(HBRUSH.NULL));
}
[Test]
@@ -51,6 +53,9 @@ public void WindowCreateTest()
Assert.That(wnd.ClassName, Is.Not.Null);
Assert.That(created);
Assert.That(wnd.Handle, Is.Not.EqualTo(HWND.NULL));
+ Assert.That(GetWindowTextLength(wnd.Handle), Is.Zero);
+ Assert.That(SetWindowText(wnd.Handle, "Hello, World!\0"));
+ Assert.That(GetWindowTextLength(wnd.Handle), Is.EqualTo(13));
}
[Test]
@@ -73,7 +78,7 @@ public class MyWin : VisibleWindow
{
protected override IntPtr WndProc(HWND hwnd, uint msg, IntPtr wParam, IntPtr lParam)
{
- if (msg == (uint)WindowMessage.WM_CREATE) MessageBox(hwnd, "Got it!");
+ //if (msg == (uint)WindowMessage.WM_CREATE) MessageBox(hwnd, "Got it!");
return base.WndProc(hwnd, msg, wParam, lParam);
}
}