Completion of UxTheme.dll methods and corrections

pull/10/head
David Hall 2017-12-27 11:01:03 -07:00
parent b9a8ac50d0
commit 1241963a8b
8 changed files with 1384 additions and 331 deletions

View File

@ -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
{
/// <summary>The ANSI CHARSET</summary>
ANSI_CHARSET = 0,
/// <summary>The DEFAULT CHARSET</summary>
DEFAULT_CHARSET = 1,
/// <summary>The SYMBOL CHARSET</summary>
SYMBOL_CHARSET = 2,
/// <summary>The SHIFTJIS_ CHARSET</summary>
SHIFTJIS_CHARSET = 128,
/// <summary>The HANGEUL CHARSET</summary>
HANGEUL_CHARSET = 129,
/// <summary>The HANGUL CHARSET</summary>
HANGUL_CHARSET = 129,
/// <summary>The G B2312 CHARSET</summary>
GB2312_CHARSET = 134,
/// <summary>The CHINESEBIG5 CHARSET</summary>
CHINESEBIG5_CHARSET = 136,
/// <summary>The OEM CHARSET</summary>
OEM_CHARSET = 255,
/// <summary>The JOHAB_CHARSET</summary>
JOHAB_CHARSET = 130,
/// <summary>The HEBREW_CHARSET</summary>
HEBREW_CHARSET = 177,
/// <summary>The ARABIC_CHARSET</summary>
ARABIC_CHARSET = 178,
/// <summary>The GREEK_CHARSET</summary>
GREEK_CHARSET = 161,
/// <summary>The TURKISH_CHARSET</summary>
TURKISH_CHARSET = 162,
/// <summary>The VIETNAMESE_CHARSET</summary>
VIETNAMESE_CHARSET = 163,
/// <summary>The THAI_CHARSET</summary>
THAI_CHARSET = 222,
/// <summary>The EASTEUROPE_CHARSET</summary>
EASTEUROPE_CHARSET = 238,
/// <summary>The RUSSIAN_CHARSET</summary>
RUSSIAN_CHARSET = 204,
/// <summary>The MAC_CHARSET</summary>
MAC_CHARSET = 77,
/// <summary>The BALTIC_CHARSET</summary>
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;
}
}
}

View File

