From 1241963a8bc1f6349fe8506425ff2e1369df2df4 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 27 Dec 2017 11:01:03 -0700 Subject: [PATCH] Completion of UxTheme.dll methods and corrections --- PInvoke/Gdi32/WinGdi.TEXTMETRIC.cs | 108 ++ PInvoke/User32.Gdi/WinUser.Gdi.cs | 142 ++- PInvoke/UxTheme/UXTHEME.cs | 1345 ++++++++++++++++---- PInvoke/UxTheme/UXTHEME_GDI.cs | 4 +- WIndows.Forms/Drawing/BufferedPaint.cs | 2 +- .../Extensions/VisualStylesRendererExtension.cs | 25 +- .../Extensions/VisualStylesRendererExtensionGDI.cs | 6 +- WIndows.Forms/VisualTheme.cs | 83 +- 8 files changed, 1384 insertions(+), 331 deletions(-) create mode 100644 PInvoke/Gdi32/WinGdi.TEXTMETRIC.cs diff --git a/PInvoke/Gdi32/WinGdi.TEXTMETRIC.cs b/PInvoke/Gdi32/WinGdi.TEXTMETRIC.cs new file mode 100644 index 00000000..58e045f1 --- /dev/null +++ b/PInvoke/Gdi32/WinGdi.TEXTMETRIC.cs @@ -0,0 +1,108 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +// ReSharper disable InconsistentNaming + +namespace Vanara.PInvoke +{ + public static partial class Gdi32 + { + [Flags] + public enum TMPF : byte + { + TMPF_FIXED_PITCH = 0x01, + TMPF_VECTOR = 0x02, + TMPF_TRUETYPE = 0x04, + TMPF_DEVICE = 0x08 + } + + public enum TMCHARSET : byte + { + /// The ANSI CHARSET + ANSI_CHARSET = 0, + + /// The DEFAULT CHARSET + DEFAULT_CHARSET = 1, + + /// The SYMBOL CHARSET + SYMBOL_CHARSET = 2, + + /// The SHIFTJIS_ CHARSET + SHIFTJIS_CHARSET = 128, + + /// The HANGEUL CHARSET + HANGEUL_CHARSET = 129, + + /// The HANGUL CHARSET + HANGUL_CHARSET = 129, + + /// The G B2312 CHARSET + GB2312_CHARSET = 134, + + /// The CHINESEBIG5 CHARSET + CHINESEBIG5_CHARSET = 136, + + /// The OEM CHARSET + OEM_CHARSET = 255, + + /// The JOHAB_CHARSET + JOHAB_CHARSET = 130, + + /// The HEBREW_CHARSET + HEBREW_CHARSET = 177, + + /// The ARABIC_CHARSET + ARABIC_CHARSET = 178, + + /// The GREEK_CHARSET + GREEK_CHARSET = 161, + + /// The TURKISH_CHARSET + TURKISH_CHARSET = 162, + + /// The VIETNAMESE_CHARSET + VIETNAMESE_CHARSET = 163, + + /// The THAI_CHARSET + THAI_CHARSET = 222, + + /// The EASTEUROPE_CHARSET + EASTEUROPE_CHARSET = 238, + + /// The RUSSIAN_CHARSET + RUSSIAN_CHARSET = 204, + + /// The MAC_CHARSET + MAC_CHARSET = 77, + + /// The BALTIC_CHARSET + BALTIC_CHARSET = 186, + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct TEXTMETRIC + { + public int tmHeight; + public int tmAscent; + public int tmDescent; + public int tmInternalLeading; + public int tmExternalLeading; + public int tmAveCharWidth; + public int tmMaxCharWidth; + public int tmWeight; + public int tmOverhang; + public int tmDigitizedAspectX; + public int tmDigitizedAspectY; + public char tmFirstChar; + public char tmLastChar; + public char tmDefaultChar; + public char tmBreakChar; + public byte tmItalic; + public byte tmUnderlined; + public byte tmStruckOut; + public TMPF tmPitchAndFamily; + public TMCHARSET tmCharSet; + } + } +} \ No newline at end of file diff --git a/PInvoke/User32.Gdi/WinUser.Gdi.cs b/PInvoke/User32.Gdi/WinUser.Gdi.cs index 7cf9725a..2363260d 100644 --- a/PInvoke/User32.Gdi/WinUser.Gdi.cs +++ b/PInvoke/User32.Gdi/WinUser.Gdi.cs @@ -21,25 +21,25 @@ namespace Vanara.PInvoke [Flags] public enum BorderFlags : uint { - BF_LEFT = 0x0001, - BF_TOP = 0x0002, - BF_RIGHT = 0x0004, - BF_BOTTOM = 0x0008, - BF_TOPLEFT = (BF_TOP | BF_LEFT), - BF_TOPRIGHT = (BF_TOP | BF_RIGHT), - BF_BOTTOMLEFT = (BF_BOTTOM | BF_LEFT), + BF_LEFT = 0x0001, + BF_TOP = 0x0002, + BF_RIGHT = 0x0004, + BF_BOTTOM = 0x0008, + BF_TOPLEFT = (BF_TOP | BF_LEFT), + BF_TOPRIGHT = (BF_TOP | BF_RIGHT), + BF_BOTTOMLEFT = (BF_BOTTOM | BF_LEFT), BF_BOTTOMRIGHT = (BF_BOTTOM | BF_RIGHT), - BF_RECT = (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM), - BF_DIAGONAL = 0x0010, - BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL | BF_TOP | BF_RIGHT), - BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL | BF_TOP | BF_LEFT), - BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL | BF_BOTTOM | BF_LEFT), + BF_RECT = (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM), + BF_DIAGONAL = 0x0010, + BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL | BF_TOP | BF_RIGHT), + BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL | BF_TOP | BF_LEFT), + BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL | BF_BOTTOM | BF_LEFT), BF_DIAGONAL_ENDBOTTOMRIGHT = (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT), - BF_MIDDLE = 0x0800, - BF_SOFT = 0x1000, - BF_ADJUST = 0x2000, - BF_FLAT = 0x4000, - BF_MONO = 0x8000, + BF_MIDDLE = 0x0800, + BF_SOFT = 0x1000, + BF_ADJUST = 0x2000, + BF_FLAT = 0x4000, + BF_MONO = 0x8000, } [PInvokeData("WinUser.h")] @@ -50,14 +50,14 @@ namespace Vanara.PInvoke BDR_SUNKENOUTER = 0x0002, BDR_RAISEDINNER = 0x0004, BDR_SUNKENINNER = 0x0008, - BDR_OUTER = (BDR_RAISEDOUTER | BDR_SUNKENOUTER), - BDR_INNER = (BDR_RAISEDINNER | BDR_SUNKENINNER), - BDR_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), - BDR_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), - EDGE_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), - EDGE_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), - EDGE_ETCHED = (BDR_SUNKENOUTER | BDR_RAISEDINNER), - EDGE_BUMP = (BDR_RAISEDOUTER | BDR_SUNKENINNER), + BDR_OUTER = (BDR_RAISEDOUTER | BDR_SUNKENOUTER), + BDR_INNER = (BDR_RAISEDINNER | BDR_SUNKENINNER), + BDR_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), + BDR_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), + EDGE_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), + EDGE_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), + EDGE_ETCHED = (BDR_SUNKENOUTER | BDR_RAISEDINNER), + EDGE_BUMP = (BDR_RAISEDOUTER | BDR_SUNKENINNER), } /// @@ -263,6 +263,83 @@ namespace Vanara.PInvoke SWP_SHOWWINDOW = 0x0040, } + /// Color index used to get a system color from . + public enum SystemColorIndex + { + /// Scroll bar gray area. + COLOR_SCROLLBAR = 0, + /// Desktop. + COLOR_BACKGROUND = 1, + /// Active window title bar. The associated foreground color is COLOR_CAPTIONTEXT. Specifies the left side color in the color gradient of an active window's title bar if the gradient effect is enabled. + COLOR_ACTIVECAPTION = 2, + /// Inactive window caption. The associated foreground color is COLOR_INACTIVECAPTIONTEXT. Specifies the left side color in the color gradient of an inactive window's title bar if the gradient effect is enabled. + COLOR_INACTIVECAPTION = 3, + /// Menu background. The associated foreground color is COLOR_MENUTEXT. + COLOR_MENU = 4, + /// Window background. The associated foreground colors are COLOR_WINDOWTEXT and COLOR_HOTLITE. + COLOR_WINDOW = 5, + /// Window frame. + COLOR_WINDOWFRAME = 6, + /// Text in menus. The associated background color is COLOR_MENU. + COLOR_MENUTEXT = 7, + /// Text in windows. The associated background color is COLOR_WINDOW. + COLOR_WINDOWTEXT = 8, + /// Text in caption, size box, and scroll bar arrow box. The associated background color is COLOR_ACTIVECAPTION. + COLOR_CAPTIONTEXT = 9, + /// Active window border. + COLOR_ACTIVEBORDER = 10, + /// Inactive window border. + COLOR_INACTIVEBORDER = 11, + /// Background color of multiple document interface (MDI) applications. + COLOR_APPWORKSPACE = 12, + /// Item(s) selected in a control. The associated foreground color is COLOR_HIGHLIGHTTEXT. + COLOR_HIGHLIGHT = 13, + /// Text of item(s) selected in a control. The associated background color is COLOR_HIGHLIGHT. + COLOR_HIGHLIGHTTEXT = 14, + /// Face color for three-dimensional display elements and for dialog box backgrounds. The associated foreground color is COLOR_BTNTEXT. + COLOR_BTNFACE = 15, + /// Shadow color for three-dimensional display elements (for edges facing away from the light source). + COLOR_BTNSHADOW = 16, + /// Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color. + COLOR_GRAYTEXT = 17, + /// Text on push buttons. The associated background color is COLOR_BTNFACE. + COLOR_BTNTEXT = 18, + /// Inactive window caption. The associated foreground color is COLOR_INACTIVECAPTIONTEXT. Specifies the left side color in the color gradient of an inactive window's title bar if the gradient effect is enabled. + COLOR_INACTIVECAPTIONTEXT = 19, + /// Highlight color for three-dimensional display elements (for edges facing the light source.) + COLOR_BTNHIGHLIGHT = 20, + /// Dark shadow for three-dimensional display elements. + COLOR_3DDKSHADOW = 21, + /// Light color for three-dimensional display elements (for edges facing the light source.) + COLOR_3DLIGHT = 22, + /// Text color for tooltip controls. The associated background color is COLOR_INFOBK. + COLOR_INFOTEXT = 23, + /// Background color for tooltip controls. The associated foreground color is COLOR_INFOTEXT. + COLOR_INFOBK = 24, + /// Item(s) selected in a control. The associated foreground color is COLOR_HIGHLIGHTTEXT. + COLOR_HOTLIGHT = 26, + /// Right side color in the color gradient of an active window's title bar. COLOR_ACTIVECAPTION specifies the left side color. Use SPI_GETGRADIENTCAPTIONS with the SystemParametersInfo function to determine whether the gradient effect is enabled. + COLOR_GRADIENTACTIVECAPTION = 27, + /// Right side color in the color gradient of an inactive window's title bar. COLOR_INACTIVECAPTION specifies the left side color. + COLOR_GRADIENTINACTIVECAPTION = 28, + /// The color used to highlight menu items when the menu appears as a flat menu (see SystemParametersInfo). The highlighted menu item is outlined with COLOR_HIGHLIGHT. Windows 2000: This value is not supported. + COLOR_MENUHILIGHT = 29, + /// The background color for the menu bar when menus appear as flat menus (see SystemParametersInfo). However, COLOR_MENU continues to specify the background color of the menu popup. Windows 2000: This value is not supported. + COLOR_MENUBAR = 30, + /// Desktop. + COLOR_DESKTOP = COLOR_BACKGROUND, + /// Face color for three-dimensional display elements and for dialog box backgrounds. + COLOR_3DFACE = COLOR_BTNFACE, + /// Shadow color for three-dimensional display elements (for edges facing away from the light source). + COLOR_3DSHADOW = COLOR_BTNSHADOW, + /// Highlight color for three-dimensional display elements (for edges facing the light source.) + COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT, + /// Highlight color for three-dimensional display elements (for edges facing the light source.) + COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT, + /// Highlight color for three-dimensional display elements (for edges facing the light source.) + COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT, + } + /// Flags used for and methods to retrieve information about a window. [Flags] public enum WindowLongFlags @@ -334,6 +411,21 @@ namespace Vanara.PInvoke [System.Security.SecurityCritical] public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref RECT lpRect); + /// Retrieves the current color of the specified display element. Display elements are the parts of a window and the display that appear on the system display screen. + /// The display element whose color is to be retrieved. + /// The function returns the red, green, blue (RGB) color value of the given element. + /// If the nIndex parameter is out of range, the return value is zero.Because zero is also a valid RGB value, you cannot use GetSysColor to determine whether a system color is supported by the current platform.Instead, use the GetSysColorBrush function, which returns NULL if the color is not supported. + [PInvokeData("WinUser.h", MSDNShortId = "ms724371")] + [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] + public static extern COLORREF GetSysColor(SystemColorIndex nIndex); + + /// The GetSysColorBrush function retrieves a handle identifying a logical brush that corresponds to the specified color index. + /// A color index. This value corresponds to the color used to paint one of the window elements. See GetSysColor for system color index values. + /// he return value identifies a logical brush if the nIndex parameter is supported by the current platform. Otherwise, it returns NULL. + [PInvokeData("WinUser.h", MSDNShortId = "dd144927")] + [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] + public static extern IntPtr GetSysColorBrush(SystemColorIndex nIndex); + /// /// Retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. /// diff --git a/PInvoke/UxTheme/UXTHEME.cs b/PInvoke/UxTheme/UXTHEME.cs index 006e4f87..6f609447 100644 --- a/PInvoke/UxTheme/UXTHEME.cs +++ b/PInvoke/UxTheme/UXTHEME.cs @@ -1,15 +1,12 @@ using System; -using System.ComponentModel; using System.Drawing; using System.Runtime.InteropServices; using System.Text; -using Microsoft.Win32.SafeHandles; +using Vanara.Extensions; using static Vanara.PInvoke.Gdi32; using static Vanara.PInvoke.User32_Gdi; -// ReSharper disable FieldCanBeMadeReadOnly.Global -// ReSharper disable InconsistentNaming -// ReSharper disable FieldCanBeMadeReadOnly.Local +// ReSharper disable FieldCanBeMadeReadOnly.Global ReSharper disable InconsistentNaming ReSharper disable FieldCanBeMadeReadOnly.Local namespace Vanara.PInvoke { @@ -18,6 +15,33 @@ namespace Vanara.PInvoke [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)] public delegate int DrawThemeTextCallback(SafeDCHandle hdc, string text, int textLen, ref RECT rc, int flags, IntPtr lParam); + [Flags] + public enum DrawThemeBackgroundFlags + { + None = 0, + + /// The ClipRectangle value is defined. + DTBG_CLIPRECT = 1, + + /// Deprecated. Draw transparent and alpha images as solid. + DTBG_DRAWSOLID = 2, + + /// Do not draw the border of the part (currently this value is only supported for bgtype=borderfill). + DTBG_OMITBORDER = 4, + + /// Do not draw the content area of the part (currently this value is only supported for bgtype=borderfill). + DTBG_OMITCONTENT = 8, + + /// Deprecated. + DTBG_COMPUTINGREGION = 16, + + /// Assume the hdc is mirrored and flip images as appropriate (currently this value is only supported for bgtype=imagefile). + DTBG_MIRRORDC = 32, + + /// Do not mirror the output; even in right-to-left (RTL) layout. + DTBG_NOMIRROR = 64 + } + [Flags] public enum DrawThemeParentBackgroundFlags { @@ -38,20 +62,20 @@ namespace Vanara.PInvoke [Flags] public enum DrawThemeTextOptionsMasks { - TextColor = 1, - BorderColor = 2, - ShadowColor = 4, - ShadowType = 8, - ShadowOffset = 16, - BorderSize = 32, - FontProp = 64, - ColorProp = 128, - StateId = 256, - CalcRect = 512, - ApplyOverlay = 1024, - GlowSize = 2048, - Callback = 4096, - Composited = 8192 + DTT_TEXTCOLOR = 1, + DTT_BORDERCOLOR = 2, + DTT_SHADOWCOLOR = 4, + DTT_SHADOWTYPE = 8, + DTT_SHADOWOFFSET = 16, + DTT_BORDERSIZE = 32, + DTT_FONTPROP = 64, + DTT_COLORPROP = 128, + DTT_STATEID = 256, + DTT_CALCRECT = 512, + DTT_APPLYOVERLAY = 1024, + DTT_GLOWSIZE = 2048, + DTT_CALLBACK = 4096, + DTT_COMPOSITED = 8192 } public enum DrawThemeTextSystemFonts @@ -64,6 +88,21 @@ namespace Vanara.PInvoke IconTitle = 806 } + [Flags] + public enum HitTestOptions : uint + { + HTTB_BACKGROUNDSEG = 0x00000000, + HTTB_FIXEDBORDER = 0x00000002, + HTTB_CAPTION = 0x00000004, + HTTB_RESIZINGBORDER_LEFT = 0x00000010, + HTTB_RESIZINGBORDER_TOP = 0x00000020, + HTTB_RESIZINGBORDER_RIGHT = 0x00000040, + HTTB_RESIZINGBORDER_BOTTOM = 0x00000080, + HTTB_RESIZINGBORDER = (HTTB_RESIZINGBORDER_LEFT | HTTB_RESIZINGBORDER_TOP | HTTB_RESIZINGBORDER_RIGHT | HTTB_RESIZINGBORDER_BOTTOM), + HTTB_SIZINGTEMPLATE = 0x00000100, + HTTB_SYSTEMSIZINGMARGINS = 0x00000200, + } + public enum IntegerListProperty { TransitionDuration = 6000 @@ -74,12 +113,28 @@ namespace Vanara.PInvoke None = 0, /// Forces drawn images from this theme to stretch to fit the rectangles specified by drawing functions. - /// OTD_FORCE_RECT_SIZING - ForceRectSizing = 1, + OTD_FORCE_RECT_SIZING = 1, /// Allows theme elements to be drawn in the non-client area of the window. - /// OTD_NONCLIENT - NonClient = 2 + OTD_NONCLIENT = 2 + } + + public enum PROPERTYORIGIN + { + /// Property was found in the state section. + PO_STATE = 0, + + /// Property was found in the part section. + PO_PART = 1, + + /// Property was found in the class section. + PO_CLASS = 2, + + /// Property was found in the list of global variables. + PO_GLOBAL = 3, + + /// Property was not found. + PO_NOTFOUND = 4 } public enum TA_PROPERTY @@ -103,6 +158,31 @@ namespace Vanara.PInvoke TAPF_HASPERSPECTIVE = 0x10, } + public enum TA_TIMINGFUNCTION_TYPE + { + TTFT_UNDEFINED, + TTFT_CUBIC_BEZIER, + } + + [PInvokeData("UxTheme.h")] + [Flags] + public enum TA_TRANSFORM_FLAG + { + TATF_NONE = 0x0, + TATF_TARGETVALUES_USER = 0x1, + TATF_HASINITIALVALUES = 0x2, + TATF_HASORIGINVALUES = 0x4, + } + + [PInvokeData("UxTheme.h")] + public enum TA_TRANSFORM_TYPE + { + TATT_TRANSLATE_2D, + TATT_SCALE_2D, + TATT_OPACITY, + TATT_CLIP, + } + public enum TextShadowType { /// No shadow will be drawn. @@ -118,42 +198,824 @@ namespace Vanara.PInvoke Continuous = 2 } - public enum ThemePropertyOrigin + [Flags] + public enum ThemeAppProperties : uint { - /// Property was found in the state section. - /// PO_STATE - State = 0, + /// Specifies that the non-client areas of application windows have visual styles applied. + STAP_ALLOW_NONCLIENT = (1U << 0), - /// Property was found in the part section. - /// PO_PART - Part = 1, + /// Specifies that controls in application windows have visual styles applied. + STAP_ALLOW_CONTROLS = (1U << 1), - /// Property was found in the class section. - /// PO_CLASS - Class = 2, - - /// Property was found in the list of global variables. - /// PO_GLOBAL - Global = 3, - - /// Property was not found. - /// PO_NOTFOUND - NotFound = 4 + /// Specifies that all web content displayed in an application is rendered using visual styles. + STAP_ALLOW_WEBCONTENT = (1U << 2), } - public enum ThemeSize + public enum ThemeDialogTextureFlags + { + /// Disables background texturing. + ETDT_DISABLE = 0x00000001, + + /// Enables dialog window background texturing. The texturing is defined by a visual style. + ETDT_ENABLE = 0x00000002, + + /// Uses the Tab control texture for the background texture of a dialog window. + ETDT_USETABTEXTURE = 0x00000004, + + /// + /// Enables dialog window background texturing. The texture is the Tab control texture defined by the visual style. This flag is equivalent to + /// (ETDT_ENABLE | ETDT_USETABTEXTURE). + /// + ETDT_ENABLETAB = (ETDT_ENABLE | ETDT_USETABTEXTURE), + + /// Uses the Aero wizard texture for the background texture of a dialog window. + ETDT_USEAEROWIZARDTABTEXTURE = 0x00000008, + + /// ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE. + ETDT_ENABLEAEROWIZARDTAB = (ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE), + + /// ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE. + ETDT_VALIDBITS = (ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE), + } + + public enum ThemeProperty + { + /// + TMT_DIBDATA = 2, + + /// + TMT_GLYPHDIBDATA = 8, + + /// + TMT_ENUM = 200, + + /// + TMT_STRING = 201, + + /// + TMT_INT = 202, + + /// + TMT_BOOL = 203, + + /// + TMT_COLOR = 204, + + /// + TMT_MARGINS = 205, + + /// + TMT_FILENAME = 206, + + /// + TMT_SIZE = 207, + + /// + TMT_POSITION = 208, + + /// + TMT_RECT = 209, + + /// + TMT_FONT = 210, + + /// + TMT_INTLIST = 211, + + /// + TMT_HBITMAP = 212, + + /// + TMT_DISKSTREAM = 213, + + /// + TMT_STREAM = 214, + + /// + TMT_BITMAPREF = 215, + + /// + TMT_FLOAT = 216, + + /// + TMT_FLOATLIST = 217, + + /// + TMT_COLORSCHEMES = 401, + + /// + TMT_SIZES = 402, + + /// + TMT_CHARSET = 403, + + /// + TMT_NAME = 600, + + /// + TMT_DISPLAYNAME = 601, + + /// + TMT_TOOLTIP = 602, + + /// + TMT_COMPANY = 603, + + /// + TMT_AUTHOR = 604, + + /// + TMT_COPYRIGHT = 605, + + /// + TMT_URL = 606, + + /// + TMT_VERSION = 607, + + /// + TMT_DESCRIPTION = 608, + + /// + TMT_FIRST_RCSTRING_NAME = TMT_DISPLAYNAME, + + /// + TMT_LAST_RCSTRING_NAME = TMT_DESCRIPTION, + + /// + TMT_CAPTIONFONT = 801, + + /// + TMT_SMALLCAPTIONFONT = 802, + + /// + TMT_MENUFONT = 803, + + /// + TMT_STATUSFONT = 804, + + /// + TMT_MSGBOXFONT = 805, + + /// + TMT_ICONTITLEFONT = 806, + + /// + TMT_HEADING1FONT = 807, + + /// + TMT_HEADING2FONT = 808, + + /// + TMT_BODYFONT = 809, + + /// + TMT_FIRSTFONT = TMT_CAPTIONFONT, + + /// + TMT_LASTFONT = TMT_BODYFONT, + + /// + TMT_FLATMENUS = 1001, + + /// + TMT_FIRSTBOOL = TMT_FLATMENUS, + + /// + TMT_LASTBOOL = TMT_FLATMENUS, + + /// + TMT_SIZINGBORDERWIDTH = 1201, + + /// + TMT_SCROLLBARWIDTH = 1202, + + /// + TMT_SCROLLBARHEIGHT = 1203, + + /// + TMT_CAPTIONBARWIDTH = 1204, + + /// + TMT_CAPTIONBARHEIGHT = 1205, + + /// + TMT_SMCAPTIONBARWIDTH = 1206, + + /// + TMT_SMCAPTIONBARHEIGHT = 1207, + + /// + TMT_MENUBARWIDTH = 1208, + + /// + TMT_MENUBARHEIGHT = 1209, + + /// + TMT_PADDEDBORDERWIDTH = 1210, + + /// + TMT_FIRSTSIZE = TMT_SIZINGBORDERWIDTH, + + /// + TMT_LASTSIZE = TMT_PADDEDBORDERWIDTH, + + /// + TMT_MINCOLORDEPTH = 1301, + + /// + TMT_FIRSTINT = TMT_MINCOLORDEPTH, + + /// + TMT_LASTINT = TMT_MINCOLORDEPTH, + + /// + TMT_CSSNAME = 1401, + + /// + TMT_XMLNAME = 1402, + + /// + TMT_LASTUPDATED = 1403, + + /// + TMT_ALIAS = 1404, + + /// + TMT_FIRSTSTRING = TMT_CSSNAME, + + /// + TMT_LASTSTRING = TMT_ALIAS, + + /// + TMT_SCROLLBAR = 1601, + + /// + TMT_BACKGROUND = 1602, + + /// + TMT_ACTIVECAPTION = 1603, + + /// + TMT_INACTIVECAPTION = 1604, + + /// + TMT_MENU = 1605, + + /// + TMT_WINDOW = 1606, + + /// + TMT_WINDOWFRAME = 1607, + + /// + TMT_MENUTEXT = 1608, + + /// + TMT_WINDOWTEXT = 1609, + + /// + TMT_CAPTIONTEXT = 1610, + + /// + TMT_ACTIVEBORDER = 1611, + + /// + TMT_INACTIVEBORDER = 1612, + + /// + TMT_APPWORKSPACE = 1613, + + /// + TMT_HIGHLIGHT = 1614, + + /// + TMT_HIGHLIGHTTEXT = 1615, + + /// + TMT_BTNFACE = 1616, + + /// + TMT_BTNSHADOW = 1617, + + /// + TMT_GRAYTEXT = 1618, + + /// + TMT_BTNTEXT = 1619, + + /// + TMT_INACTIVECAPTIONTEXT = 1620, + + /// + TMT_BTNHIGHLIGHT = 1621, + + /// + TMT_DKSHADOW3D = 1622, + + /// + TMT_LIGHT3D = 1623, + + /// + TMT_INFOTEXT = 1624, + + /// + TMT_INFOBK = 1625, + + /// + TMT_BUTTONALTERNATEFACE = 1626, + + /// + TMT_HOTTRACKING = 1627, + + /// + TMT_GRADIENTACTIVECAPTION = 1628, + + /// + TMT_GRADIENTINACTIVECAPTION = 1629, + + /// + TMT_MENUHILIGHT = 1630, + + /// + TMT_MENUBAR = 1631, + + /// + TMT_FIRSTCOLOR = TMT_SCROLLBAR, + + /// + TMT_LASTCOLOR = TMT_MENUBAR, + + /// + TMT_FROMHUE1 = 1801, + + /// + TMT_FROMHUE2 = 1802, + + /// + TMT_FROMHUE3 = 1803, + + /// + TMT_FROMHUE4 = 1804, + + /// + TMT_FROMHUE5 = 1805, + + /// + TMT_TOHUE1 = 1806, + + /// + TMT_TOHUE2 = 1807, + + /// + TMT_TOHUE3 = 1808, + + /// + TMT_TOHUE4 = 1809, + + /// + TMT_TOHUE5 = 1810, + + /// + TMT_FROMCOLOR1 = 2001, + + /// + TMT_FROMCOLOR2 = 2002, + + /// + TMT_FROMCOLOR3 = 2003, + + /// + TMT_FROMCOLOR4 = 2004, + + /// + TMT_FROMCOLOR5 = 2005, + + /// + TMT_TOCOLOR1 = 2006, + + /// + TMT_TOCOLOR2 = 2007, + + /// + TMT_TOCOLOR3 = 2008, + + /// + TMT_TOCOLOR4 = 2009, + + /// + TMT_TOCOLOR5 = 2010, + + /// + TMT_TRANSPARENT = 2201, + + /// + TMT_AUTOSIZE = 2202, + + /// + TMT_BORDERONLY = 2203, + + /// + TMT_COMPOSITED = 2204, + + /// + TMT_BGFILL = 2205, + + /// + TMT_GLYPHTRANSPARENT = 2206, + + /// + TMT_GLYPHONLY = 2207, + + /// + TMT_ALWAYSSHOWSIZINGBAR = 2208, + + /// + TMT_MIRRORIMAGE = 2209, + + /// + TMT_UNIFORMSIZING = 2210, + + /// + TMT_INTEGRALSIZING = 2211, + + /// + TMT_SOURCEGROW = 2212, + + /// + TMT_SOURCESHRINK = 2213, + + /// + TMT_DRAWBORDERS = 2214, + + /// + TMT_NOETCHEDEFFECT = 2215, + + /// + TMT_TEXTAPPLYOVERLAY = 2216, + + /// + TMT_TEXTGLOW = 2217, + + /// + TMT_TEXTITALIC = 2218, + + /// + TMT_COMPOSITEDOPAQUE = 2219, + + /// + TMT_LOCALIZEDMIRRORIMAGE = 2220, + + /// + TMT_IMAGECOUNT = 2401, + + /// + TMT_ALPHALEVEL = 2402, + + /// + TMT_BORDERSIZE = 2403, + + /// + TMT_ROUNDCORNERWIDTH = 2404, + + /// + TMT_ROUNDCORNERHEIGHT = 2405, + + /// + TMT_GRADIENTRATIO1 = 2406, + + /// + TMT_GRADIENTRATIO2 = 2407, + + /// + TMT_GRADIENTRATIO3 = 2408, + + /// + TMT_GRADIENTRATIO4 = 2409, + + /// + TMT_GRADIENTRATIO5 = 2410, + + /// + TMT_PROGRESSCHUNKSIZE = 2411, + + /// + TMT_PROGRESSSPACESIZE = 2412, + + /// + TMT_SATURATION = 2413, + + /// + TMT_TEXTBORDERSIZE = 2414, + + /// + TMT_ALPHATHRESHOLD = 2415, + + /// + TMT_WIDTH = 2416, + + /// + TMT_HEIGHT = 2417, + + /// + TMT_GLYPHINDEX = 2418, + + /// + TMT_TRUESIZESTRETCHMARK = 2419, + + /// + TMT_MINDPI1 = 2420, + + /// + TMT_MINDPI2 = 2421, + + /// + TMT_MINDPI3 = 2422, + + /// + TMT_MINDPI4 = 2423, + + /// + TMT_MINDPI5 = 2424, + + /// + TMT_TEXTGLOWSIZE = 2425, + + /// + TMT_FRAMESPERSECOND = 2426, + + /// + TMT_PIXELSPERFRAME = 2427, + + /// + TMT_ANIMATIONDELAY = 2428, + + /// + TMT_GLOWINTENSITY = 2429, + + /// + TMT_OPACITY = 2430, + + /// + TMT_COLORIZATIONCOLOR = 2431, + + /// + TMT_COLORIZATIONOPACITY = 2432, + + /// + TMT_MINDPI6 = 2433, + + /// + TMT_MINDPI7 = 2434, + + /// + TMT_GLYPHFONT = 2601, + + /// + TMT_IMAGEFILE = 3001, + + /// + TMT_IMAGEFILE1 = 3002, + + /// + TMT_IMAGEFILE2 = 3003, + + /// + TMT_IMAGEFILE3 = 3004, + + /// + TMT_IMAGEFILE4 = 3005, + + /// + TMT_IMAGEFILE5 = 3006, + + /// + TMT_GLYPHIMAGEFILE = 3008, + + /// + TMT_IMAGEFILE6 = 3009, + + /// + TMT_IMAGEFILE7 = 3010, + + /// + TMT_TEXT = 3201, + + /// + TMT_CLASSICVALUE = 3202, + + /// + TMT_OFFSET = 3401, + + /// + TMT_TEXTSHADOWOFFSET = 3402, + + /// + TMT_MINSIZE = 3403, + + /// + TMT_MINSIZE1 = 3404, + + /// + TMT_MINSIZE2 = 3405, + + /// + TMT_MINSIZE3 = 3406, + + /// + TMT_MINSIZE4 = 3407, + + /// + TMT_MINSIZE5 = 3408, + + /// + TMT_NORMALSIZE = 3409, + + /// + TMT_MINSIZE6 = 3410, + + /// + TMT_MINSIZE7 = 3411, + + /// + TMT_SIZINGMARGINS = 3601, + + /// + TMT_CONTENTMARGINS = 3602, + + /// + TMT_CAPTIONMARGINS = 3603, + + /// + TMT_BORDERCOLOR = 3801, + + /// + TMT_FILLCOLOR = 3802, + + /// + TMT_TEXTCOLOR = 3803, + + /// + TMT_EDGELIGHTCOLOR = 3804, + + /// + TMT_EDGEHIGHLIGHTCOLOR = 3805, + + /// + TMT_EDGESHADOWCOLOR = 3806, + + /// + TMT_EDGEDKSHADOWCOLOR = 3807, + + /// + TMT_EDGEFILLCOLOR = 3808, + + /// + TMT_TRANSPARENTCOLOR = 3809, + + /// + TMT_GRADIENTCOLOR1 = 3810, + + /// + TMT_GRADIENTCOLOR2 = 3811, + + /// + TMT_GRADIENTCOLOR3 = 3812, + + /// + TMT_GRADIENTCOLOR4 = 3813, + + /// + TMT_GRADIENTCOLOR5 = 3814, + + /// + TMT_SHADOWCOLOR = 3815, + + /// + TMT_GLOWCOLOR = 3816, + + /// + TMT_TEXTBORDERCOLOR = 3817, + + /// + TMT_TEXTSHADOWCOLOR = 3818, + + /// + TMT_GLYPHTEXTCOLOR = 3819, + + /// + TMT_GLYPHTRANSPARENTCOLOR = 3820, + + /// + TMT_FILLCOLORHINT = 3821, + + /// + TMT_BORDERCOLORHINT = 3822, + + /// + TMT_ACCENTCOLORHINT = 3823, + + /// + TMT_TEXTCOLORHINT = 3824, + + /// + TMT_HEADING1TEXTCOLOR = 3825, + + /// + TMT_HEADING2TEXTCOLOR = 3826, + + /// + TMT_BODYTEXTCOLOR = 3827, + + /// + TMT_BGTYPE = 4001, + + /// + TMT_BORDERTYPE = 4002, + + /// + TMT_FILLTYPE = 4003, + + /// + TMT_SIZINGTYPE = 4004, + + /// + TMT_HALIGN = 4005, + + /// + TMT_CONTENTALIGNMENT = 4006, + + /// + TMT_VALIGN = 4007, + + /// + TMT_OFFSETTYPE = 4008, + + /// + TMT_ICONEFFECT = 4009, + + /// + TMT_TEXTSHADOWTYPE = 4010, + + /// + TMT_IMAGELAYOUT = 4011, + + /// + TMT_GLYPHTYPE = 4012, + + /// + TMT_IMAGESELECTTYPE = 4013, + + /// + TMT_GLYPHFONTSIZINGTYPE = 4014, + + /// + TMT_TRUESIZESCALINGTYPE = 4015, + + /// + TMT_USERPICTURE = 5001, + + /// + TMT_DEFAULTPANESIZE = 5002, + + /// + TMT_BLENDCOLOR = 5003, + + /// + TMT_CUSTOMSPLITRECT = 5004, + + /// + TMT_ANIMATIONBUTTONRECT = 5005, + + /// + TMT_ANIMATIONDURATION = 5006, + + /// + TMT_TRANSITIONDURATIONS = 6000, + + /// + TMT_SCALEDBACKGROUND = 7001, + + /// + TMT_ATLASIMAGE = 8000, + + /// + TMT_ATLASINPUTIMAGE = 8001, + + /// + TMT_ATLASRECT = 8002, + } + + public enum THEMESIZE { /// Receives the minimum size of a visual style part. - /// TS_MIN - Min, + TS_MIN, /// Receives the size of the visual style part that will best fit the available space. - /// TS_TRUE - True, + TS_TRUE, /// Receives the size that the theme manager uses to draw a part. - /// TS_DRAW - Draw + TS_DRAW } public enum WindowThemeAttributeType @@ -162,19 +1024,19 @@ namespace Vanara.PInvoke } [Flags] - public enum WindowThemeNonClientAttributes + public enum WTNCA { /// Do Not Draw The Caption (Text) - NoDrawCaption = 0x00000001, + WTNCA_NODRAWCAPTION = 0x00000001, /// Do Not Draw the Icon - NoDrawIcon = 0x00000002, + WTNCA_NODRAWICON = 0x00000002, /// Do Not Show the System Menu - NoSysMenu = 0x00000004, + WTNCA_NOSYSMENU = 0x00000004, /// Do Not Mirror the Question mark Symbol - NoMirrorHelp = 0x00000008 + WTNCA_NOMIRRORHELP = 0x00000008 } [PInvokeData("UxTheme.h")] @@ -189,7 +1051,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [System.Security.SecurityCritical] - public static extern HRESULT DrawThemeBackgroundEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, DrawThemeBackgroundOptions opts); + public static extern HRESULT DrawThemeBackgroundEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, DTBGOPTS opts); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -218,25 +1080,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] [System.Security.SecurityCritical] - public static extern HRESULT DrawThemeTextEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int iCharCount, DrawTextFlags dwFlags, ref RECT pRect, ref DrawThemeTextOptions pOptions); - - public enum ThemeDialogTextureFlags - { - /// Disables background texturing. - ETDT_DISABLE = 0x00000001, - /// Enables dialog window background texturing. The texturing is defined by a visual style. - ETDT_ENABLE = 0x00000002, - /// Uses the Tab control texture for the background texture of a dialog window. - ETDT_USETABTEXTURE = 0x00000004, - /// Enables dialog window background texturing. The texture is the Tab control texture defined by the visual style. This flag is equivalent to (ETDT_ENABLE | ETDT_USETABTEXTURE). - ETDT_ENABLETAB = (ETDT_ENABLE | ETDT_USETABTEXTURE), - /// Uses the Aero wizard texture for the background texture of a dialog window. - ETDT_USEAEROWIZARDTABTEXTURE = 0x00000008, - /// ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE. - ETDT_ENABLEAEROWIZARDTAB = (ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE), - /// ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE. - ETDT_VALIDBITS = (ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE), - } + public static extern HRESULT DrawThemeTextEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int iCharCount, DrawTextFlags dwFlags, ref RECT pRect, ref DTTOPTS pOptions); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -255,51 +1099,11 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern HRESULT GetThemeAnimationProperty(SafeThemeHandle hTheme, int iStoryboardId, int iTargetId, uint dwTransformIndex, ref TA_TRANSFORM, uint cbSize, out uint pcbSizeOut); - - [PInvokeData("UxTheme.h")] - public enum TA_TRANSFORM_TYPE - { - TATT_TRANSLATE_2D, - TATT_SCALE_2D, - TATT_OPACITY, - TATT_CLIP, - } - - [PInvokeData("UxTheme.h")] - [Flags] - public enum TA_TRANSFORM_FLAG - { - TATF_NONE = 0x0, - TATF_TARGETVALUES_USER = 0x1, - TATF_HASINITIALVALUES = 0x2, - TATF_HASORIGINVALUES = 0x4, - } - - [PInvokeData("UxTheme.h")] - public struct TA_TRANSFORM - { - public TA_TRANSFORM_TYPE eTransformType; - public uint dwTimingFunctionId; - public uint dwStartTime; // in milliseconds - public uint dwDurationTime; - public TA_TRANSFORM_FLAG eFlags; - } + public static extern HRESULT GetThemeAnimationProperty(SafeThemeHandle hTheme, int iStoryboardId, int iTargetId, TA_PROPERTY eProperty, IntPtr pvProperty, uint cbSize, out uint pcbSizeOut); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern HRESULT GetThemeAnimationTransform(SafeThemeHandle hTheme, int iStoryboardId, int iTargetId, TA_PROPERTY eProperty, IntPtr pvProperty, uint cbSize, out uint pcbSizeOut); - - [Flags] - public enum ThemeAppProperties : uint - { - /// Specifies that the non-client areas of application windows have visual styles applied. - STAP_ALLOW_NONCLIENT = (1U << 0), - /// Specifies that controls in application windows have visual styles applied. - STAP_ALLOW_CONTROLS = (1U << 1), - /// Specifies that all web content displayed in an application is rendered using visual styles. - STAP_ALLOW_WEBCONTENT = (1U << 2), - } + public static extern HRESULT GetThemeAnimationTransform(SafeThemeHandle hTheme, int iStoryboardId, int iTargetId, uint dwTransformIndex, ref TA_TRANSFORM pTransform, uint cbSize, out uint pcbSizeOut); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -327,7 +1131,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern HRESULT GetThemeColor(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int pColor); + public static extern HRESULT GetThemeColor(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out COLORREF pColor); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] @@ -339,7 +1143,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern HRESULT GetThemeFilename(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref System.Text.StringBuilder pszBuff, int buffLength); + public static extern HRESULT GetThemeFilename(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref StringBuilder pszBuff, int buffLength); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -370,7 +1174,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [System.Security.SecurityCritical] - public static extern HRESULT GetThemeMargins(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, IntPtr prc, out RECT pMargins); + public static extern HRESULT GetThemeMargins(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, PRECT prc, out MARGINS pMargins); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -378,7 +1182,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern HRESULT GetThemePartSize(SafeThemeHandle hTheme, SafeDCHandle hdc, int part, int state, PRECT pRect, ThemeSize eSize, out Size size); + public static extern HRESULT GetThemePartSize(SafeThemeHandle hTheme, SafeDCHandle hdc, int part, int state, PRECT pRect, THEMESIZE eSize, out SIZE size); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -386,7 +1190,7 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern HRESULT GetThemePropertyOrigin(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out ThemePropertyOrigin pOrigin); + public static extern HRESULT GetThemePropertyOrigin(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out PROPERTYORIGIN pOrigin); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] @@ -401,109 +1205,174 @@ namespace Vanara.PInvoke [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - [return: [MarshalAs(UnmanagedType.Bool)]] + [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetThemeSysBool(SafeThemeHandle hTheme, int iBoolID); [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern COLORREF GetThemeSysColor(SafeThemeHandle hTheme, int iColorID); + public static extern COLORREF GetThemeSysColor(SafeThemeHandle hTheme, SystemColorIndex iColorID); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern IntPtr GetThemeSysColorBrush(SafeThemeHandle hTheme, SystemColorIndex iColorID); [DllImport(Lib.UxTheme, ExactSpelling = true)] - public static extern int GetThemeSysInt(SafeThemeHandle hTheme, int iIntID, out int piVal); + public static extern HRESULT GetThemeSysInt(SafeThemeHandle hTheme, int iIntID, out int piVal); + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern int GetThemeSysSize(SafeThemeHandle hTheme, int iSizeID); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern HRESULT GetThemeSysString(SafeThemeHandle hTheme, int iStringID, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszStringBuff, int cchMaxStringChars); + + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern int GetThemeTextExtent(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int textLength, DrawTextFlags textFlags, ref RECT boundingRect, out RECT extentRect); + public static extern HRESULT GetThemeTextExtent(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string pszText, int iCharCount, DrawTextFlags dwTextFlags, PRECT pBoundingRect, out RECT pExtentRect); + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] + public static extern HRESULT GetThemeTextMetrics(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, out TEXTMETRIC ptm); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern HRESULT GetThemeTimingFunction(SafeThemeHandle hTheme, int iTimingFunctionId, out TA_TIMINGFUNCTION pTimingFunction, uint cbSize, out uint pcbSizeOut); + + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [System.Security.SecurityCritical] - public static extern int GetThemeTransitionDuration(SafeThemeHandle hTheme, int iPartId, int iStateIdFrom, int iStateIdTo, int iPropId, out int pdwDuration); + public static extern HRESULT GetThemeTransitionDuration(SafeThemeHandle hTheme, int iPartId, int iStateIdFrom, int iStateIdTo, int iPropId, out uint pdwDuration); + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern IntPtr GetWindowTheme(HandleRef hWnd); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern HRESULT HitTestThemeBackground(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, HitTestOptions dwOptions, ref RECT pRect, IntPtr hrgn, Point ptTest, out HitTestValues pwHitTestCode); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsAppThemed(); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsCompositionActive(); + + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsThemeActive(); + + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsThemeBackgroundPartiallyTransparent(SafeThemeHandle hTheme, int iPartId, int iStateId); + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsThemeDialogTextureEnabled(HandleRef hWnd); + + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsThemePartDefined(SafeThemeHandle hTheme, int iPartId, int iStateId); + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern IntPtr OpenThemeData(HandleRef hWnd, string classList); + public static extern SafeThemeHandle OpenThemeData(HandleRef hWnd, string classList); + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern IntPtr OpenThemeDataEx(HandleRef hWnd, string classList, OpenThemeDataOptions dwFlags); + public static extern SafeThemeHandle OpenThemeDataEx(HandleRef hWnd, string classList, OpenThemeDataOptions dwFlags); + [PInvokeData("UxTheme.h")] + [DllImport(Lib.UxTheme, ExactSpelling = true)] + public static extern void SetThemeAppProperties(ThemeAppProperties dwFlags); + + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] [System.Security.SecurityCritical] - public static extern int SetWindowTheme(HandleRef hWnd, string pszSubAppName, string pszSubIdList); + public static extern HRESULT SetWindowTheme(HandleRef hWnd, string pszSubAppName, string pszSubIdList); - /// - /// Sets attributes to control how visual styles are applied to a specified window. - /// + /// Sets attributes to control how visual styles are applied to a specified window. /// Handle to a window to apply changes to. - /// Value of type WINDOWTHEMEATTRIBUTETYPE that specifies the type of attribute to set. The value of this parameter determines the type of data that should be passed in the pvAttribute parameter. - /// A pointer that specifies attributes to set. Type is determined by the value of the eAttribute value. - /// Specifies the size, in bytes, of the data pointed to by pvAttribute. + /// + /// Value of type WINDOWTHEMEATTRIBUTETYPE that specifies the type of attribute to set. The value of this parameter determines the type of data that + /// should be passed in the pvAttribute parameter. + /// + /// A pointer that specifies attributes to set. Type is determined by the value of the eAttribute value. + /// Specifies the size, in bytes, of the data pointed to by pvAttribute. /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] [System.Security.SecurityCritical] - public static extern int SetWindowThemeAttribute(HandleRef hWnd, WindowThemeAttributeType wtype, ref WTA_OPTIONS attributes, int size); + public static extern HRESULT SetWindowThemeAttribute(HandleRef hWnd, WindowThemeAttributeType eAttribute, ref WTA_OPTIONS pvAttribute, int cbAttribute); - /// - /// Sets attributes to control how visual styles are applied to a specified window. - /// + /// Sets attributes to control how visual styles are applied to a specified window. /// Handle to a window to apply changes to. /// A combination of flags that modify window visual style attributes. /// if set to true add the flag to the window attributes, otherwise remove the flag. - public static void SetWindowThemeAttribute(HandleRef hWnd, WindowThemeNonClientAttributes ncAttrs, bool activate = true) + public static void SetWindowThemeNonClientAttributes(HandleRef hWnd, WTNCA ncAttrs, bool activate = true) { var opt = new WTA_OPTIONS { Flags = ncAttrs, Mask = activate ? (int)ncAttrs : 0 }; - var ret = SetWindowThemeAttribute(hWnd, WindowThemeAttributeType.NonClient, ref opt, Marshal.SizeOf(opt)); - if (ret != 0) throw new Win32Exception(ret); + SetWindowThemeAttribute(hWnd, WindowThemeAttributeType.NonClient, ref opt, Marshal.SizeOf(opt)).ThrowIfFailed(); } + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true)] - private static extern int GetThemeIntList(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out INTLIST pIntList); + private static extern HRESULT GetThemeIntList(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out INTLIST pIntList); + [PInvokeData("UxTheme.h")] [DllImport(Lib.UxTheme, ExactSpelling = true, EntryPoint = "GetThemeIntList")] - private static extern int GetThemeIntListPreVista(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out INTLIST_OLD pIntList); + private static extern HRESULT GetThemeIntListPreVista(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out INTLIST_OLD pIntList); /// Defines the options for the function. [StructLayout(LayoutKind.Sequential)] - public struct DrawThemeTextOptions + public struct DTTOPTS { - public int dwSize; + public uint dwSize; public DrawThemeTextOptionsMasks dwMasks; - public int crText; - public int crBorder; - public int crShadow; + public COLORREF crText; + public COLORREF crBorder; + public COLORREF crShadow; public TextShadowType iTextShadowType; public Point ptShadowOffset; public int iBorderSize; public int iFontPropId; public int iColorPropId; public int iStateId; + [MarshalAs(UnmanagedType.Bool)] public bool fApplyOverlay; + public int iGlowSize; + [MarshalAs(UnmanagedType.FunctionPtr)] public DrawThemeTextCallback pfnDrawTextCallback; + public IntPtr lParam; - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// This value must be specified to initialize. Use null. - public DrawThemeTextOptions(byte? shouldBeNull) : this() + public DTTOPTS(byte? shouldBeNull) : this() { - dwSize = Marshal.SizeOf(typeof(DrawThemeTextOptions)); + dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS)); } /// Gets or sets a value that specifies an alternate color property to use when drawing text. /// The alternate color of the text. - public Color AlternateColor + public int AlternateColorProperty { - get => ColorTranslator.FromWin32(iColorPropId); set + get => iColorPropId; + set { - iColorPropId = ColorTranslator.ToWin32(value); - dwMasks |= DrawThemeTextOptionsMasks.ColorProp; + iColorPropId = value; + dwMasks |= DrawThemeTextOptionsMasks.DTT_COLORPROP; } } @@ -511,10 +1380,11 @@ namespace Vanara.PInvoke /// The alternate font. public DrawThemeTextSystemFonts AlternateFont { - get => (DrawThemeTextSystemFonts)iFontPropId; set + get => (DrawThemeTextSystemFonts)iFontPropId; + set { iFontPropId = (int)value; - dwMasks |= DrawThemeTextOptionsMasks.FontProp; + dwMasks |= DrawThemeTextOptionsMasks.DTT_FONTPROP; } } @@ -526,7 +1396,8 @@ namespace Vanara.PInvoke /// true if antialiased alpha; otherwise, false. public bool AntiAliasedAlpha { - get => (dwMasks & DrawThemeTextOptionsMasks.Composited) == DrawThemeTextOptionsMasks.Composited; set => SetFlag(DrawThemeTextOptionsMasks.Composited, value); + get => dwMasks.IsFlagSet(DrawThemeTextOptionsMasks.DTT_COMPOSITED); + set => SetFlag(DrawThemeTextOptionsMasks.DTT_COMPOSITED, value); } /// @@ -536,10 +1407,11 @@ namespace Vanara.PInvoke /// true if drawn on top; otherwise, false. public bool ApplyOverlay { - get => fApplyOverlay; set + get => fApplyOverlay; + set { fApplyOverlay = value; - dwMasks |= DrawThemeTextOptionsMasks.ApplyOverlay; + dwMasks |= DrawThemeTextOptionsMasks.DTT_APPLYOVERLAY; } } @@ -547,10 +1419,11 @@ namespace Vanara.PInvoke /// The color of the border. public Color BorderColor { - get => ColorTranslator.FromWin32(crBorder); set + get => crBorder; + set { - crBorder = ColorTranslator.ToWin32(value); - dwMasks |= DrawThemeTextOptionsMasks.BorderColor; + crBorder = value; + dwMasks |= DrawThemeTextOptionsMasks.DTT_BORDERCOLOR; } } @@ -558,10 +1431,11 @@ namespace Vanara.PInvoke /// The size of the border. public int BorderSize { - get => iBorderSize; set + get => iBorderSize; + set { iBorderSize = value; - dwMasks |= DrawThemeTextOptionsMasks.BorderSize; + dwMasks |= DrawThemeTextOptionsMasks.DTT_BORDERSIZE; } } @@ -569,10 +1443,11 @@ namespace Vanara.PInvoke /// The callback function. public DrawThemeTextCallback Callback { - get => pfnDrawTextCallback; set + get => pfnDrawTextCallback; + set { pfnDrawTextCallback = value; - dwMasks |= DrawThemeTextOptionsMasks.Callback; + dwMasks |= DrawThemeTextOptionsMasks.DTT_CALLBACK; } } @@ -580,10 +1455,11 @@ namespace Vanara.PInvoke /// The size of the glow. public int GlowSize { - get => iGlowSize; set + get => iGlowSize; + set { iGlowSize = value; - dwMasks |= DrawThemeTextOptionsMasks.GlowSize; + dwMasks |= DrawThemeTextOptionsMasks.DTT_GLOWSIZE; } } @@ -591,7 +1467,8 @@ namespace Vanara.PInvoke /// The parameter. public IntPtr LParam { - get => lParam; set => lParam = value; + get => lParam; + set => lParam = value; } /// @@ -602,17 +1479,19 @@ namespace Vanara.PInvoke /// true if returning the calculated rectangle; otherwise, false. public bool ReturnCalculatedRectangle { - get => (dwMasks & DrawThemeTextOptionsMasks.CalcRect) == DrawThemeTextOptionsMasks.CalcRect; set => SetFlag(DrawThemeTextOptionsMasks.CalcRect, value); + get => dwMasks.IsFlagSet(DrawThemeTextOptionsMasks.DTT_CALCRECT); + set => SetFlag(DrawThemeTextOptionsMasks.DTT_CALCRECT, value); } /// Gets or sets the color of the shadow drawn behind the text. /// The color of the shadow. public Color ShadowColor { - get => ColorTranslator.FromWin32(crShadow); set + get => crShadow; + set { - crShadow = ColorTranslator.ToWin32(value); - dwMasks |= DrawThemeTextOptionsMasks.ShadowColor; + crShadow = value; + dwMasks |= DrawThemeTextOptionsMasks.DTT_SHADOWCOLOR; } } @@ -620,10 +1499,11 @@ namespace Vanara.PInvoke /// The shadow offset. public Point ShadowOffset { - get => new Point(ptShadowOffset.X, ptShadowOffset.Y); set + get => new Point(ptShadowOffset.X, ptShadowOffset.Y); + set { ptShadowOffset = value; - dwMasks |= DrawThemeTextOptionsMasks.ShadowOffset; + dwMasks |= DrawThemeTextOptionsMasks.DTT_SHADOWOFFSET; } } @@ -634,7 +1514,7 @@ namespace Vanara.PInvoke get => iTextShadowType; set { iTextShadowType = value; - dwMasks |= DrawThemeTextOptionsMasks.ShadowType; + dwMasks |= DrawThemeTextOptionsMasks.DTT_SHADOWTYPE; } } @@ -642,27 +1522,55 @@ namespace Vanara.PInvoke /// The color of the text. public Color TextColor { - get => ColorTranslator.FromWin32(crText); set + get => crText; + set { - crText = ColorTranslator.ToWin32(value); - dwMasks |= DrawThemeTextOptionsMasks.TextColor; + crText = value; + dwMasks |= DrawThemeTextOptionsMasks.DTT_TEXTCOLOR; } } /// Gets an instance with default values set. - public static DrawThemeTextOptions Default => new DrawThemeTextOptions(null); + public static DTTOPTS Default => new DTTOPTS(null); private void SetFlag(DrawThemeTextOptionsMasks f, bool value) { - if (value) dwMasks |= f; else dwMasks &= ~f; + dwMasks = dwMasks.SetFlags(f, value); } } + [PInvokeData("UxTheme.h")] + [StructLayout(LayoutKind.Sequential)] + public struct MARGINS + { + public int cxLeftWidth; + public int cxRightWidth; + public int cyTopHeight; + public int cyBottomHeight; + } + + [StructLayout(LayoutKind.Sequential)] + public struct TA_TIMINGFUNCTION + { + public TA_TIMINGFUNCTION_TYPE eTimingFunctionType; + } + + [PInvokeData("UxTheme.h")] + [StructLayout(LayoutKind.Sequential)] + public struct TA_TRANSFORM + { + public uint dwDurationTime; + public uint dwStartTime; + public uint dwTimingFunctionId; + public TA_TRANSFORM_FLAG eFlags; + public TA_TRANSFORM_TYPE eTransformType; + } + /// The Options of What Attributes to Add/Remove [StructLayout(LayoutKind.Sequential)] public struct WTA_OPTIONS { - public WindowThemeNonClientAttributes Flags; + public WTNCA Flags; public int Mask; } @@ -686,44 +1594,17 @@ namespace Vanara.PInvoke /// Defines the options for the DrawThemeBackgroundEx function. [StructLayout(LayoutKind.Sequential)] - public class DrawThemeBackgroundOptions + public class DTBGOPTS { - public int dwSize; - public int dwFlags; + public uint dwSize; + public DrawThemeBackgroundFlags dwFlags; public RECT rcClip; - [Flags] - private enum DrawThemeBackgroundFlags - { - None = 0, - - /// The ClipRectangle value is defined. - ClipRect = 1, - - /// Deprecated. Draw transparent and alpha images as solid. - DrawSolid = 2, - - /// Do not draw the border of the part (currently this value is only supported for bgtype=borderfill). - OmitBorder = 4, - - /// Do not draw the content area of the part (currently this value is only supported for bgtype=borderfill). - OmitContent = 8, - - /// Deprecated. - ComputingRegion = 16, - - /// Assume the hdc is mirrored and flip images as appropriate (currently this value is only supported for bgtype=imagefile). - HasMirroredDC = 32, - - /// Do not mirror the output; even in right-to-left (RTL) layout. - DoNotMirror = 64 - } - - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// The rectangle to which drawing is clipped. - public DrawThemeBackgroundOptions(Rectangle? clipRect) + public DTBGOPTS(Rectangle? clipRect) { - dwSize = Marshal.SizeOf(this); + dwSize = (uint)Marshal.SizeOf(this); ClipRectangle = clipRect; } @@ -739,51 +1620,43 @@ namespace Vanara.PInvoke set { rcClip = value ?? default(RECT); - SetFlag(DrawThemeBackgroundFlags.ClipRect, value.HasValue); + SetFlag(DrawThemeBackgroundFlags.DTBG_CLIPRECT, value.HasValue); } } /// Gets or sets a value indicating whether omit drawing the border. /// true if omit border; otherwise, false. - public bool OmitBorder { get => GetFlag(DrawThemeBackgroundFlags.OmitBorder); set => SetFlag(DrawThemeBackgroundFlags.OmitBorder, value); } + public bool OmitBorder { get => dwFlags.IsFlagSet(DrawThemeBackgroundFlags.DTBG_OMITBORDER); set => SetFlag(DrawThemeBackgroundFlags.DTBG_OMITBORDER, value); } /// Gets or sets a value indicating whether omit drawing the content area of the part. /// true if omit content area of the part; otherwise, false. - public bool OmitContent { get => GetFlag(DrawThemeBackgroundFlags.OmitContent); set => SetFlag(DrawThemeBackgroundFlags.OmitContent, value); } + public bool OmitContent { get => dwFlags.IsFlagSet(DrawThemeBackgroundFlags.DTBG_OMITCONTENT); set => SetFlag(DrawThemeBackgroundFlags.DTBG_OMITCONTENT, value); } /// Gets or sets a value indicating the hdc is mirrored and flip images as appropriate. /// true if mirrored; otherwise, false. - public bool HasMirroredDC { get => GetFlag(DrawThemeBackgroundFlags.HasMirroredDC); set => SetFlag(DrawThemeBackgroundFlags.HasMirroredDC, value); } + public bool HasMirroredDC { get => dwFlags.IsFlagSet(DrawThemeBackgroundFlags.DTBG_MIRRORDC); set => SetFlag(DrawThemeBackgroundFlags.DTBG_MIRRORDC, value); } /// Gets or sets a value indicating whether to mirror the output; even in right-to-left (RTL) layout. /// true if not mirroring; otherwise, false. - public bool DoNotMirror { get => GetFlag(DrawThemeBackgroundFlags.DoNotMirror); set => SetFlag(DrawThemeBackgroundFlags.DoNotMirror, value); } + public bool DoNotMirror { get => dwFlags.IsFlagSet(DrawThemeBackgroundFlags.DTBG_NOMIRROR); set => SetFlag(DrawThemeBackgroundFlags.DTBG_NOMIRROR, value); } - /// Performs an implicit conversion from to . + /// Performs an implicit conversion from to . /// The clipping rectangle. /// The result of the conversion. - public static implicit operator DrawThemeBackgroundOptions(Rectangle clipRectangle) => new DrawThemeBackgroundOptions(clipRectangle); - - private bool GetFlag(DrawThemeBackgroundFlags f) => (dwFlags & (int)f) == (int)f; + public static implicit operator DTBGOPTS(Rectangle clipRectangle) => new DTBGOPTS(clipRectangle); private void SetFlag(DrawThemeBackgroundFlags f, bool value) { - if (value) dwFlags |= (int)f; else dwFlags &= ~(int)f; + dwFlags = dwFlags.SetFlags(f, value); } } - /// - /// Represents a safe handle for a token. Use in place of HTOKEN or HANDLE. - /// - /// - public class SafeThemeHandle : SafeHandleZeroOrMinusOneIsInvalid + /// Represents a safe handle for a theme. Use in place of HTHEME. + public class SafeThemeHandle : Vanara.InteropServices.GenericSafeHandle { - public SafeThemeHandle(IntPtr hTheme, bool ownsHandle = true) : base(ownsHandle) - { - SetHandle(hTheme); - } + public SafeThemeHandle() : this(IntPtr.Zero) { } - protected override bool ReleaseHandle() => CloseThemeData(handle) == 0; + public SafeThemeHandle(IntPtr hTheme, bool ownsHandle = true) : base(hTheme, p => CloseThemeData(p) == 0, ownsHandle) { } } } } \ No newline at end of file diff --git a/PInvoke/UxTheme/UXTHEME_GDI.cs b/PInvoke/UxTheme/UXTHEME_GDI.cs index 1b57bf1b..be9b66d8 100644 --- a/PInvoke/UxTheme/UXTHEME_GDI.cs +++ b/PInvoke/UxTheme/UXTHEME_GDI.cs @@ -6,9 +6,9 @@ namespace Vanara.PInvoke public static partial class UxTheme { [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern int GetThemeFont(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, out LOGFONT pFont); + public static extern HRESULT GetThemeFont(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, out LOGFONT pFont); [DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] - public static extern int GetThemeSysFont(SafeThemeHandle hTheme, int iFontId, out LOGFONT pFont); + public static extern HRESULT GetThemeSysFont(SafeThemeHandle hTheme, int iFontId, out LOGFONT pFont); } } \ No newline at end of file diff --git a/WIndows.Forms/Drawing/BufferedPaint.cs b/WIndows.Forms/Drawing/BufferedPaint.cs index c594eb77..ffb05918 100644 --- a/WIndows.Forms/Drawing/BufferedPaint.cs +++ b/WIndows.Forms/Drawing/BufferedPaint.cs @@ -16,7 +16,7 @@ namespace Vanara.Drawing static BufferedPaint() { BufferedPaintInit(); } - public delegate int GetDuration(TState oldState, TState newState); + public delegate uint GetDuration(TState oldState, TState newState); public delegate void PaintAction(Graphics graphics, Rectangle bounds, TState currentState, TParam data); diff --git a/WIndows.Forms/Extensions/VisualStylesRendererExtension.cs b/WIndows.Forms/Extensions/VisualStylesRendererExtension.cs index ab3b6129..21dba2d0 100644 --- a/WIndows.Forms/Extensions/VisualStylesRendererExtension.cs +++ b/WIndows.Forms/Extensions/VisualStylesRendererExtension.cs @@ -13,22 +13,22 @@ namespace Vanara.Extensions { public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins) { - RECT rc; using (var hdc = new SafeDCHandle(dc)) - GetThemeMargins(new SafeThemeHandle(rnd.Handle, false), hdc, rnd.Part, rnd.State, (int)prop, IntPtr.Zero, out rc); - return new Padding(rc.left, rc.top, rc.right, rc.bottom); + { + GetThemeMargins(rnd.GetSafeHandle(), hdc, rnd.Part, rnd.State, (int)prop, null, out MARGINS m); + return new Padding(m.cxLeftWidth, m.cyTopHeight, m.cxRightWidth, m.cyBottomHeight); + } } - public static int GetTransitionDuration(this VisualStyleRenderer rnd, int toState, int fromState = 0) + public static uint GetTransitionDuration(this VisualStyleRenderer rnd, int toState, int fromState = 0) { - int dwDuration; - GetThemeTransitionDuration(new SafeThemeHandle(rnd.Handle, false), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out dwDuration); + GetThemeTransitionDuration(rnd.GetSafeHandle(), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out var dwDuration); return dwDuration; } public static int[,] GetTransitionMatrix(this VisualStyleRenderer rnd) { - var res = GetThemeIntList(new SafeThemeHandle(rnd.Handle, false), rnd.Part, rnd.State, (int)IntegerListProperty.TransitionDuration); + var res = GetThemeIntList(rnd.GetSafeHandle(), rnd.Part, rnd.State, (int)IntegerListProperty.TransitionDuration); if (res == null || res.Length == 0) return null; var dim = res[0]; var ret = new int[dim, dim]; @@ -38,10 +38,7 @@ namespace Vanara.Extensions return ret; } - public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) - { - return IsThemePartDefined(new SafeThemeHandle(rnd.Handle, false), part, state); - } + public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) => IsThemePartDefined(rnd.GetSafeHandle(), part, state); /// /// Sets the state of the . @@ -68,10 +65,12 @@ namespace Vanara.Extensions /// The window. /// The attributes to apply or disable. /// if set to true enable the attribute, otherwise disable it. - public static void SetWindowThemeAttribute(this IWin32Window window, WindowThemeNonClientAttributes attr, bool enable = true) + public static void SetWindowThemeAttribute(this IWin32Window window, WTNCA attr, bool enable = true) { - try { UxTheme.SetWindowThemeAttribute(new HandleRef(window, window.Handle), attr, enable); } + try { UxTheme.SetWindowThemeNonClientAttributes(new HandleRef(window, window.Handle), attr, enable); } catch (EntryPointNotFoundException) { } } + + private static SafeThemeHandle GetSafeHandle(this VisualStyleRenderer rnd) => new SafeThemeHandle(rnd.Handle, false); } } \ No newline at end of file diff --git a/WIndows.Forms/Extensions/VisualStylesRendererExtensionGDI.cs b/WIndows.Forms/Extensions/VisualStylesRendererExtensionGDI.cs index 125b6233..1011fcfb 100644 --- a/WIndows.Forms/Extensions/VisualStylesRendererExtensionGDI.cs +++ b/WIndows.Forms/Extensions/VisualStylesRendererExtensionGDI.cs @@ -139,7 +139,7 @@ namespace Vanara.Extensions using (new SafeDCObjectHandle(memoryHdc, font?.ToHfont() ?? IntPtr.Zero)) { // Draw glowing text - var dttOpts = new DrawThemeTextOptions(null) {GlowSize = glowSize, AntiAliasedAlpha = true}; + var dttOpts = new DTTOPTS(null) {GlowSize = glowSize, AntiAliasedAlpha = true}; if (color != null) dttOpts.TextColor = color.Value; var textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(ht, memoryHdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref textBounds, ref dttOpts); @@ -156,8 +156,8 @@ namespace Vanara.Extensions /// A in which the text is drawn. /// The text to draw. /// A bitwise combination of the values. - /// The . - public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, TextFormatFlags flags, ref DrawThemeTextOptions options) + /// The . + public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, TextFormatFlags flags, ref DTTOPTS options) { var rc = new RECT(bounds); var ht = new SafeThemeHandle(rnd.Handle, false); diff --git a/WIndows.Forms/VisualTheme.cs b/WIndows.Forms/VisualTheme.cs index 511779b7..dc50d3c7 100644 --- a/WIndows.Forms/VisualTheme.cs +++ b/WIndows.Forms/VisualTheme.cs @@ -35,7 +35,7 @@ namespace Vanara.Windows.Forms public void DrawBackground(IDeviceContext graphics, int partId, int stateId, Rectangle bounds, Rectangle clipRect) { var b = new RECT(bounds); - var o = new DrawThemeBackgroundOptions(clipRect); // {OmitBorder = true, OmitContent = true}; + var o = new DTBGOPTS(clipRect); // {OmitBorder = true, OmitContent = true}; using (var hdc = new SafeDCHandle(graphics)) DrawThemeBackgroundEx(hTheme, hdc, partId, stateId, ref b, o); } @@ -46,10 +46,10 @@ namespace Vanara.Windows.Forms DrawThemeParentBackground(new HandleRef(childWindow, childWindow.Handle), hdc, bounds); } - public void DrawText(IDeviceContext graphics, int partId, int stateId, Rectangle bounds, string text, TextFormatFlags fmt = TextFormatFlags.Default, DrawThemeTextOptions? options = null, Font font = null) + public void DrawText(IDeviceContext graphics, int partId, int stateId, Rectangle bounds, string text, TextFormatFlags fmt = TextFormatFlags.Default, DTTOPTS? options = null, Font font = null) { var b = new RECT(bounds); - var dt = options ?? DrawThemeTextOptions.Default; //new DrawThemeTextOptions(true) {AntiAliasedAlpha = true, BorderSize = 10, BorderColor = Color.Red, ApplyOverlay = true, ShadowType = TextShadowType.Continuous, ShadowColor = Color.White, ShadowOffset = new Point(2, 2), GlowSize = 18, TextColor = Color.White, Callback = DrawTextCallback }; + var dt = options ?? DTTOPTS.Default; //new DrawThemeTextOptions(true) {AntiAliasedAlpha = true, BorderSize = 10, BorderColor = Color.Red, ApplyOverlay = true, ShadowType = TextShadowType.Continuous, ShadowColor = Color.White, ShadowOffset = new Point(2, 2), GlowSize = 18, TextColor = Color.White, Callback = DrawTextCallback }; using (var hdc = new SafeDCHandle(graphics)) using (new SafeDCObjectHandle(hdc, font?.ToHfont() ?? IntPtr.Zero)) DrawThemeTextEx(hTheme, hdc, partId, stateId, text, text.Length, (DrawTextFlags)fmt, ref b, ref dt); @@ -60,8 +60,7 @@ namespace Vanara.Windows.Forms RECT b = new RECT(bounds); using (var hdc = new SafeDCHandle(graphics)) { - RECT rc; - if (0 == GetThemeBackgroundContentRect(hTheme, hdc, partId, stateId, ref b, out rc)) return rc; + if (GetThemeBackgroundContentRect(hTheme, hdc, partId, stateId, ref b, out RECT rc).Succeeded) return rc; } return null; } @@ -70,30 +69,26 @@ namespace Vanara.Windows.Forms { using (var hdc = new SafeDCHandle(graphics)) { - IntPtr hBmp; - if (0 == GetThemeBitmap(hTheme, hdc, partId, stateId, propId, 0, out hBmp)) return Image.FromHbitmap(hBmp); + if (GetThemeBitmap(hTheme, hdc, partId, stateId, propId, 0, out IntPtr hBmp).Succeeded) return Image.FromHbitmap(hBmp); } return null; } public bool? GetBool(int partId, int stateId, int propId) { - bool b; - if (0 == GetThemeBool(hTheme, partId, stateId, propId, out b)) return b; + if (GetThemeBool(hTheme, partId, stateId, propId, out bool b).Succeeded) return b; return null; } public Color? GetColor(int partId, int stateId, int propId) { - int cr; - if (0 == GetThemeColor(hTheme, partId, stateId, propId, out cr)) return ColorTranslator.FromWin32(cr); + if (GetThemeColor(hTheme, partId, stateId, propId, out var cr).Succeeded) return cr; return null; } public int? GetEnumValue(int partId, int stateId, int propId) { - int i; - if (0 == GetThemeEnumValue(hTheme, partId, stateId, propId, out i)) return i; + if (GetThemeEnumValue(hTheme, partId, stateId, propId, out int i).Succeeded) return i; return null; } @@ -101,7 +96,7 @@ namespace Vanara.Windows.Forms { const int sbLen = 1024; var sb = new StringBuilder(sbLen); - if (0 == GetThemeFilename(hTheme, partId, stateId, propId, ref sb, sbLen)) return sb.ToString(); + if (GetThemeFilename(hTheme, partId, stateId, propId, ref sb, sbLen).Succeeded) return sb.ToString(); return null; } @@ -109,23 +104,20 @@ namespace Vanara.Windows.Forms { using (var hdc = new SafeDCHandle(graphics)) { - LOGFONT f; - if (0 == GetThemeFont(hTheme, hdc, partId, stateId, propId, out f)) return f.ToFont(); + if (GetThemeFont(hTheme, hdc, partId, stateId, propId, out LOGFONT f).Succeeded) return f.ToFont(); } return null; } public int? GetInt(int partId, int stateId, int propId) { - int i; - if (0 == GetThemeInt(hTheme, partId, stateId, propId, out i)) return i; + if (GetThemeInt(hTheme, partId, stateId, propId, out int i).Succeeded) return i; return null; } public int? GetSysInt(int propId) { - int i; - if (0 == GetThemeSysInt(hTheme, propId, out i)) return i; + if (GetThemeSysInt(hTheme, propId, out int i).Succeeded) return i; return null; } @@ -135,9 +127,8 @@ namespace Vanara.Windows.Forms { using (var hdc = new SafeDCHandle(graphics)) { - RECT rc; - if (0 == GetThemeMargins(hTheme, hdc, partId, stateId, propId, IntPtr.Zero, out rc)) - return new Padding(rc.left, rc.top, rc.right, rc.bottom); + if (GetThemeMargins(hTheme, hdc, partId, stateId, propId, null, out MARGINS m).Succeeded) + return new Padding(m.cxLeftWidth, m.cyTopHeight, m.cxRightWidth, m.cyBottomHeight); } return null; } @@ -146,8 +137,7 @@ namespace Vanara.Windows.Forms { using (var hdc = new SafeDCHandle(graphics)) { - int i; - if (0 == GetThemeMetric(hTheme, hdc, partId, stateId, propId, out i)) return i; + if (GetThemeMetric(hTheme, hdc, partId, stateId, propId, out int i).Succeeded) return i; } return null; } @@ -250,7 +240,7 @@ namespace Vanara.Windows.Forms o = GetFilename(partId, stateId, propId); break; case PropertyType.Size: - o = GetPartSize(graphics, partId, stateId, null, (ThemeSize)propId); + o = GetPartSize(graphics, partId, stateId, null, (THEMESIZE)propId); break; case PropertyType.Position: o = GetPosition(partId, stateId, propId); @@ -280,55 +270,47 @@ namespace Vanara.Windows.Forms return o; } - public Size? GetPartSize(IDeviceContext graphics, int partId, int stateId, Rectangle? destRect, ThemeSize themeSize) + public Size? GetPartSize(IDeviceContext graphics, int partId, int stateId, Rectangle? destRect, THEMESIZE themeSize) { using (var hdc = new SafeDCHandle(graphics)) { - Size sz; - if (0 != GetThemePartSize(hTheme, hdc, partId, stateId, destRect, themeSize, out sz)) - return null; - return sz; + if (GetThemePartSize(hTheme, hdc, partId, stateId, destRect, themeSize, out var sz).Succeeded) + return sz; + return null; } } public Point? GetPosition(int partId, int stateId, int propId) { - Point i; - if (0 == GetThemePosition(hTheme, partId, stateId, propId, out i)) return i; + if (GetThemePosition(hTheme, partId, stateId, propId, out Point i).Succeeded) return i; return null; } public int GetPropertyOrigin(int partId, int stateId, int propId) { - ThemePropertyOrigin po; - GetThemePropertyOrigin(hTheme, partId, stateId, propId, out po); + GetThemePropertyOrigin(hTheme, partId, stateId, propId, out PROPERTYORIGIN po); return (int)po; } public Rectangle? GetRect(int partId, int stateId, int propId) { - RECT rc; - if (0 == GetThemeRect(hTheme, partId, stateId, propId, out rc)) return rc; + if (GetThemeRect(hTheme, partId, stateId, propId, out RECT rc).Succeeded) return rc; return null; } public byte[] GetDiskStream(SafeLibraryHandle hInst, int partId, int stateId, int propId) { - byte[] bytes; - int bLen; - var r = GetThemeStream(hTheme, partId, stateId, propId, out bytes, out bLen, hInst); - if (r == 0) return bytes; - if ((uint)r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream"); + var r = GetThemeStream(hTheme, partId, stateId, propId, out byte[] bytes, out int bLen, hInst); + if (r.Succeeded) return bytes; + if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream"); return null; } public byte[] GetStream(int partId, int stateId, int propId) { - byte[] bytes; - int bLen; - var r = GetThemeStream(hTheme, partId, stateId, propId, out bytes, out bLen, IntPtr.Zero); - if (r == 0) return bytes; - if ((uint)r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream"); + var r = GetThemeStream(hTheme, partId, stateId, propId, out byte[] bytes, out int bLen, IntPtr.Zero); + if (r.Succeeded) return bytes; + if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream"); return null; } @@ -336,15 +318,14 @@ namespace Vanara.Windows.Forms { const int sbLen = 1024; var sb = new StringBuilder(sbLen); - if (0 == GetThemeString(hTheme, partId, stateId, propId, ref sb, sbLen)) + if (GetThemeString(hTheme, partId, stateId, propId, sb, sbLen).Succeeded) return sb.ToString(); return null; } - public int GetTransitionDuration(int partId, int fromStateId, int toStateId, int propId) + public uint GetTransitionDuration(int partId, int fromStateId, int toStateId, int propId) { - int dur; - GetThemeTransitionDuration(hTheme, partId, fromStateId, toStateId, propId, out dur); + GetThemeTransitionDuration(hTheme, partId, fromStateId, toStateId, propId, out var dur); return dur; }