using System;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.User32;
namespace Vanara.PInvoke
{
public static partial class ComCtl32
{
/// The default color.
public const uint CLR_DEFAULT = 0xFF000000;
/// No color.
public const uint CLR_NONE = 0xFFFFFFFF;
public const int I_IMAGECALLBACK = -1;
public const int I_IMAGENONE = -2;
public const int INFOTIPSIZE = 1024;
public const int NM_FIRST = 0;
[PInvokeData("Commctrl.h")]
public static readonly IntPtr LPSTR_TEXTCALLBACK = (IntPtr)(-1);
/// Defines the prototype for the callback function used by RemoveWindowSubclass and SetWindowSubclass.
///
/// Type: HWND
/// The handle to the subclassed window.
///
///
/// Type: UINT
/// The message being passed.
///
///
/// Type: WPARAM
/// Additional message information. The contents of this parameter depend on the value of uMsg.
///
///
/// Type: LPARAM
/// Additional message information. The contents of this parameter depend on the value of uMsg.
///
///
/// Type: UINT_PTR
/// The subclass ID.
///
///
/// Type: DWORD_PTR
///
/// The reference data provided to the SetWindowSubclass function. This can be used to associate the subclass instance with a
/// "this" pointer.
///
///
///
/// Type: LRESULT
/// The return value is the result of the message processing and depends on the message sent.
///
// typedef LRESULT ( CALLBACK *SUBCLASSPROC)( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR
// dwRefData); https://msdn.microsoft.com/en-us/library/windows/desktop/bb776774(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb776774")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr SUBCLASSPROC(HWND hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, [MarshalAs(UnmanagedType.SysUInt)] uint uIdSubclass, IntPtr dwRefData);
///
/// The set of bit flags that indicate which common control classes will be loaded from the DLL when calling .
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb775507")]
[Flags]
public enum CommonControlClass
{
/// Load animate control class.
ICC_ANIMATE_CLASS = 0X00000080,
/// Load toolbar, status bar, trackbar, and tooltip control classes.
ICC_BAR_CLASSES = 0X00000004,
/// Load rebar control class.
ICC_COOL_CLASSES = 0X00000400,
/// Load date and time picker control class.
ICC_DATE_CLASSES = 0X00000100,
/// Load hot key control class.
ICC_HOTKEY_CLASS = 0X00000040,
/// Load IP address class.
ICC_INTERNET_CLASSES = 0X00000800,
/// Load a hyperlink control class.
ICC_LINK_CLASS = 0X00008000,
/// Load list-view and header control classes.
ICC_LISTVIEW_CLASSES = 0X00000001,
/// Load a native font control class.
ICC_NATIVEFNTCTL_CLASS = 0x00002000,
/// Load pager control class.
ICC_PAGESCROLLER_CLASS = 0X00001000,
/// Load progress bar control class.
ICC_PROGRESS_CLASS = 0X00000020,
///
/// Load one of the intrinsic User32 control classes. The user controls include button, edit, static, listbox, combobox, and
/// scroll bar.
///
ICC_STANDARD_CLASSES = 0X00004000,
/// Load tab and tooltip control classes.
ICC_TAB_CLASSES = 0X00000008,
/// Load tree-view and tooltip control classes.
ICC_TREEVIEW_CLASSES = 0X00000002,
/// Load up-down control class.
ICC_UPDOWN_CLASS = 0X00000010,
/// Load ComboBoxEx class.
ICC_USEREX_CLASSES = 0X00000200,
///
/// Load animate control, header, hot key, list-view, progress bar, status bar, tab, tooltip, toolbar, trackbar, tree-view, and
/// up-down control classes.
///
ICC_WIN95_CLASSES = 0X000000FF
}
/// Notification codes for CommCtrl.h
public enum CommonControlNotification
{
///
/// Notifies a control's parent window that the control could not complete an operation because there was not enough memory
/// available. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_OUTOFMEMORY = NM_FIRST - 1,
///
/// Sent by a control when the user clicks with the left mouse button. This notification code is sent in the form of a WM_NOTIFY message.
///
NM_CLICK = NM_FIRST - 2,
///
/// Sent by a control when the user double-clicks with the left mouse button. This notification code is sent in the form of a
/// WM_NOTIFY message.
///
NM_DBLCLK = NM_FIRST - 3,
///
/// Notifies a control's parent window that the control has the input focus and that the user has pressed the ENTER key. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_RETURN = NM_FIRST - 4,
///
/// Sent by a control when the user clicks with the right mouse button. This notification code is sent in the form of a WM_NOTIFY message.
///
NM_RCLICK = NM_FIRST - 5,
///
/// Sent by a control when the user double-clicks with the right mouse button. This notification code is sent in the form of a
/// WM_NOTIFY message.
///
NM_RDBLCLK = NM_FIRST - 6,
///
/// Notifies a control's parent window that the control has received the input focus. This notification code is sent in the form
/// of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_SETFOCUS = NM_FIRST - 7,
///
/// Notifies a control's parent window that the control has lost the input focus. This notification code is sent in the form of a
/// WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_KILLFOCUS = NM_FIRST - 8,
///
/// Notifies a control's parent window about custom drawing operations. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
///
/// A pointer to a custom draw-related structure that contains information about the drawing operation. The following list
/// specifies the controls and their associated structures.
///
///
/// Control
/// Custom Draw Structure
///
/// -
/// Rebar, trackbar, and header
/// NMCUSTOMDRAW
///
/// -
/// List view
/// NMLVCUSTOMDRAW
///
/// -
/// Tooltip
/// NMTTCUSTOMDRAW
///
/// -
/// Tree view
/// NMTVCUSTOMDRAW
///
/// -
/// Toolbar
/// NMTBCUSTOMDRAW
///
///
///
///
///
/// -
/// Return value
///
/// The value your application can return depends on the current drawing stage. The dwDrawStage member of the associated
/// NMCUSTOMDRAW structure holds a value that specifies the drawing stage.
///
///
///
NM_CUSTOMDRAW = NM_FIRST - 12,
///
/// Sent by a control when the mouse hovers over an item. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
/// -
/// Return value
///
/// Unless otherwise specified, return zero to allow the control to process the hover normally, or nonzero to prevent the hover
/// from being processed.
///
///
///
///
NM_HOVER = NM_FIRST - 13,
///
/// Sent by a rebar control when the control receives a WM_NCHITTEST message. This notification code is sent in the form of a
/// WM_NOTIFY message.
///
/// -
/// lParam
///
/// A pointer to a NMMOUSE structure that contains information about the notification code. The pt member contains the mouse
/// coordinates of the hit test message.
///
///
/// -
/// Return value
///
/// Unless otherwise specified, return zero to allow the control to perform default processing of the hit test message, or return
/// one of the HT* values documented under WM_NCHITTEST to override the default hit test processing.
///
///
///
///
NM_NCHITTEST = NM_FIRST - 14,
///
/// Sent by a control when the control has the keyboard focus and the user presses a key. This notification code is sent in the
/// form of a WM_NOTIFY message.
///
/// -
/// lParam
///
/// A pointer to an NMKEY structure that contains additional information about the key that caused the notification code.
///
///
/// -
/// Return value
/// Return nonzero to prevent the control from processing the key, or zero otherwise.
///
///
///
NM_KEYDOWN = NM_FIRST - 15,
///
/// Notifies a control's parent window that the control is releasing mouse capture. This notification code is sent in the form of
/// a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_RELEASEDCAPTURE = NM_FIRST - 16,
///
/// Notifies a control's parent window that the control is setting the cursor in response to a WM_SETCURSOR message. This
/// notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMMOUSE structure that contains additional information about this notification.
///
/// -
/// Return value
///
/// Return zero to enable the control to set the cursor or nonzero to prevent the control from setting the cursor.
///
///
///
///
NM_SETCURSOR = NM_FIRST - 17,
///
/// The NM_CHAR notification code is sent by a control when a character key is processed. This notification code is sent in the
/// form of a WM_NOTIFY message.
///
/// -
/// lParam
///
/// A pointer to an NMCHAR structure that contains additional information about the character that caused the notification code.
///
///
///
///
NM_CHAR = NM_FIRST - 18,
///
/// Notifies a control's parent window that the control has created a tooltip control. This notification code is sent in the form
/// of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMTOOLTIPSCREATED structure that contains additional information about this notification.
///
///
///
NM_TOOLTIPSCREATED = NM_FIRST - 19,
///
/// Notifies a control's parent window that the left mouse button has been pressed. This notification code is sent in the form of
/// a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_LDOWN = NM_FIRST - 20,
/// This notification code is not supported.
NM_RDOWN = NM_FIRST - 21,
///
/// Notifies a control's parent window that the theme has changed. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_THEMECHANGED = NM_FIRST - 22,
///
/// Sent by a list-view control when the control has changed a font. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMHDR structure that contains additional information about this notification.
///
///
///
NM_FONTCHANGED = NM_FIRST - 23,
///
/// Notifies a control's parent window about custom text operations. This notification code is sent in the form of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMCUSTOMTEXT structure that contains additional information about this notification.
///
///
///
NM_CUSTOMTEXT = NM_FIRST - 24,
///
/// Sent by a tree-view control to its parent window that the state image is changing. This notification code is sent in the form
/// of a WM_NOTIFY message.
///
/// -
/// lParam
/// A pointer to an NMTVSTATEIMAGECHANGING structure that contains additional information about this notification.
///
///
///
NM_TVSTATEIMAGECHANGING = NM_FIRST - 24,
}
/// The current item state.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775483")]
[Flags]
public enum CustomDrawItemState
{
/// The item is selected.
CDIS_SELECTED = 0x0001,
/// The item is grayed.
CDIS_GRAYED = 0x0002,
/// The item is disabled.
CDIS_DISABLED = 0x0004,
/// The item is in focus.
CDIS_CHECKED = 0x0008,
/// The item is in focus.
CDIS_FOCUS = 0x0010,
/// The item is in its default state.
CDIS_DEFAULT = 0x0020,
/// The item is currently under the pointer ("hot").
CDIS_HOT = 0x0040,
///
/// The item is marked. The meaning of this is determined by the implementation. This flag does not work correctly for
/// owner-drawn list-view controls that have the LVS_SHOWSELALWAYS style. For these controls, you can determine whether an item
/// is selected by using LVM_GETITEMSTATE (or
/// ListView_GetItemState) and checking for the LVIS_SELECTED flag.
///
CDIS_MARKED = 0x0080,
/// The item is in an indeterminate state.
CDIS_INDETERMINATE = 0x0100,
///
/// Version 6.0.The item is showing its keyboard cues. Comctl32 version 6 is not redistributable. operating systems. To use
/// Comctl32.dll version 6, specify it in the manifest. For more information on manifests, see Enabling Visual Styles.
///
CDIS_SHOWKEYBOARDCUES = 0x0200,
///
/// The item is part of a control that is currently under the mouse pointer ("hot"), but the item is not "hot" itself. The
/// meaning of this is determined by the implementation.
///
CDIS_NEARHOT = 0x0400,
///
/// The item is part of a splitbutton that is currently under the mouse pointer ("hot"), but the item is not "hot" itself. The
/// meaning of this is determined by the implementation.
///
CDIS_OTHERSIDEHOT = 0x0800,
/// The item is currently the drop target of a drag-and-drop operation.
CDIS_DROPHILITED = 0x1000,
}
/// These constants are used as return values by a control in response to an NM_CUSTOMDRAW notification code.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775489")]
[Flags]
public enum CustomDrawResponse
{
///
/// The control will draw itself. It will not send any additional NM_CUSTOMDRAW notification codes for this paint cycle. This
/// occurs when the dwDrawStage of the NMCUSTOMDRAW structure equals CDDS_PREPAINT.
///
CDRF_DODEFAULT = 0x00000000,
///
/// The application specified a new font for the item; the control will use the new font. For more information about changing
/// fonts, see Changing fonts and colors. This occurs when the dwDrawStage of the NMCUSTOMDRAW structure equals CDDS_ITEMPREPAINT.
///
CDRF_NEWFONT = 0x00000002,
///
/// The application drew the item manually. The control will not draw the item. This occurs when the dwDrawStage of the
/// NMCUSTOMDRAW structure equals CDDS_ITEMPREPAINT.
///
CDRF_SKIPDEFAULT = 0x00000004,
/// Windows Vista and later. The control will draw the background.
CDRF_DOERASE = 0x00000008,
///
/// The control will notify the parent after painting an item. This occurs when the dwDrawStage of the NMCUSTOMDRAW structure
/// equals CDDS_PREPAINT.
///
CDRF_NOTIFYPOSTPAINT = 0x00000010,
///
/// The control will notify the parent of any item-related drawing operations. It will send NM_CUSTOMDRAW notification codes
/// before and after drawing items. This occurs when the dwDrawStage of the NMCUSTOMDRAW structure equals CDDS_PREPAINT.
///
CDRF_NOTIFYITEMDRAW = 0x00000020,
///
/// Internet Explorer 4.0 and later. The control will notify the parent of any item-related drawing operations. It will send
/// NM_CUSTOMDRAW notification codes before and after drawing items. This occurs when the dwDrawStage of the NMCUSTOMDRAW
/// structure equals CDDS_PREPAINT. This flag is identical to CDRF_NOTIFYITEMDRAW and its use is context-dependent.
///
CDRF_NOTIFYSUBITEMDRAW = 0x00000020,
///
/// The control will notify the parent after erasing an item. This occurs when the dwDrawStage of the NMCUSTOMDRAW structure
/// equals CDDS_PREPAINT.
///
CDRF_NOTIFYPOSTERASE = 0x00000040,
/// Windows Vista and later. The control will not draw the focus rectangle.
CDRF_SKIPPOSTPAINT = 0x00000100,
}
/// The current drawing stage.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775483")]
[Flags]
public enum CustomDrawStage
{
/// Before the painting cycle begins.
CDDS_PREPAINT = 0x00000001,
/// After the painting cycle is complete.
CDDS_POSTPAINT = 0x00000002,
/// Before the erasing cycle begins.
CDDS_PREERASE = 0x00000003,
/// After the erasing cycle is complete.
CDDS_POSTERASE = 0x00000004,
/// Indicates that the dwItemSpec, uItemState, and lItemlParam members are valid.
CDDS_ITEM = 0x00010000,
/// Before an item is drawn.
CDDS_ITEMPREPAINT = (CDDS_ITEM | CDDS_PREPAINT),
/// After an item has been drawn.
CDDS_ITEMPOSTPAINT = (CDDS_ITEM | CDDS_POSTPAINT),
/// Before an item is erased.
CDDS_ITEMPREERASE = (CDDS_ITEM | CDDS_PREERASE),
/// After an item has been erased.
CDDS_ITEMPOSTERASE = (CDDS_ITEM | CDDS_POSTERASE),
///
/// Flag combined with CDDS_ITEMPREPAINT or CDDS_ITEMPOSTPAINT if a subitem is being drawn. This will only be set if
/// CDRF_NOTIFYITEMDRAW is returned from CDDS_PREPAINT.
///
CDDS_SUBITEM = 0x00020000,
}
/// Flags that indicate why the hot item has changed.
[PInvokeData("Commctrl.h", MSDNShortId = "bb760456")]
[Flags]
public enum HotItemChangeFlags
{
///
/// The change in the hot item resulted from an event that could not be determined. This will most often be due to a change in
/// focus or the TB_SETHOTITEM message.
///
HICF_OTHER = 0x00000000,
/// The change in the hot item resulted from a mouse event.
HICF_MOUSE = 0x00000001,
/// The change in the hot item was caused by an arrow key.
HICF_ARROWKEYS = 0x00000002,
/// The change in the hot item was caused by a shortcut key.
HICF_ACCELERATOR = 0x00000004,
/// Modifies HICF_ACCELERATOR. If this flag is set, more than one item has the same shortcut key character.
HICF_DUPACCEL = 0x00000008,
///
/// Modifies the other reason flags. If this flag is set, there is no previous hot item and idOld does not contain valid information.
///
HICF_ENTERING = 0x00000010,
///
/// Modifies the other reason flags. If this flag is set, there is no new hot item and idNew does not contain valid information.
///
HICF_LEAVING = 0x00000020,
/// The change in the hot item resulted from the user entering the shortcut key for an item that was already hot.
HICF_RESELECT = 0x00000040,
/// The change in the hot item resulted from a left-click mouse event.
HICF_LMOUSE = 0x00000080,
/// Version 5.80. Causes the button to switch states.
HICF_TOGGLEDROPDOWN = 0x00000100,
}
[Flags]
public enum HOTKEYF : byte
{
/// SHIFT key
HOTKEYF_SHIFT = 0x01,
/// CTRL key
HOTKEYF_CONTROL = 0x02,
/// ALT key
HOTKEYF_ALT = 0x04,
/// Extended key
HOTKEYF_EXT = 0x08,
}
/// The desired metric.
public enum LI_METRIC
{
/// Corresponds to SM_CXSMICON, the recommended pixel width of a small icon.
LIM_SMALL,
/// Corresponds toSM_CXICON, the default pixel width of an icon.
LIM_LARGE,
}
///
/// Posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time. This function calls
/// TrackMouseEvent if it exists, otherwise it emulates it.
///
///
/// Type: LPTRACKMOUSEEVENT
/// A pointer to a TRACKMOUSEEVENT structure that contains tracking information.
///
///
/// Type: BOOL
/// If the function succeeds, the return value is nonzero .
/// If the function fails, return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI TrackMouseEvent( _Inout_ LPTRACKMOUSEEVENT lpEventTrack); https://msdn.microsoft.com/en-us/library/windows/desktop/ms646266(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("CommCtrl.h", MSDNShortId = "ms646266")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool _TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
///
/// Calls the next handler in a window's subclass chain. The last handler in the subclass chain calls the original window procedure
/// for the window.
///
///
/// Type: HWND
/// A handle to the window being subclassed.
///
///
/// Type: UINT
/// A value of type unsigned int that specifies a window message.
///
///
/// Type: WPARAM
/// Specifies additional message information. The contents of this parameter depend on the value of the window message.
///
///
/// Type: LPARAM
///
/// Specifies additional message information. The contents of this parameter depend on the value of the window message. Note: On
/// 64-bit versions of Windows LPARAM is a 64-bit value.
///
///
///
/// Type: LRESULT
/// The returned value is specific to the message sent. This value should be ignored.
///
// LRESULT DefSubclassProc( _In_ HWND hWnd, _In_ UINT uMsg, _In_ WPARAM WPARAM, _In_ LPARAM LPARAM); https://msdn.microsoft.com/en-us/library/windows/desktop/bb776403(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb776403")]
public static extern IntPtr DefSubclassProc(HWND hWnd, uint uMsg, IntPtr WPARAM, IntPtr LPARAM);
/// Draws text that has a shadow.
///
/// Type: HDC
/// HDC.
///
///
/// Type: LPCWSTR
/// A pointer to a string that contains the text to be drawn.
///
///
/// Type: UINT
/// A UINT that specifies the number of characters in the string that is to be drawn.
///
///
/// Type: const RECT*
/// A pointer to a RECT structure that contains, in logical coordinates, the rectangle in which the text is to be drawn.
///
///
/// Type: DWORD
/// A DWORD that specifies how the text is to be drawn. See Format Values for possible parameter values.
///
///
/// Type: COLORREF
/// A COLORREF structure that contains the color of the text.
///
///
/// Type: COLORREF
/// A COLORREF structure that contains the color of the text shadow.
///
///
/// Type: int
/// A value of type int that specifies the x-coordinate of where the text should begin.
///
///
/// Type: int
/// A value of type int that specifies the y-coordinate of where the text should begin.
///
///
/// Type: int
/// Returns the height of the text in logical units if the function succeeds, otherwise returns zero.
///
// int DrawShadowText( HDC hdc, LPCWSTR pszText, UINT cch, const RECT *pRect, DWORD dwFlags, COLORREF crText, COLORREF crShadow, int
// ixOffset, int iyOffset); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775639(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775639")]
public static extern int DrawShadowText(HDC hdc, string pszText, uint cch, in RECT pRect, uint dwFlags, COLORREF crText, COLORREF crShadow, int ixOffset, int iyOffset);
/// Calculates the dimensions of a rectangle in the client area that contains all the specified controls.
///
/// Type: HWND
/// A handle to the window that has the client area to check.
///
///
/// Type: LPRECT
/// A pointer to a RECT structure that receives the dimensions of the rectangle.
///
///
/// Type: const INT*
///
/// A pointer to a null-terminated array of integers that identify controls in the client area. Each control requires a pair of
/// consecutive elements. The first element of the pair must be nonzero and the second element of the pair must be the control
/// identifier. The first pair represents the menu and is ignored. The last element must be zero to identify the end of the array.
///
///
/// No return value.
// void GetEffectiveClientRect( HWND hWnd, LPRECT lprc, _In_ const INT *lpInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775674(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775674")]
public static extern void GetEffectiveClientRect(HWND hWnd, out RECT lprc, IntPtr lpInfo);
/// Calculates the dimensions of a rectangle in the client area that contains all the specified controls.
/// A handle to the window that has the client area to check.
/// An array of integers that identify the control identifiers in the client area.
/// The dimensions of the rectangle.
// void GetEffectiveClientRect( HWND hWnd, LPRECT lprc, _In_ const INT *lpInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775674(v=vs.85).aspx
[PInvokeData("Commctrl.h", MSDNShortId = "bb775674")]
public static RECT GetEffectiveClientRect(HWND hWnd, int[] controlIdentifiers)
{
var lpInfo = new int[(controlIdentifiers.Length + 2) * 2];
for (var i = 0; i < controlIdentifiers.Length; i++)
{
lpInfo[(i + 1) * 2] = 1;
lpInfo[((i + 1) * 2) + 1] = controlIdentifiers[i];
}
var ptr = InteropServices.SafeCoTaskMemHandle.CreateFromList(lpInfo);
GetEffectiveClientRect(hWnd, out var rect, (IntPtr)ptr);
return rect;
}
/// Gets the language currently in use by the common controls for a particular process.
///
/// Type: LANGID
///
/// Returns the language identifier of the language an application has specified for the common controls by calling
/// InitMUILanguage. GetMUILanguage returns the value for the process from which it is called. If
/// InitMUILanguage has not been called or was not called from the same process, GetMUILanguage returns the
/// language-neutral LANGID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL).
///
///
// LANGID GetMUILanguage(void); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775676(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775676")]
public static extern ushort GetMUILanguage();
/// Retrieves the reference data for the specified window subclass callback.
///
/// Type: HWND
/// The handle of the window being subclassed.
///
///
/// Type: SUBCLASSPROC
/// A pointer to a window procedure. This pointer and the subclass ID uniquely identify this subclass callback.
///
///
/// Type: UINT_PTR
///
/// UINT_PTR subclass ID. This ID and the callback pointer uniquely identify this subclass callback. Note: On 64-bit versions
/// of Windows this is a 64-bit value.
///
///
///
/// Type: DWORD_PTR*
///
/// A pointer to a DWORD which will return the reference data. Note: On 64-bit versions of Windows, pointers are 64-bit values.
///
///
///
/// Type: BOOL
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The subclass callback was successfully installed.
///
/// -
/// FALSE
/// The subclass callback was not installed.
///
///
///
///
// BOOL GetWindowSubclass( _In_ HWND hWnd, _In_ SUBCLASSPROC pfnSubclass, _In_ UINT_PTR uIdSubclass, _Out_ DWORD_PTR *pdwRefData); https://msdn.microsoft.com/en-us/library/windows/desktop/bb776430(v=vs.85).aspx
[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);
///
/// Ensures that the common control DLL (Comctl32.dll) is loaded, and registers specific common control classes from the DLL. An
/// application must call this function before creating a common control.
///
///
/// A pointer to an INITCOMMONCONTROLSEX structure that contains information specifying which control classes will be registered.
///
/// Returns TRUE if successful, or FALSE otherwise.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775697")]
[DllImport(Lib.ComCtl32, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InitCommonControlsEx(in INITCOMMONCONTROLSEX icc);
///
/// Ensures that the common control DLL (Comctl32.dll) is loaded, and registers specific common control classes from the DLL. An
/// application must call this function before creating a common control.
///
/// The value to assign to the dwICC field in .
/// Returns TRUE if successful, or FALSE otherwise.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775697")]
public static bool InitCommonControlsEx(CommonControlClass ccc) => InitCommonControlsEx(new INITCOMMONCONTROLSEX(ccc));
///
/// Enables an application to specify a language to be used with the common controls that is different from the system language.
///
///
/// Type: LANGID
/// The language identifier of the language to be used by the common controls.
///
/// None
// VOID InitMUILanguage( LANGID uiLang); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775699(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775699")]
public static extern void InitMUILanguage(ushort uiLang);
/// Loads a specified icon resource with a client-specified system metric.
///
/// Type: HINSTANCE
///
/// 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.
///
/// To load a predefined icon or a standalone icon file, set this parameter to NULL.
///
///
/// Type: PCWSTR
///
/// A pointer to a null-terminated, Unicode buffer that contains location information about the icon to load. It is interpreted as follows:
///
/// If hinst is NULL, pszName can specify one of two things.
/// If hinst is non-null, pszName can specify one of two things.
///
///
/// Type: int
/// The desired metric. One of the following values:
///
///
///
/// Value
/// Meaning
///
/// -
/// LIM_SMALL
/// Corresponds to SM_CXSMICON, the recommended pixel width of a small icon.
///
/// -
/// LIM_LARGE
/// Corresponds toSM_CXICON, the default pixel width of an icon.
///
///
///
///
///
/// Type: HICON*
/// When this function returns, contains a pointer to the handle of the loaded icon.
///
///
/// Type: HRESULT
/// Returns S_OK if successful, otherwise an error, including the following value.
///
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// The contents of the buffer pointed to by pszName do not fit any of the expected interpretations.
///
///
///
///
// 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
[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);
///
/// 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.
///
///
/// Type: HINSTANCE
///
/// 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.
///
/// To load a predefined icon or a standalone icon file, set this parameter to NULL.
///
///
/// Type: PCWSTR
/// A pointer to a null-terminated, Unicode buffer that contains location information about the icon to load.
///
/// If hinst is non- NULL, pszName specifies the icon resource either by name or ordinal. This ordinal must be packaged by
/// using the MAKEINTRESOURCE macro.
///
///
/// If hinst is NULL, pszName specifies either the name of a standalone icon (.ico) file or the identifier of a predefined
/// icon to load. The following identifiers are recognized. To pass these constants to the LoadIconWithScaleDown function, use
/// the MAKEINTRESOURCE macro. For example, to load the IDI_ERROR icon, pass as the pszName parameter and NULL as the
/// hinst parameter.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// IDI_APPLICATION
/// Default application icon.
///
/// -
/// IDI_ASTERISK
/// Same as IDI_INFORMATION.
///
/// -
/// IDI_ERROR
/// Hand-shaped icon.
///
/// -
/// IDI_EXCLAMATION
/// Same as IDI_WARNING.
///
/// -
/// IDI_HAND
/// Same as IDI_ERROR.
///
/// -
/// IDI_INFORMATION
/// Asterisk icon.
///
/// -
/// IDI_QUESTION
/// Question mark icon.
///
/// -
/// IDI_WARNING
/// Exclamation point icon.
///
/// -
/// IDI_WINLOGO
/// Windows logo icon.
///
/// -
/// IDI_SHIELD
/// Security Shield icon.
///
///
///
///
///
/// Type: int
/// The desired width, in pixels, of the icon.
///
///
/// Type: int
/// The desired height, in pixels, of the icon.
///
///
/// Type: HICON*
/// When this function returns, contains a pointer to the handle of the loaded icon.
///
///
/// Type: HRESULT
/// Returns S_OK if successful, or an error value otherwise, including the following:
///
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// The contents of the buffer pointed to by pszName do not fit any of the expected interpretations.
///
///
///
///
// 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);
/// Removes a subclass callback from a window.
///
/// Type: HWND
/// The handle of the window being subclassed.
///
///
/// Type: SUBCLASSPROC
///
/// A pointer to a window procedure. This pointer and the subclass ID uniquely identify this subclass callback. For the callback
/// function prototype, see SUBCLASSPROC.
///
///
///
/// Type: UINT_PTR
///
/// The UINT_PTR subclass ID. This ID and the callback pointer uniquely identify this subclass callback. Note: On 64-bit
/// versions of Windows this is a 64-bit value.
///
///
///
/// Type: BOOL
/// TRUE if the subclass callback was successfully removed; otherwise, FALSE.
///
// BOOL RemoveWindowSubclass( _In_ HWND hWnd, _In_ SUBCLASSPROC pfnSubclass, _In_ UINT_PTR uIdSubclass); https://msdn.microsoft.com/en-us/library/windows/desktop/bb762094(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb762094")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RemoveWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, [MarshalAs(UnmanagedType.SysUInt)] uint uIdSubclass);
/// Installs or updates a window subclass callback.
///
/// Type: HWND
/// The handle of the window being subclassed.
///
///
/// Type: SUBCLASSPROC
///
/// A pointer to a window procedure. This pointer and the subclass ID uniquely identify this subclass callback. For the callback
/// function prototype, see SUBCLASSPROC.
///
///
///
/// Type: UINT_PTR
///
/// The subclass ID. This ID together with the subclass procedure uniquely identify a subclass. To remove a subclass, pass the
/// subclass procedure and this value to the RemoveWindowSubclass function. This value is passed to the subclass procedure in
/// the uIdSubclass parameter.
///
///
///
/// Type: DWORD_PTR
///
/// DWORD_PTR to reference data. The meaning of this value is determined by the calling application. This value is passed to
/// the subclass procedure in the dwRefData parameter. A different dwRefData is associated with each combination of window handle,
/// subclass procedure and uIdSubclass.
///
///
///
/// Type: BOOL
/// TRUE if the subclass callback was successfully installed; otherwise, FALSE.
///
// BOOL SetWindowSubclass( _In_ HWND hWnd, _In_ SUBCLASSPROC pfnSubclass, _In_ UINT_PTR uIdSubclass, _In_ DWORD_PTR dwRefData); https://msdn.microsoft.com/en-us/library/windows/desktop/bb762102(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb762102")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowSubclass(HWND hWnd, SUBCLASSPROC pfnSubclass, [MarshalAs(UnmanagedType.SysUInt)] uint uIdSubclass, IntPtr dwRefData);
///
///
/// [ ShowHideMenuCtl is available for use in the operating systems specified in the Requirements section. It may be altered
/// or unavailable in subsequent versions.]
///
///
/// Sets or removes the specified menu item's check mark attribute and shows or hides the corresponding control. The function adds a
/// check mark to the specified menu item if it does not have one and then displays the corresponding control. If the menu item
/// already has a check mark, the function removes the check mark and hides the corresponding control.
///
///
///
/// Type: HWND
/// A handle to the window that contains the menu and controls.
///
///
/// Type: UINT_PTR
/// The identifier of the menu item to receive or lose a check mark.
///
///
/// Type: LPINT
///
/// A pointer to an array that contains pairs of values. The second value in the first pair must be the handle to the application's
/// main menu. Each subsequent pair consists of a menu item identifier and a control window identifier. The function searches the
/// array for a value that matches uFlags and, if the value is found, checks or unchecks the menu item and shows or hides the
/// corresponding control.
///
///
///
/// Type: BOOL
/// Returns nonzero if successful, or zero otherwise.
///
// BOOL ShowHideMenuCtl( HWND hWnd, UINT_PTR uFlags, LPINT lpInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/bb775731(v=vs.85).aspx
[DllImport(Lib.ComCtl32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Commctrl.h", MSDNShortId = "bb775731")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowHideMenuCtl(HWND hWnd, [MarshalAs(UnmanagedType.SysUInt)] uint uFlags, [In, MarshalAs(UnmanagedType.LPArray)] int[] lpInfo);
/// Contains information for the drawing of buttons in a toolbar or rebar.
[StructLayout(LayoutKind.Sequential)]
public struct COLORSCHEME
{
/// The size of this structure, in bytes.
public uint dwSize;
///
/// The COLORREF value that represents the highlight color of the buttons. Use CLR_DEFAULT for the default highlight color.
///
public COLORREF clrBtnHighlight;
/// The COLORREF value that represents the shadow color of the buttons. Use CLR_DEFAULT for the default shadow color.
public COLORREF clrBtnShadow;
}
///
/// Carries information used to load common control classes from the dynamic-link library (DLL). This structure is used with the
/// function.
///
[PInvokeData("Commctrl.h", MSDNShortId = "bb775507")]
[StructLayout(LayoutKind.Sequential)]
public struct INITCOMMONCONTROLSEX
{
/// The size of the structure, in bytes.
public int dwSize;
///
/// The set of bit flags that indicate which common control classes will be loaded from the DLL when calling
/// .
///
public CommonControlClass dwICC;
/// Initializes a new instance of the class and sets the dwICC field.
/// The value to assign to the dwICC field.
public INITCOMMONCONTROLSEX(CommonControlClass ccc)
{
dwICC = ccc;
dwSize = Marshal.SizeOf(typeof(INITCOMMONCONTROLSEX));
}
}
/// Contains information used with character notification messages.
// 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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: UINT
/// The character that is being processed.
///
public uint ch;
///
/// Type: DWORD
/// A 32-bit value that is determined by the control that is sending the notification.
///
public uint dwItemPrev;
///
/// Type: DWORD
/// A 32-bit value that is determined by the control that is sending the notification.
///
public uint dwItemNext;
}
/// Contains information specific to an NM_CUSTOMDRAW notification code.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775483")]
[StructLayout(LayoutKind.Sequential)]
public struct NMCUSTOMDRAW
{
/// An NMHDR structure that contains information about this notification code.
public NMHDR hdr;
/// The current drawing stage.
public CustomDrawStage dwDrawStage;
/// A handle to the control's device context. Use this HDC to perform any GDI functions.
public HDC hdc;
///
/// The RECT structure that describes the bounding rectangle of the area being drawn. This member is initialized only by the
/// CDDS_ITEMPREPAINT notification. Version 5.80. This member is also initialized by the CDDS_PREPAINT notification.
///
public RECT rc;
///
/// The item number. What is contained in this member will depend on the type of control that is sending the notification. See
/// the NM_CUSTOMDRAW notification reference for the specific control to determine what, if anything, is contained in this member.
///
public IntPtr dwItemSpec;
/// The current item state.
public CustomDrawItemState uItemState;
/// Application-defined item data.
public IntPtr lItemlParam;
}
/// Contains information about the two rectangles of a split button. Sent with the NM_GETCUSTOMSPLITRECT notification.
[PInvokeData("Commctrl.h", MSDNShortId = "bb775510")]
[StructLayout(LayoutKind.Sequential)]
public struct NMCUSTOMSPLITRECTINFO
{
/// An NMHDR structure that contains information about the notification.
public NMHDR hdr;
/// A RECT structure that describes the client area the button occupies.
public RECT rcClient;
/// A RECT structure that describes the rectangle that does not contain the drop-down arrow.
public RECT rcButton;
/// A RECT structure that describes the rectangle that contains the drop-down arrow.
public RECT rcSplit;
}
/// Contains information used with custom text notification.
// typedef struct tagNMCUSTOMTEXT { NMHDR hdr; HDC hDC; LPCWSTR lpString; int nCount; LPRECT lpRect; UINT uFormat; BOOL fLink;} NMCUSTOMTEXT,
// *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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: HDC
/// The device context to draw to.
///
public HDC hDC;
///
/// Type: LPCWSTR
/// The string to draw.
///
public string lpString;
///
/// Type: int
/// Length of lpString.
///
public int nCount;
///
/// Type: LPRECT
/// The rect to draw in.
///
public IntPtr lpRect;
///
/// Type: UINT
///
/// One or more of the DT_* flags. For more information, see the description of the uFormat parameter of the DrawText
/// function. This may be NULL.
///
///
public uint uFormat;
///
/// Type: BOOL
/// Whether the text is a link.
///
[MarshalAs(UnmanagedType.Bool)]
public bool fLink;
}
/// Contains information used with key notification messages.
// 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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: UINT
/// A virtual key code of the key that caused the event.
///
public uint nVKey;
///
/// Type: UINT
///
/// Flags associated with the key. These are the same flags that are passed in the high word of the lParam parameter of the
/// WM_KEYDOWN message.
///
///
public uint uFlags;
}
/// Contains information used with mouse notification messages.
// typedef struct tagNMMOUSE { NMHDR hdr; DWORD_PTR dwItemSpec; DWORD_PTR dwItemData; POINT pt; LPARAM dwHitInfo;} NMMOUSE,
// *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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: DWORD_PTR
/// A control-specific item identifier.
///
public IntPtr dwItemSpec;
///
/// Type: DWORD_PTR
/// A control-specific item data.
///
public IntPtr dwItemData;
///
/// Type: POINT
/// A POINT structure that contains the client coordinates of the mouse when the click occurred.
///
public System.Drawing.Point pt;
///
/// Type: LPARAM
/// Carries information about where on the item or control the cursor is pointing.
///
public IntPtr dwHitInfo;
}
/// Contains information used with the TBN_GETOBJECT, TCN_GETOBJECT, and PSN_GETOBJECT notification codes.
// typedef struct tagNMOBJECTNOTIFY { NMHDR hdr; int iItem; IID *piid; IUnknown *pObject; HRESULT hResult;} NMOBJECTNOTIFY,
// *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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: int
///
/// A control-specific item identifier. This value will comply to item identification standards for the control sending the
/// notification. However, this member is not used with the PSN_GETOBJECT notification code.
///
///
public int iItem;
///
/// Type: IID*
/// A pointer to an interface identifier of the requested object.
///
public IntPtr piid;
///
/// Type: IUnknown*
///
/// A pointer to an object provided by the window processing the notification code. The application processing the notification
/// code sets this member.
///
///
public IntPtr pObject;
///
/// Type: HRESULT
/// COM success or failure flags. The application processing the notification code sets this member.
///
public HRESULT hResult;
/// Undocumented
public uint dwFlags;
}
/// Contains information used with NM_TOOLTIPSCREATED notification codes.
// 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
{
///
/// Type: NMHDR
/// An NMHDR structure that contains additional information about this notification.
///
public NMHDR hdr;
///
/// Type: HWND
/// The window handle to the tooltip control created.
///
public HWND hwndToolTips;
}
}
}