Partial work on ComCtl32

nullableenabled
David Hall 2023-05-16 21:08:44 -06:00
parent ec3efefb73
commit 822ee75fa7
16 changed files with 187 additions and 98 deletions

View File

@ -22,7 +22,7 @@ namespace Vanara.Windows.Forms;
[SuppressUnmanagedCodeSecurity]
public class ComCtl32v6Context : IDisposable
{
private SafeHACTCTX hActCtx;
private SafeHACTCTX hActCtx = SafeHACTCTX.Null;
private IntPtr localCookie;
/// <summary>Initializes a new instance of the <see cref="ComCtl32v6Context"/> class.</summary>
@ -42,16 +42,17 @@ public class ComCtl32v6Context : IDisposable
{
try
{
if ((localCookie != IntPtr.Zero) && DeactivateActCtx(0, localCookie))
if (localCookie != IntPtr.Zero && DeactivateActCtx(0, localCookie))
localCookie = IntPtr.Zero;
hActCtx.Dispose();
hActCtx = SafeHACTCTX.Null;
}
catch { }
}
private void Activate()
{
if (hActCtx != null && !ActivateActCtx(hActCtx, out localCookie))
if (!hActCtx.IsInvalid && !ActivateActCtx(hActCtx, out localCookie))
localCookie = IntPtr.Zero;
}

View File

@ -122,7 +122,7 @@ public static partial class ComCtl32
/// <summary>Contains information about a BCN_DROPDOWN notification.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775957")]
[StructLayout(LayoutKind.Sequential)]
public struct NMBCDROPDOWN
public struct NMBCDROPDOWN : INotificationInfo
{
/// <summary>An NMHDR structure containing information about the notification.</summary>
public NMHDR hdr;
@ -134,7 +134,7 @@ public static partial class ComCtl32
/// <summary>Contains information about the movement of the mouse over a button control.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775959")]
[StructLayout(LayoutKind.Sequential)]
public struct NMBCHOTITEM
public struct NMBCHOTITEM : INotificationInfo
{
/// <summary>An NMHDR structure.</summary>
public NMHDR hdr;

View File

@ -154,7 +154,7 @@ public static partial class ComCtl32
/// <summary>Contains information used with the CBEN_DRAGBEGIN notification code.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775748")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMCBEDRAGBEGIN
public struct NMCBEDRAGBEGIN : INotificationInfo
{
/// <summary>The NMHDR structure that contains information about the notification code.</summary>
public NMHDR hdr;
@ -175,7 +175,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775750")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMCBEENDEDIT
public struct NMCBEENDEDIT : INotificationInfo
{
/// <summary>The NMHDR structure that contains information about the notification code.</summary>
public NMHDR hdr;
@ -202,7 +202,7 @@ public static partial class ComCtl32
/// <summary>Contains information specific to ComboBoxEx items for use with notification codes.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775752")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMCOMBOBOXEX
public struct NMCOMBOBOXEX : INotificationInfo
{
/// <summary>The NMHDR structure that contains information about the notification code.</summary>
public NMHDR hdr;

View File

@ -1,37 +1,29 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke;
public static partial class ComCtl32
{
/// <summary>
/// Contains information about a balloon tip associated with a button control.
/// </summary>
/// <summary>Contains information about a balloon tip associated with a button control.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775466")]
[StructLayout(LayoutKind.Sequential)]
public struct EDITBALLOONTIP
{
/// <summary>
/// A DWORD that contains the size, in bytes, of the structure.
/// </summary>
/// <summary>A DWORD that contains the size, in bytes, of the structure.</summary>
public int cbStruct;
/// <summary>
/// A pointer to a Unicode string that contains the title of the balloon tip.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)] public string pszTitle;
/// <summary>
/// A pointer to a Unicode string that contains the balloon tip text.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)] public string pszText;
/// <summary>
/// A value of type INT that specifies the type of icon to associate with the balloon tip.
/// </summary>
/// <summary>A pointer to a Unicode string that contains the title of the balloon tip.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszTitle;
/// <summary>A pointer to a Unicode string that contains the balloon tip text.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pszText;
/// <summary>A value of type INT that specifies the type of icon to associate with the balloon tip.</summary>
public ToolTipIcon ttiIcon;
/// <summary>
/// Initializes a new instance of the <see cref="EDITBALLOONTIP"/> struct.
/// </summary>
/// <summary>Initializes a new instance of the <see cref="EDITBALLOONTIP"/> struct.</summary>
/// <param name="title">The title.</param>
/// <param name="text">The text.</param>
/// <param name="icon">The icon.</param>

View File

@ -14,7 +14,19 @@ public static partial class ComCtl32
private const int HDM_FIRST = 0x1200;
private const int HDN_FIRST = -300;
/// <summary>The type of image list to retrieve.</summary>
[PInvokeData("Commctrl.h")]
public enum HDSIL : ushort
{
/// <summary>Indicates that this is a normal image list.</summary>
HDSIL_NORMAL = 0,
/// <summary>Indicates that this is a state image list.</summary>
HDSIL_STATE = 1
}
/// <summary>The variable that receives information about the results of a hit test.</summary>
[PInvokeData("Commctrl.h")]
[Flags]
public enum HeaderHitTestFlag : uint
{
@ -66,6 +78,7 @@ public static partial class ComCtl32
}
/// <summary>The type of filter specified by <see cref="HDITEM.pvFilter"/>.</summary>
[PInvokeData("Commctrl.h")]
public enum HeaderItemFilterType
{
/// <summary>String data.</summary>
@ -82,6 +95,7 @@ public static partial class ComCtl32
}
/// <summary>Flags that specify an <see cref="HDITEM"/> format.</summary>
[PInvokeData("Commctrl.h")]
[Flags]
public enum HeaderItemFormat : uint
{
@ -150,6 +164,7 @@ public static partial class ComCtl32
}
/// <summary>Determines which type of bitmap is displayed on a header column.</summary>
[PInvokeData("Commctrl.h")]
[Flags]
public enum HeaderItemImageDisplay
{
@ -170,6 +185,7 @@ public static partial class ComCtl32
}
/// <summary>Flags indicating which <see cref="HDITEM"/> structure members contain valid data or must be filled in.</summary>
[PInvokeData("Commctrl.h")]
[Flags]
public enum HeaderItemMask : uint
{
@ -219,6 +235,7 @@ public static partial class ComCtl32
}
/// <summary>Valid entries for <see cref="HDITEM.state"/>.</summary>
[PInvokeData("Commctrl.h")]
public enum HeaderItemState
{
/// <summary>No state value.</summary>
@ -247,6 +264,7 @@ public static partial class ComCtl32
/// If the column value is specified as -1, all the filters are cleared, and the HDN_FILTERCHANGE notification is sent only once.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-clearfilter
[MsgParams(typeof(int), null, LResultType = typeof(BOOL))]
HDM_CLEARFILTER = HDM_FIRST + 24, // int, 0
/// <summary>
@ -263,6 +281,7 @@ public static partial class ComCtl32
/// <para>Returns a handle to an image list that contains the new image as its only element.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-createdragimage
[MsgParams(typeof(int), null, LResultType = typeof(HIMAGELIST))]
HDM_CREATEDRAGIMAGE = HDM_FIRST + 16, // int, 0
/// <summary>
@ -276,6 +295,7 @@ public static partial class ComCtl32
/// <para>Returns <c>TRUE</c> if successful, or <c>FALSE</c> otherwise.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-deleteitem
[MsgParams(typeof(int), null, LResultType = typeof(BOOL))]
HDM_DELETEITEM = HDM_FIRST + 2, // int, 0
/// <summary>Moves the input focus to the edit box when a filter button has the focus.
@ -305,6 +325,7 @@ public static partial class ComCtl32
/// <para>Returns an integer. The <c>LRESULT</c> is cast to an integer that indicates <c>TRUE</c>(1) or <c>FALSE</c>(0).</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-editfilter
[MsgParams(typeof(int), typeof(BOOL), LResultType = typeof(BOOL))]
HDM_EDITFILTER = HDM_FIRST + 23, // int, bool
/// <summary>
@ -322,6 +343,7 @@ public static partial class ComCtl32
/// </para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getbitmapmargin
[MsgParams()]
HDM_GETBITMAPMARGIN = HDM_FIRST + 21, // 0,0
/// <summary>
@ -336,6 +358,7 @@ public static partial class ComCtl32
/// <para>Returns the index of the item in focus.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getfocuseditem
[MsgParams()]
HDM_GETFOCUSEDITEM = HDM_FIRST + 27, // 0,0
/// <summary>
@ -364,6 +387,7 @@ public static partial class ComCtl32
/// <para>Returns a handle to the image list set for the header control.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getimagelist
[MsgParams(typeof(HDSIL), null, LResultType = typeof(HIMAGELIST))]
HDM_GETIMAGELIST = HDM_FIRST + 9, // 0, 0
/// <summary>
@ -386,6 +410,7 @@ public static partial class ComCtl32
/// Applications should not assume that the text will always be placed in the requested buffer.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getitem
[MsgParams(typeof(int), typeof(HDITEM), LResultType = typeof(BOOL))]
HDM_GETITEM = HDM_FIRST + 11, // int, HDITEM
/// <summary>
@ -399,6 +424,7 @@ public static partial class ComCtl32
/// <para>Returns the number of items if successful, or -1 otherwise.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getitemcount
[MsgParams()]
HDM_GETITEMCOUNT = HDM_FIRST + 0, // 0, 0
/// <summary>
@ -417,6 +443,7 @@ public static partial class ComCtl32
/// </summary>
/// <remarks>The header item must have style <c>HDF_SPLITBUTTON</c>.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getitemdropdownrect
[MsgParams(typeof(int), typeof(RECT?), LResultType = typeof(BOOL))]
HDM_GETITEMDROPDOWNRECT = HDM_FIRST + 25, // int, RECT
/// <summary>
@ -434,6 +461,7 @@ public static partial class ComCtl32
/// <para>Returns nonzero if successful, or zero otherwise.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getitemrect
[MsgParams(typeof(int), typeof(RECT?), LResultType = typeof(BOOL))]
HDM_GETITEMRECT = HDM_FIRST + 7, // int, RECT*
/// <summary>
@ -462,6 +490,7 @@ public static partial class ComCtl32
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getorderarray
[MsgParams(typeof(int), typeof(int[]), LResultType = typeof(BOOL))]
HDM_GETORDERARRAY = HDM_FIRST + 17, // iCount, lpArray
/// <summary>
@ -480,6 +509,7 @@ public static partial class ComCtl32
/// </summary>
/// <remarks>The header control must have style <c>HDF_SPLITBUTTON</c>.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getoverflowrect
[MsgParams(null, typeof(RECT?), LResultType = typeof(BOOL))]
HDM_GETOVERFLOWRECT = HDM_FIRST + 26, // 0, RECT*
/// <summary>
@ -498,6 +528,7 @@ public static partial class ComCtl32
/// </summary>
/// <remarks>See the remarks for <c>CCM_GETUNICODEFORMAT</c> for a discussion of this message.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-getunicodeformat
[MsgParams(null, null, LResultType = typeof(BOOL))]
HDM_GETUNICODEFORMAT = 0X2006, // CCM_GETUNICODEFORMAT,
/// <summary>Tests a point to determine which header item, if any, is at the specified point.
@ -510,9 +541,10 @@ public static partial class ComCtl32
/// of the test.
/// </para>
/// <para><strong>Returns</strong></para>
/// <para>Returns the index of the item at the specified position, if any, or 1 otherwise.</para>
/// <para>Returns the index of the item at the specified position, if any, or -1 otherwise.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-hittest
[MsgParams(null, typeof(HDHITTESTINFO), LResultType = typeof(int))]
HDM_HITTEST = HDM_FIRST + 6, // 0, HDHITTEST
/// <summary>
@ -530,6 +562,7 @@ public static partial class ComCtl32
/// <para>Returns the index of the new item if successful, or -1 otherwise.</para>
/// </summary>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-insertitem
[MsgParams(typeof(int), typeof(HDITEM), LResultType = typeof(int))]
HDM_INSERTITEM = HDM_FIRST + 10, // int, HDITEM
/// <summary>
@ -559,6 +592,7 @@ public static partial class ComCtl32
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/controls/hdm-layout
[MsgParams(null, typeof(HDLAYOUT), LResultType = typeof(BOOL))]
HDM_LAYOUT = HDM_FIRST + 5, // 0, HDLAYOUT
/// <summary>
@ -1639,7 +1673,7 @@ public static partial class ComCtl32
/// <summary>Contains information used in handling HDN_GETDISPINFO notification codes.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775253")]
[StructLayout(LayoutKind.Sequential)]
public sealed class NMHDDISPINFO
public sealed class NMHDDISPINFO : INotificationInfo
{
/// <summary>NMHDR structure containing information about this notification code</summary>
public NMHDR hdr;
@ -1670,7 +1704,7 @@ public static partial class ComCtl32
/// <summary>Specifies or receives the attributes of a filter button click.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775255")]
[StructLayout(LayoutKind.Sequential)]
public sealed class NMHDFILTERBTNCLICK
public sealed class NMHDFILTERBTNCLICK : INotificationInfo
{
/// <summary>A handle of an NMHDR structure that contains additional information.</summary>
public NMHDR hdr;
@ -1685,7 +1719,7 @@ public static partial class ComCtl32
/// <summary>Contains information about header control notification messages. This structure supersedes the HD_NOTIFY structure.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775257")]
[StructLayout(LayoutKind.Sequential)]
public sealed class NMHEADER
public sealed class NMHEADER : INotificationInfo
{
/// <summary>A NMHDR structure that contains information about the notification message.</summary>
public NMHDR nmhdr;

View File

@ -172,7 +172,7 @@ public static partial class ComCtl32
/// <summary>Contains information for the IPN_FIELDCHANGED notification code.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb761375")]
[StructLayout(LayoutKind.Sequential)]
public struct NMIPADDRESS
public struct NMIPADDRESS : INotificationInfo
{
/// <summary>An <see cref="NMHDR"/> structure that contains additional information about the notification.</summary>
public NMHDR hdr;

View File

@ -5769,7 +5769,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb774773")]
[StructLayout(LayoutKind.Sequential)]
public struct NMLISTVIEW
public struct NMLISTVIEW : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification message</summary>
public NMHDR hdr;

View File

@ -1021,7 +1021,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb760258")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTTDISPINFO
public struct NMTTDISPINFO : INotificationInfo
{
/// <summary>NMHDR structure that contains additional information about the notification.</summary>
public NMHDR hdr;

View File

@ -2861,7 +2861,7 @@ public static partial class ComCtl32
TBSTYLE_CHECK = 0x0002,
/// <summary>Equivalent to BTNS_CHECKGROUP. Use TBSTYLE_CHECKGROUP for version 4.72 and earlier.</summary>
TBSTYLE_CHECKGROUP = (TBSTYLE_GROUP | TBSTYLE_CHECK),
TBSTYLE_CHECKGROUP = TBSTYLE_GROUP | TBSTYLE_CHECK,
/// <summary>Version 4.70. Generates NM_CUSTOMDRAW notification codes when the toolbar processes WM_ERASEBKGND messages.</summary>
TBSTYLE_CUSTOMERASE = 0x2000,
@ -3160,7 +3160,7 @@ public static partial class ComCtl32
// *LPNMTBDISPINFO; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760452(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760452")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTBDISPINFO
public struct NMTBDISPINFO : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -3243,7 +3243,7 @@ public static partial class ComCtl32
// *LPNMTBGETINFOTIP; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760454(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760454")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTBGETINFOTIP
public struct NMTBGETINFOTIP : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -3290,7 +3290,7 @@ public static partial class ComCtl32
// typedef struct tagNMTBHOTITEM { NMHDR hdr; int idOld; int idNew; DWORD dwFlags;} NMTBHOTITEM, *LPNMTBHOTITEM; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760456(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760456")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTBHOTITEM
public struct NMTBHOTITEM : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -3378,7 +3378,7 @@ public static partial class ComCtl32
// cbBytesPerRecord; TBBUTTON tbButton;} NMTBRESTORE, *LPNMTBRESTORE; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760458(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760458")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTBRESTORE
public struct NMTBRESTORE : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -3457,7 +3457,7 @@ public static partial class ComCtl32
// *LPNMTBSAVE; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760471(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760471")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTBSAVE
public struct NMTBSAVE : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -3526,7 +3526,7 @@ public static partial class ComCtl32
// *LPNMTOOLBAR; https://msdn.microsoft.com/en-us/library/windows/desktop/bb760473(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb760473")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTOOLBAR
public struct NMTOOLBAR : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>

View File

@ -873,14 +873,14 @@ public static partial class ComCtl32
/// <summary>Contains information about a trackbar change notification. This message is sent with the TRBN_THUMBPOSCHANGING notification.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb760153")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTRBTHUMBPOSCHANGING
public struct NMTRBTHUMBPOSCHANGING : INotificationInfo
{
/// <summary>Position on trackbar.</summary>
public uint dwPos;
/// <summary>A NMHDR structure that describes the notification.</summary>
public NMHDR hdr;
/// <summary>Position on trackbar.</summary>
public uint dwPos;
/// <summary>
/// Type of movement as one of the following values: TB_LINEUP, TB_LINEDOWN, TB_PAGEUP, TB_PAGEDOWN, TB_THUMBPOSITION,
/// TB_THUMBTRACK, TB_TOP, TB_BOTTOM, or TB_ENDTRACK.

View File

@ -2343,7 +2343,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773411")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTREEVIEW
public struct NMTREEVIEW : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification message.</summary>
public NMHDR hdr;
@ -2380,7 +2380,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773413")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTVASYNCDRAW
public struct NMTVASYNCDRAW : INotificationInfo
{
/// <summary>NMHDR structure.</summary>
public NMHDR hdr;
@ -2438,7 +2438,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773418")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTVDISPINFO
public struct NMTVDISPINFO : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification.</summary>
public NMHDR hdr;
@ -2453,7 +2453,7 @@ public static partial class ComCtl32
/// <summary>Contains information pertaining to extended TreeView notification information.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb760143")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NMTVDISPINFOEX
public struct NMTVDISPINFOEX : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification.</summary>
public NMHDR hdr;
@ -2468,7 +2468,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773421")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMTVGETINFOTIP
public struct NMTVGETINFOTIP : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification.</summary>
public NMHDR hdr;
@ -2497,7 +2497,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773425")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMTVITEMCHANGE
public struct NMTVITEMCHANGE : INotificationInfo
{
/// <summary>NMHDR structure that contains information about the notification.</summary>
public NMHDR hdr;
@ -2527,7 +2527,7 @@ public static partial class ComCtl32
/// </summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb773433")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTVKEYDOWN
public struct NMTVKEYDOWN : INotificationInfo
{
/// <summary>NMHDR structure that contains information about this notification.</summary>
public NMHDR hdr;

View File

@ -442,7 +442,7 @@ public static partial class ComCtl32
/// </summary>
// typedef struct _NM_UPDOWN { NMHDR hdr; int iPos; int iDelta;} NMUPDOWN, *LPNMUPDOWN; https://msdn.microsoft.com/en-us/library/windows/desktop/bb759893(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb759893")]
public struct NMUPDOWN
public struct NMUPDOWN : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>

View File

@ -766,16 +766,16 @@ public static partial class ComCtl32
CDDS_ITEM = 0x00010000,
/// <summary>Before an item is drawn.</summary>
CDDS_ITEMPREPAINT = (CDDS_ITEM | CDDS_PREPAINT),
CDDS_ITEMPREPAINT = CDDS_ITEM | CDDS_PREPAINT,
/// <summary>After an item has been drawn.</summary>
CDDS_ITEMPOSTPAINT = (CDDS_ITEM | CDDS_POSTPAINT),
CDDS_ITEMPOSTPAINT = CDDS_ITEM | CDDS_POSTPAINT,
/// <summary>Before an item is erased.</summary>
CDDS_ITEMPREERASE = (CDDS_ITEM | CDDS_PREERASE),
CDDS_ITEMPREERASE = CDDS_ITEM | CDDS_PREERASE,
/// <summary>After an item has been erased.</summary>
CDDS_ITEMPOSTERASE = (CDDS_ITEM | CDDS_POSTERASE),
CDDS_ITEMPOSTERASE = CDDS_ITEM | CDDS_POSTERASE,
/// <summary>
/// Flag combined with CDDS_ITEMPREPAINT or CDDS_ITEMPOSTPAINT if a subitem is being drawn. This will only be set if
@ -970,7 +970,7 @@ public static partial class ComCtl32
for (var i = 0; i < controlIdentifiers.Length; i++)
{
lpInfo[(i + 1) * 2] = 1;
lpInfo[((i + 1) * 2) + 1] = controlIdentifiers[i];
lpInfo[(i + 1) * 2 + 1] = controlIdentifiers[i];
}
var ptr = InteropServices.SafeCoTaskMemHandle.CreateFromList(lpInfo);
GetEffectiveClientRect(hWnd, out var rect, (IntPtr)ptr);
@ -1037,7 +1037,7 @@ public static partial class ComCtl32
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb776430")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, [MarshalAs(UnmanagedType.SysUInt)] uint uIdSubclass, out IntPtr pdwRefData);
public static extern bool GetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, nuint uIdSubclass, out IntPtr pdwRefData);
/// <summary>
/// Ensures that the common control DLL (Comctl32.dll) is loaded, and registers specific common control classes from the DLL. An
@ -1076,64 +1076,107 @@ public static partial class ComCtl32
/// <summary>Loads a specified icon resource with a client-specified system metric.</summary>
/// <param name="hinst">
/// <para>Type: <c><c>HINSTANCE</c></c></para>
/// <para>Type: <c>HINSTANCE</c></para>
/// <para>
/// A handle to the module of either a DLL or executable (.exe) file that contains the icon to be loaded. For more information, see <c>GetModuleHandle</c>.
/// A handle to the module of either a DLL or executable (.exe) file that contains the icon to be loaded. For more information, see GetModuleHandle.
/// </para>
/// <para>To load a predefined icon or a standalone icon file, set this parameter to <c>NULL</c>.</para>
/// </param>
/// <param name="pszName">
/// <para>Type: <c><c>PCWSTR</c></c></para>
/// <para>Type: <c>PCWSTR</c></para>
/// <para>
/// A pointer to a null-terminated, Unicode buffer that contains location information about the icon to load. It is interpreted as follows:
/// </para>
/// <para>If hinst is <c>NULL</c>, pszName can specify one of two things.</para>
/// <para>If hinst is non-null, pszName can specify one of two things.</para>
/// <para>If <c>hinst</c> is <c>NULL</c>, <c>pszName</c> can specify one of two things.</para>
/// <list type="number">
/// <item>
/// <description>The name of a standalone icon (.ico) file.</description>
/// </item>
/// <item>
/// <description>The identifier of a predefined icon to load. These identifiers are recognized:</description>
/// </item>
/// </list>
/// <para>If <c>hinst</c> is non-null, <c>pszName</c> can specify one of two things.</para>
/// <list type="number">
/// <item>
/// <description>The name of the icon resource, if the icon resource is to be loaded by name from the module.</description>
/// </item>
/// <item>
/// <description>
/// The icon ordinal, if the icon resource is to be loaded by ordinal from the module. This ordinal must be packaged by using the
/// MAKEINTRESOURCE macro.
/// </description>
/// </item>
/// </list>
/// </param>
/// <param name="lims">
/// <para>Type: <c>int</c></para>
/// <para>The desired metric. One of the following values:</para>
/// <para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// <description>Value</description>
/// <description>Meaning</description>
/// </listheader>
/// <item>
/// <term>LIM_SMALL</term>
/// <term>Corresponds to SM_CXSMICON, the recommended pixel width of a small icon.</term>
/// <description><c>LIM_SMALL</c></description>
/// <description>Corresponds to SM_CXSMICON, the recommended pixel width of a small icon.</description>
/// </item>
/// <item>
/// <term>LIM_LARGE</term>
/// <term>Corresponds toSM_CXICON, the default pixel width of an icon.</term>
/// <description><c>LIM_LARGE</c></description>
/// <description>Corresponds toSM_CXICON, the default pixel width of an icon.</description>
/// </item>
/// </list>
/// </para>
/// </param>
/// <param name="phico">
/// <para>Type: <c><c>HICON</c>*</c></para>
/// <para>Type: <c>HICON*</c></para>
/// <para>When this function returns, contains a pointer to the handle of the loaded icon.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>Type: <c>HRESULT</c></para>
/// <para>Returns S_OK if successful, otherwise an error, including the following value.</para>
/// <para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// <description>Return code</description>
/// <description>Description</description>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>The contents of the buffer pointed to by pszName do not fit any of the expected interpretations.</term>
/// <description><c>E_INVALIDARG</c></description>
/// <description>The contents of the buffer pointed to by <c>pszName</c> do not fit any of the expected interpretations.</description>
/// </item>
/// </list>
/// </para>
/// </returns>
// HRESULT LoadIconMetric( _In_ HINSTANCE hinst, _In_ PCWSTR pszName, _In_ int lims, _Out_ HICON *phico); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775701(v=vs.85).aspx
/// <remarks>
/// <para>
/// <c>LoadIconMetric</c> is similar to LoadIcon, but with the capability to specify the icon metric. It is used in place of
/// <c>LoadIcon</c> when the calling application wants to ensure a high quality icon. This is particularly useful in high dots per inch
/// (dpi) situations.
/// </para>
/// <para>Icons are extracted or created as follows.</para>
/// <list type="number">
/// <item>
/// <description>If an exact size match is found in the resource, that icon is used.</description>
/// </item>
/// <item>
/// <description>
/// If an exact size match cannot be found and a larger icon is available, a new icon is created by scaling the larger version down to
/// the desired size.
/// </description>
/// </item>
/// <item>
/// <description>
/// If an exact size match cannot be found and no larger icon is available, a new icon is created by scaling a smaller icon up to the
/// desired size.
/// </description>
/// </item>
/// </list>
/// <para>Comparative calls are shown here for <c>LoadIconMetric</c> and LoadIcon.</para>
/// <para>The application is responsible for calling DestroyIcon on the retrieved icon.</para>
/// </remarks>
// https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-loadiconmetric
// HRESULT LoadIconMetric( [in] HINSTANCE hinst, [in] PCWSTR pszName, [in] int lims, [out] HICON *phico );
[PInvokeData("commctrl.h", MSDNShortId = "NF:commctrl.LoadIconMetric")]
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775701")]
public static extern HRESULT LoadIconMetric(HINSTANCE hinst, string pszName, LI_METRIC lims, out SafeHICON phico);
public static extern HRESULT LoadIconMetric([In, Optional] HINSTANCE hinst, [MarshalAs(UnmanagedType.LPWStr)] string pszName, LI_METRIC lims, out SafeHICON phico);
/// <summary>
/// Loads an icon. If the icon is not a standard size, this function scales down a larger image instead of scaling up a smaller image.
@ -1238,7 +1281,7 @@ public static partial class ComCtl32
// HRESULT WINAPI LoadIconWithScaleDown( _In_ HINSTANCE hinst, _In_ PCWSTR pszName, _In_ int cx, _In_ int cy, _Out_ HICON *phico); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775703(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775703")]
public static extern HRESULT LoadIconWithScaleDown(HINSTANCE hinst, string pszName, int cx, int cy, out IntPtr phico);
public static extern HRESULT LoadIconWithScaleDown([In, Optional] HINSTANCE hinst, [MarshalAs(UnmanagedType.LPWStr)] string pszName, int cx, int cy, out SafeHICON phico);
/// <summary>Removes a subclass callback from a window.</summary>
/// <param name="hWnd">
@ -1391,7 +1434,7 @@ public static partial class ComCtl32
// typedef struct tagNMCHAR { NMHDR hdr; UINT ch; DWORD dwItemPrev; DWORD dwItemNext;} NMCHAR, *LPNMCHAR; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775508(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775508")]
[StructLayout(LayoutKind.Sequential)]
public struct NMCHAR
public struct NMCHAR : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -1421,7 +1464,7 @@ public static partial class ComCtl32
/// <summary>Contains information specific to an NM_CUSTOMDRAW notification code.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775483")]
[StructLayout(LayoutKind.Sequential)]
public struct NMCUSTOMDRAW
public struct NMCUSTOMDRAW : INotificationInfo
{
/// <summary>An NMHDR structure that contains information about this notification code.</summary>
public NMHDR hdr;
@ -1454,7 +1497,7 @@ public static partial class ComCtl32
/// <summary>Contains information about the two rectangles of a split button. Sent with the NM_GETCUSTOMSPLITRECT notification.</summary>
[PInvokeData("Commctrl.h", MSDNShortId = "bb775510")]
[StructLayout(LayoutKind.Sequential)]
public struct NMCUSTOMSPLITRECTINFO
public struct NMCUSTOMSPLITRECTINFO : INotificationInfo
{
/// <summary>An NMHDR structure that contains information about the notification.</summary>
public NMHDR hdr;
@ -1474,7 +1517,7 @@ public static partial class ComCtl32
// *LPNMCUSTOMTEXT; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775512(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775512")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NMCUSTOMTEXT
public struct NMCUSTOMTEXT : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -1513,7 +1556,7 @@ public static partial class ComCtl32
/// function. This may be <c>NULL</c>.
/// </para>
/// </summary>
public uint uFormat;
public DrawTextFlags uFormat;
/// <summary>
/// <para>Type: <c><c>BOOL</c></c></para>
@ -1527,7 +1570,7 @@ public static partial class ComCtl32
// typedef struct tagNMKEY { NMHDR hdr; UINT nVKey; UINT uFlags;} NMKEY, *LPNMKEY; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775516(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775516")]
[StructLayout(LayoutKind.Sequential)]
public struct NMKEY
public struct NMKEY : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -1556,7 +1599,7 @@ public static partial class ComCtl32
// *LPNMMOUSE; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775518(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775518")]
[StructLayout(LayoutKind.Sequential)]
public struct NMMOUSE
public struct NMMOUSE : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -1594,7 +1637,7 @@ public static partial class ComCtl32
// *LPNMOBJECTNOTIFY; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775520(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775520")]
[StructLayout(LayoutKind.Sequential)]
public struct NMOBJECTNOTIFY
public struct NMOBJECTNOTIFY : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>
@ -1640,7 +1683,7 @@ public static partial class ComCtl32
// typedef struct tagNMTOOLTIPSCREATED { NMHDR hdr; HWND hwndToolTips;} NMTOOLTIPSCREATED, *LPNMTOOLTIPSCREATED; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775522(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775522")]
[StructLayout(LayoutKind.Sequential)]
public struct NMTOOLTIPSCREATED
public struct NMTOOLTIPSCREATED : INotificationInfo
{
/// <summary>
/// <para>Type: <c><c>NMHDR</c></c></para>

View File

@ -1671,7 +1671,7 @@ public static partial class Kernel32
}
/// <summary>Represents a NULL value.</summary>
public static HACTCTX Null => new SafeHACTCTX(IntPtr.Zero, false);
public static SafeHACTCTX Null => new SafeHACTCTX(IntPtr.Zero, false);
/// <summary>Performs an implicit conversion from <see cref="SafeHACTCTX"/> to <see cref="HACTCTX"/>.</summary>
/// <param name="h">The safe handle instance.</param>

View File

@ -52,9 +52,20 @@ public static class MsgExtensions
}
else
{
object? wParam = attr.WParamType is null ? null : attr.WParamType.IsNullable() ? msg.wParam.ToStructure(attr.WParamType) : msg.wParam.ToInt32().CastTo(attr.WParamType);
object? lParam = attr.LParamType is null ? null : attr.LParamType.IsNullable() ? msg.lParam.ToStructure(attr.LParamType) : msg.lParam.ToInt32().CastTo(attr.LParamType);
object? wParam = GetParam(attr.WParamType, msg.wParam);
object? lParam = GetParam(attr.LParamType, msg.lParam);
return (wParam, lParam);
}
static object? GetParam(Type? t, IntPtr p)
{
if (t is null)
return null;
if (t.IsClass)
return p.ToStructure(t);
if (t.IsNullable())
return p.ToStructure(t.GetGenericArguments()[0]);
return p.ToInt32().CastTo(t);
}
}
}

View File

@ -6,6 +6,14 @@ namespace Vanara.PInvoke;
public static partial class User32
{
/// <summary>
/// Interface to indicate that a structure provides information about a notification and contains a <see cref="NMHDR"/> structure as its
/// first member.
/// </summary>
public interface INotificationInfo
{
}
/// <summary>Contains information about a notification message.</summary>
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-nmhdr
// typedef struct tagNMHDR { HWND hwndFrom; UINT_PTR idFrom; UINT code; } NMHDR;