@ -21,25 +21,25 @@ namespace Vanara.PInvoke
[Flags] [Flags]
public enum BorderFlags : uint public enum BorderFlags : uint
{ {
BF_LEFT = 0x0001, BF_LEFT = 0x0001,
BF_TOP = 0x0002, BF_TOP = 0x0002,
BF_RIGHT = 0x0004, BF_RIGHT = 0x0004,
BF_BOTTOM = 0x0008, BF_BOTTOM = 0x0008,
BF_TOPLEFT = (BF_TOP | BF_LEFT), BF_TOPLEFT = (BF_TOP | BF_LEFT),
BF_TOPRIGHT = (BF_TOP | BF_RIGHT), BF_TOPRIGHT = (BF_TOP | BF_RIGHT),
BF_BOTTOMLEFT = (BF_BOTTOM | BF_LEFT), BF_BOTTOMLEFT = (BF_BOTTOM | BF_LEFT),
BF_BOTTOMRIGHT = (BF_BOTTOM | BF_RIGHT), BF_BOTTOMRIGHT = (BF_BOTTOM | BF_RIGHT),
BF_RECT = (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM), BF_RECT = (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM),
BF_DIAGONAL = 0x0010, BF_DIAGONAL = 0x0010,
BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL | BF_TOP | BF_RIGHT), BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL | BF_TOP | BF_RIGHT),
BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL | BF_TOP | BF_LEFT), BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL | BF_TOP | BF_LEFT),
BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL | BF_BOTTOM | BF_LEFT), BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL | BF_BOTTOM | BF_LEFT),
BF_DIAGONAL_ENDBOTTOMRIGHT = (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT), BF_DIAGONAL_ENDBOTTOMRIGHT = (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT),
BF_MIDDLE = 0x0800, BF_MIDDLE = 0x0800,
BF_SOFT = 0x1000, BF_SOFT = 0x1000,
BF_ADJUST = 0x2000, BF_ADJUST = 0x2000,
BF_FLAT = 0x4000, BF_FLAT = 0x4000,
BF_MONO = 0x8000, BF_MONO = 0x8000,
} }
[PInvokeData("WinUser.h")] [PInvokeData("WinUser.h")]
@ -50,14 +50,14 @@ namespace Vanara.PInvoke
BDR_SUNKENOUTER = 0x0002, BDR_SUNKENOUTER = 0x0002,
BDR_RAISEDINNER = 0x0004, BDR_RAISEDINNER = 0x0004,
BDR_SUNKENINNER = 0x0008, BDR_SUNKENINNER = 0x0008,
BDR_OUTER = (BDR_RAISEDOUTER | BDR_SUNKENOUTER), BDR_OUTER = (BDR_RAISEDOUTER | BDR_SUNKENOUTER),
BDR_INNER = (BDR_RAISEDINNER | BDR_SUNKENINNER), BDR_INNER = (BDR_RAISEDINNER | BDR_SUNKENINNER),
BDR_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), BDR_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER),
BDR_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), BDR_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER),
EDGE_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER), EDGE_RAISED = (BDR_RAISEDOUTER | BDR_RAISEDINNER),
EDGE_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER), EDGE_SUNKEN = (BDR_SUNKENOUTER | BDR_SUNKENINNER),
EDGE_ETCHED = (BDR_SUNKENOUTER | BDR_RAISEDINNER), EDGE_ETCHED = (BDR_SUNKENOUTER | BDR_RAISEDINNER),
EDGE_BUMP = (BDR_RAISEDOUTER | BDR_SUNKENINNER), EDGE_BUMP = (BDR_RAISEDOUTER | BDR_SUNKENINNER),
} }
/// <summary> /// <summary>
@ -263,6 +263,83 @@ namespace Vanara.PInvoke
SWP_SHOWWINDOW = 0x0040, SWP_SHOWWINDOW = 0x0040,
} }
/// <summary>Color index used to get a system color from <see cref="GetSysColor"/>.</summary>
public enum SystemColorIndex
{
/// <summary>Scroll bar gray area.</summary>
COLOR_SCROLLBAR = 0,
/// <summary>Desktop.</summary>
COLOR_BACKGROUND = 1,
/// <summary>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.</summary>
COLOR_ACTIVECAPTION = 2,
/// <summary>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.</summary>
COLOR_INACTIVECAPTION = 3,
/// <summary>Menu background. The associated foreground color is COLOR_MENUTEXT.</summary>
COLOR_MENU = 4,
/// <summary>Window background. The associated foreground colors are COLOR_WINDOWTEXT and COLOR_HOTLITE.</summary>
COLOR_WINDOW = 5,
/// <summary>Window frame.</summary>
COLOR_WINDOWFRAME = 6,
/// <summary>Text in menus. The associated background color is COLOR_MENU.</summary>
COLOR_MENUTEXT = 7,
/// <summary>Text in windows. The associated background color is COLOR_WINDOW.</summary>
COLOR_WINDOWTEXT = 8,
/// <summary>Text in caption, size box, and scroll bar arrow box. The associated background color is COLOR_ACTIVECAPTION.</summary>
COLOR_CAPTIONTEXT = 9,
/// <summary>Active window border.</summary>
COLOR_ACTIVEBORDER = 10,
/// <summary>Inactive window border.</summary>
COLOR_INACTIVEBORDER = 11,
/// <summary>Background color of multiple document interface (MDI) applications.</summary>
COLOR_APPWORKSPACE = 12,
/// <summary>Item(s) selected in a control. The associated foreground color is COLOR_HIGHLIGHTTEXT.</summary>
COLOR_HIGHLIGHT = 13,
/// <summary>Text of item(s) selected in a control. The associated background color is COLOR_HIGHLIGHT.</summary>
COLOR_HIGHLIGHTTEXT = 14,
/// <summary>Face color for three-dimensional display elements and for dialog box backgrounds. The associated foreground color is COLOR_BTNTEXT.</summary>
COLOR_BTNFACE = 15,
/// <summary>Shadow color for three-dimensional display elements (for edges facing away from the light source).</summary>
COLOR_BTNSHADOW = 16,
/// <summary>Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color.</summary>
COLOR_GRAYTEXT = 17,
/// <summary>Text on push buttons. The associated background color is COLOR_BTNFACE.</summary>
COLOR_BTNTEXT = 18,
/// <summary>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.</summary>
COLOR_INACTIVECAPTIONTEXT = 19,
/// <summary>Highlight color for three-dimensional display elements (for edges facing the light source.)</summary>
COLOR_BTNHIGHLIGHT = 20,
/// <summary>Dark shadow for three-dimensional display elements.</summary>
COLOR_3DDKSHADOW = 21,
/// <summary>Light color for three-dimensional display elements (for edges facing the light source.)</summary>
COLOR_3DLIGHT = 22,
/// <summary>Text color for tooltip controls. The associated background color is COLOR_INFOBK.</summary>
COLOR_INFOTEXT = 23,
/// <summary>Background color for tooltip controls. The associated foreground color is COLOR_INFOTEXT.</summary>
COLOR_INFOBK = 24,
/// <summary>Item(s) selected in a control. The associated foreground color is COLOR_HIGHLIGHTTEXT.</summary>
COLOR_HOTLIGHT = 26,
/// <summary>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.</summary>
COLOR_GRADIENTACTIVECAPTION = 27,
/// <summary>Right side color in the color gradient of an inactive window's title bar. COLOR_INACTIVECAPTION specifies the left side color.</summary>
COLOR_GRADIENTINACTIVECAPTION = 28,
/// <summary>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.</summary>
COLOR_MENUHILIGHT = 29,
/// <summary>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.</summary>
COLOR_MENUBAR = 30,
/// <summary>Desktop.</summary>
COLOR_DESKTOP = COLOR_BACKGROUND,
/// <summary>Face color for three-dimensional display elements and for dialog box backgrounds.</summary>
COLOR_3DFACE = COLOR_BTNFACE,
/// <summary>Shadow color for three-dimensional display elements (for edges facing away from the light source).</summary>
COLOR_3DSHADOW = COLOR_BTNSHADOW,
/// <summary>Highlight color for three-dimensional display elements (for edges facing the light source.)</summary>
COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT,
/// <summary>Highlight color for three-dimensional display elements (for edges facing the light source.)</summary>
COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT,
/// <summary>Highlight color for three-dimensional display elements (for edges facing the light source.)</summary>
COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT,
}
/// <summary>Flags used for <see cref="GetWindowLong"/> and <see cref="SetWindowLong"/> methods to retrieve information about a window.</summary> /// <summary>Flags used for <see cref="GetWindowLong"/> and <see cref="SetWindowLong"/> methods to retrieve information about a window.</summary>
[Flags] [Flags]
public enum WindowLongFlags public enum WindowLongFlags
@ -334,6 +411,21 @@ namespace Vanara.PInvoke
[System.Security.SecurityCritical] [System.Security.SecurityCritical]
public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref RECT lpRect); public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref RECT lpRect);
/// <summary>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.</summary>
/// <param name="nIndex">The display element whose color is to be retrieved.</param>
/// <returns>The function returns the red, green, blue (RGB) color value of the given element.
/// <para>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.</para></returns>
[PInvokeData("WinUser.h", MSDNShortId = "ms724371")]
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
public static extern COLORREF GetSysColor(SystemColorIndex nIndex);
/// <summary>The GetSysColorBrush function retrieves a handle identifying a logical brush that corresponds to the specified color index.</summary>
/// <param name="nIndex">A color index. This value corresponds to the color used to paint one of the window elements. See GetSysColor for system color index values.</param>
/// <returns>he return value identifies a logical brush if the nIndex parameter is supported by the current platform. Otherwise, it returns NULL.</returns>
[PInvokeData("WinUser.h", MSDNShortId = "dd144927")]
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
public static extern IntPtr GetSysColorBrush(SystemColorIndex nIndex);
/// <summary> /// <summary>
/// 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. /// 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.
/// </summary> /// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,9 @@ namespace Vanara.PInvoke
public static partial class UxTheme public static partial class UxTheme
{ {
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)] [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)] [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);
} }
} }

View File

@ -16,7 +16,7 @@ namespace Vanara.Drawing
static BufferedPaint() { BufferedPaintInit(); } static BufferedPaint() { BufferedPaintInit(); }
public delegate int GetDuration<in TState>(TState oldState, TState newState); public delegate uint GetDuration<in TState>(TState oldState, TState newState);
public delegate void PaintAction<in TState, in TParam>(Graphics graphics, Rectangle bounds, TState currentState, TParam data); public delegate void PaintAction<in TState, in TParam>(Graphics graphics, Rectangle bounds, TState currentState, TParam data);

View File

@ -13,22 +13,22 @@ namespace Vanara.Extensions
{ {
public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins) public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins)
{ {
RECT rc;
using (var hdc = new SafeDCHandle(dc)) 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(rnd.GetSafeHandle(), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out var dwDuration);
GetThemeTransitionDuration(new SafeThemeHandle(rnd.Handle, false), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out dwDuration);
return dwDuration; return dwDuration;
} }
public static int[,] GetTransitionMatrix(this VisualStyleRenderer rnd) 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; if (res == null || res.Length == 0) return null;
var dim = res[0]; var dim = res[0];
var ret = new int[dim, dim]; var ret = new int[dim, dim];
@ -38,10 +38,7 @@ namespace Vanara.Extensions
return ret; return ret;
} }
public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) => IsThemePartDefined(rnd.GetSafeHandle(), part, state);
{
return IsThemePartDefined(new SafeThemeHandle(rnd.Handle, false), part, state);
}
/// <summary> /// <summary>
/// Sets the state of the <see cref="VisualStyleRenderer"/>. /// Sets the state of the <see cref="VisualStyleRenderer"/>.
@ -68,10 +65,12 @@ namespace Vanara.Extensions
/// <param name="window">The window.</param> /// <param name="window">The window.</param>
/// <param name="attr">The attributes to apply or disable.</param> /// <param name="attr">The attributes to apply or disable.</param>
/// <param name="enable">if set to <c>true</c> enable the attribute, otherwise disable it.</param> /// <param name="enable">if set to <c>true</c> enable the attribute, otherwise disable it.</param>
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) { } catch (EntryPointNotFoundException) { }
} }
private static SafeThemeHandle GetSafeHandle(this VisualStyleRenderer rnd) => new SafeThemeHandle(rnd.Handle, false);
} }
} }

View File

@ -139,7 +139,7 @@ namespace Vanara.Extensions
using (new SafeDCObjectHandle(memoryHdc, font?.ToHfont() ?? IntPtr.Zero)) using (new SafeDCObjectHandle(memoryHdc, font?.ToHfont() ?? IntPtr.Zero))
{ {
// Draw glowing text // 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; if (color != null) dttOpts.TextColor = color.Value;
var textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); 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); DrawThemeTextEx(ht, memoryHdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref textBounds, ref dttOpts);
@ -156,8 +156,8 @@ namespace Vanara.Extensions
/// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param> /// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param>
/// <param name="text">The text to draw.</param> /// <param name="text">The text to draw.</param>
/// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags"/> values.</param> /// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags"/> values.</param>
/// <param name="options">The <see cref="DrawThemeTextOptions"/> .</param> /// <param name="options">The <see cref="DTTOPTS"/> .</param>
public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, TextFormatFlags flags, ref DrawThemeTextOptions options) 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 rc = new RECT(bounds);
var ht = new SafeThemeHandle(rnd.Handle, false); var ht = new SafeThemeHandle(rnd.Handle, false);

View File

@ -35,7 +35,7 @@ namespace Vanara.Windows.Forms
public void DrawBackground(IDeviceContext graphics, int partId, int stateId, Rectangle bounds, Rectangle clipRect) public void DrawBackground(IDeviceContext graphics, int partId, int stateId, Rectangle bounds, Rectangle clipRect)
{ {
var b = new RECT(bounds); 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)) using (var hdc = new SafeDCHandle(graphics))
DrawThemeBackgroundEx(hTheme, hdc, partId, stateId, ref b, o); DrawThemeBackgroundEx(hTheme, hdc, partId, stateId, ref b, o);
} }
@ -46,10 +46,10 @@ namespace Vanara.Windows.Forms
DrawThemeParentBackground(new HandleRef(childWindow, childWindow.Handle), hdc, bounds); 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 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 (var hdc = new SafeDCHandle(graphics))
using (new SafeDCObjectHandle(hdc, font?.ToHfont() ?? IntPtr.Zero)) using (new SafeDCObjectHandle(hdc, font?.ToHfont() ?? IntPtr.Zero))
DrawThemeTextEx(hTheme, hdc, partId, stateId, text, text.Length, (DrawTextFlags)fmt, ref b, ref dt); 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); RECT b = new RECT(bounds);
using (var hdc = new SafeDCHandle(graphics)) using (var hdc = new SafeDCHandle(graphics))
{ {
RECT rc; if (GetThemeBackgroundContentRect(hTheme, hdc, partId, stateId, ref b, out RECT rc).Succeeded) return rc;
if (0 == GetThemeBackgroundContentRect(hTheme, hdc, partId, stateId, ref b, out rc)) return rc;
} }
return null; return null;
} }
@ -70,30 +69,26 @@ namespace Vanara.Windows.Forms
{ {
using (var hdc = new SafeDCHandle(graphics)) using (var hdc = new SafeDCHandle(graphics))
{ {
IntPtr hBmp; if (GetThemeBitmap(hTheme, hdc, partId, stateId, propId, 0, out IntPtr hBmp).Succeeded) return Image.FromHbitmap(hBmp);
if (0 == GetThemeBitmap(hTheme, hdc, partId, stateId, propId, 0, out hBmp)) return Image.FromHbitmap(hBmp);
} }
return null; return null;
} }
public bool? GetBool(int partId, int stateId, int propId) public bool? GetBool(int partId, int stateId, int propId)
{ {
bool b; if (GetThemeBool(hTheme, partId, stateId, propId, out bool b).Succeeded) return b;
if (0 == GetThemeBool(hTheme, partId, stateId, propId, out b)) return b;
return null; return null;
} }
public Color? GetColor(int partId, int stateId, int propId) public Color? GetColor(int partId, int stateId, int propId)
{ {
int cr; if (GetThemeColor(hTheme, partId, stateId, propId, out var cr).Succeeded) return cr;
if (0 == GetThemeColor(hTheme, partId, stateId, propId, out cr)) return ColorTranslator.FromWin32(cr);
return null; return null;
} }
public int? GetEnumValue(int partId, int stateId, int propId) public int? GetEnumValue(int partId, int stateId, int propId)
{ {
int i; if (GetThemeEnumValue(hTheme, partId, stateId, propId, out int i).Succeeded) return i;
if (0 == GetThemeEnumValue(hTheme, partId, stateId, propId, out i)) return i;
return null; return null;
} }
@ -101,7 +96,7 @@ namespace Vanara.Windows.Forms
{ {
const int sbLen = 1024; const int sbLen = 1024;
var sb = new StringBuilder(sbLen); 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; return null;
} }
@ -109,23 +104,20 @@ namespace Vanara.Windows.Forms
{ {
using (var hdc = new SafeDCHandle(graphics)) using (var hdc = new SafeDCHandle(graphics))
{ {
LOGFONT f; if (GetThemeFont(hTheme, hdc, partId, stateId, propId, out LOGFONT f).Succeeded) return f.ToFont();
if (0 == GetThemeFont(hTheme, hdc, partId, stateId, propId, out f)) return f.ToFont();
} }
return null; return null;
} }
public int? GetInt(int partId, int stateId, int propId) public int? GetInt(int partId, int stateId, int propId)
{ {
int i; if (GetThemeInt(hTheme, partId, stateId, propId, out int i).Succeeded) return i;
if (0 == GetThemeInt(hTheme, partId, stateId, propId, out i)) return i;
return null; return null;
} }
public int? GetSysInt(int propId) public int? GetSysInt(int propId)
{ {
int i; if (GetThemeSysInt(hTheme, propId, out int i).Succeeded) return i;
if (0 == GetThemeSysInt(hTheme, propId, out i)) return i;
return null; return null;
} }
@ -135,9 +127,8 @@ namespace Vanara.Windows.Forms
{ {
using (var hdc = new SafeDCHandle(graphics)) using (var hdc = new SafeDCHandle(graphics))
{ {
RECT rc; if (GetThemeMargins(hTheme, hdc, partId, stateId, propId, null, out MARGINS m).Succeeded)
if (0 == GetThemeMargins(hTheme, hdc, partId, stateId, propId, IntPtr.Zero, out rc)) return new Padding(m.cxLeftWidth, m.cyTopHeight, m.cxRightWidth, m.cyBottomHeight);
return new Padding(rc.left, rc.top, rc.right, rc.bottom);
} }
return null; return null;
} }
@ -146,8 +137,7 @@ namespace Vanara.Windows.Forms
{ {
using (var hdc = new SafeDCHandle(graphics)) using (var hdc = new SafeDCHandle(graphics))
{ {
int i; if (GetThemeMetric(hTheme, hdc, partId, stateId, propId, out int i).Succeeded) return i;
if (0 == GetThemeMetric(hTheme, hdc, partId, stateId, propId, out i)) return i;
} }
return null; return null;
} }
@ -250,7 +240,7 @@ namespace Vanara.Windows.Forms
o = GetFilename(partId, stateId, propId); o = GetFilename(partId, stateId, propId);
break; break;
case PropertyType.Size: case PropertyType.Size:
o = GetPartSize(graphics, partId, stateId, null, (ThemeSize)propId); o = GetPartSize(graphics, partId, stateId, null, (THEMESIZE)propId);
break; break;
case PropertyType.Position: case PropertyType.Position:
o = GetPosition(partId, stateId, propId); o = GetPosition(partId, stateId, propId);
@ -280,55 +270,47 @@ namespace Vanara.Windows.Forms
return o; 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)) using (var hdc = new SafeDCHandle(graphics))
{ {
Size sz; if (GetThemePartSize(hTheme, hdc, partId, stateId, destRect, themeSize, out var sz).Succeeded)
if (0 != GetThemePartSize(hTheme, hdc, partId, stateId, destRect, themeSize, out sz)) return sz;
return null; return null;
return sz;
} }
} }
public Point? GetPosition(int partId, int stateId, int propId) public Point? GetPosition(int partId, int stateId, int propId)
{ {
Point i; if (GetThemePosition(hTheme, partId, stateId, propId, out Point i).Succeeded) return i;
if (0 == GetThemePosition(hTheme, partId, stateId, propId, out i)) return i;
return null; return null;
} }
public int GetPropertyOrigin(int partId, int stateId, int propId) public int GetPropertyOrigin(int partId, int stateId, int propId)
{ {
ThemePropertyOrigin po; GetThemePropertyOrigin(hTheme, partId, stateId, propId, out PROPERTYORIGIN po);
GetThemePropertyOrigin(hTheme, partId, stateId, propId, out po);
return (int)po; return (int)po;
} }
public Rectangle? GetRect(int partId, int stateId, int propId) public Rectangle? GetRect(int partId, int stateId, int propId)
{ {
RECT rc; if (GetThemeRect(hTheme, partId, stateId, propId, out RECT rc).Succeeded) return rc;
if (0 == GetThemeRect(hTheme, partId, stateId, propId, out rc)) return rc;
return null; return null;
} }
public byte[] GetDiskStream(SafeLibraryHandle hInst, int partId, int stateId, int propId) public byte[] GetDiskStream(SafeLibraryHandle hInst, int partId, int stateId, int propId)
{ {
byte[] bytes; var r = GetThemeStream(hTheme, partId, stateId, propId, out byte[] bytes, out int bLen, hInst);
int bLen; if (r.Succeeded) return bytes;
var r = GetThemeStream(hTheme, partId, stateId, propId, out bytes, out bLen, hInst); if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
if (r == 0) return bytes;
if ((uint)r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
return null; return null;
} }
public byte[] GetStream(int partId, int stateId, int propId) public byte[] GetStream(int partId, int stateId, int propId)
{ {
byte[] bytes; var r = GetThemeStream(hTheme, partId, stateId, propId, out byte[] bytes, out int bLen, IntPtr.Zero);
int bLen; if (r.Succeeded) return bytes;
var r = GetThemeStream(hTheme, partId, stateId, propId, out bytes, out bLen, IntPtr.Zero); if (r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
if (r == 0) return bytes;
if ((uint)r != 0x80070490) throw new InvalidOperationException("Bad GetThemeStream");
return null; return null;
} }
@ -336,15 +318,14 @@ namespace Vanara.Windows.Forms
{ {
const int sbLen = 1024; const int sbLen = 1024;
var sb = new StringBuilder(sbLen); 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 sb.ToString();
return null; 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 var dur);
GetThemeTransitionDuration(hTheme, partId, fromStateId, toStateId, propId, out dur);
return dur; return dur;
} }