2017-11-27 13:11:20 -05:00
using System ;
using System.ComponentModel ;
using System.Drawing ;
using System.Runtime.InteropServices ;
2017-12-24 12:25:05 -05:00
using System.Text ;
2017-11-27 13:11:20 -05:00
using Microsoft.Win32.SafeHandles ;
using static Vanara . PInvoke . Gdi32 ;
2017-12-24 12:25:05 -05:00
using static Vanara . PInvoke . User32_Gdi ;
2017-11-27 13:11:20 -05:00
// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable InconsistentNaming
// ReSharper disable FieldCanBeMadeReadOnly.Local
namespace Vanara.PInvoke
{
public static partial class UxTheme
{
[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 DrawThemeParentBackgroundFlags
{
None = 0 ,
/// <summary>If set, hdc is assumed to be a window DC, not a client DC.</summary>
DTPB_WINDOWDC = 1 ,
/// <summary>
/// If set, this function sends a WM_CTLCOLORSTATIC message to the parent and uses the brush if one is provided. Otherwise, it uses COLOR_BTNFACE.
/// </summary>
DTPB_USECTLCOLORSTATIC = 2 ,
/// <summary>If set, this function returns S_OK without sending a WM_CTLCOLORSTATIC message if the parent actually painted on WM_ERASEBKGND.</summary>
DTPB_USEERASEBKGND = 4
}
[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
}
public enum DrawThemeTextSystemFonts
{
Caption = 801 ,
SmallCaption = 802 ,
Menu = 803 ,
Status = 804 ,
MessageBox = 805 ,
IconTitle = 806
}
public enum IntegerListProperty
{
TransitionDuration = 6000
}
public enum OpenThemeDataOptions
{
None = 0 ,
/// <summary>Forces drawn images from this theme to stretch to fit the rectangles specified by drawing functions.</summary>
/// <remarks>OTD_FORCE_RECT_SIZING</remarks>
ForceRectSizing = 1 ,
/// <summary>Allows theme elements to be drawn in the non-client area of the window.</summary>
/// <remarks>OTD_NONCLIENT</remarks>
NonClient = 2
}
2017-12-24 12:25:05 -05:00
public enum TA_PROPERTY
{
TAP_FLAGS ,
TAP_TRANSFORMCOUNT ,
TAP_STAGGERDELAY ,
TAP_STAGGERDELAYCAP ,
TAP_STAGGERDELAYFACTOR ,
TAP_ZORDER ,
}
[Flags]
public enum TA_PROPERTY_FLAG
{
TAPF_NONE = 0x0 ,
TAPF_HASSTAGGER = 0x1 ,
TAPF_ISRTLAWARE = 0x2 ,
TAPF_ALLOWCOLLECTION = 0x4 ,
TAPF_HASBACKGROUND = 0x8 ,
TAPF_HASPERSPECTIVE = 0x10 ,
}
2017-11-27 13:11:20 -05:00
public enum TextShadowType
{
/// <summary>No shadow will be drawn.</summary>
/// <remarks>TST_NONE</remarks>
None = 0 ,
/// <summary>The shadow will be drawn to appear detailed underneath text.</summary>
/// <remarks>TST_SINGLE</remarks>
Single = 1 ,
/// <summary>The shadow will be drawn to appear blurred underneath text.</summary>
/// <remarks>TST_CONTINUOUS</remarks>
Continuous = 2
}
public enum ThemePropertyOrigin
{
/// <summary>Property was found in the state section.</summary>
/// <remarks>PO_STATE</remarks>
State = 0 ,
/// <summary>Property was found in the part section.</summary>
/// <remarks>PO_PART</remarks>
Part = 1 ,
/// <summary>Property was found in the class section.</summary>
/// <remarks>PO_CLASS</remarks>
Class = 2 ,
/// <summary>Property was found in the list of global variables.</summary>
/// <remarks>PO_GLOBAL</remarks>
Global = 3 ,
/// <summary>Property was not found.</summary>
/// <remarks>PO_NOTFOUND</remarks>
NotFound = 4
}
public enum ThemeSize
{
/// <summary>Receives the minimum size of a visual style part.</summary>
/// <remarks>TS_MIN</remarks>
Min ,
/// <summary>Receives the size of the visual style part that will best fit the available space.</summary>
/// <remarks>TS_TRUE</remarks>
True ,
/// <summary>Receives the size that the theme manager uses to draw a part.</summary>
/// <remarks>TS_DRAW</remarks>
Draw
}
public enum WindowThemeAttributeType
{
NonClient = 1 ,
}
[Flags]
public enum WindowThemeNonClientAttributes
{
/// <summary>Do Not Draw The Caption (Text)</summary>
NoDrawCaption = 0x00000001 ,
/// <summary>Do Not Draw the Icon</summary>
NoDrawIcon = 0x00000002 ,
/// <summary>Do Not Show the System Menu</summary>
NoSysMenu = 0x00000004 ,
/// <summary>Do Not Mirror the Question mark Symbol</summary>
NoMirrorHelp = 0x00000008
}
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT CloseThemeData ( IntPtr hTheme ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeBackground ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pRect , PRECT pClipRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeBackgroundEx ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pRect , DrawThemeBackgroundOptions opts ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeEdge ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pDestRect , BorderStyles3D uEdge , BorderFlags uFlags , out RECT pContentRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeIcon ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pRect , IntPtr himl , int iImageIndex ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeParentBackground ( HandleRef hwnd , SafeDCHandle hdc , PRECT pRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern HRESULT DrawThemeParentBackgroundEx ( HandleRef hwnd , SafeDCHandle hdc , DrawThemeParentBackgroundFlags dwFlags , PRECT pRect ) ;
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT DrawThemeText ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , string text , int textLength , DrawTextFlags textFlags , int textFlags2 , ref RECT pRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
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
{
/// <summary>Disables background texturing.</summary>
ETDT_DISABLE = 0x00000001 ,
/// <summary>Enables dialog window background texturing. The texturing is defined by a visual style.</summary>
ETDT_ENABLE = 0x00000002 ,
/// <summary>Uses the Tab control texture for the background texture of a dialog window.</summary>
ETDT_USETABTEXTURE = 0x00000004 ,
/// <summary>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).</summary>
ETDT_ENABLETAB = ( ETDT_ENABLE | ETDT_USETABTEXTURE ) ,
/// <summary>Uses the Aero wizard texture for the background texture of a dialog window.</summary>
ETDT_USEAEROWIZARDTABTEXTURE = 0x00000008 ,
/// <summary>ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE.</summary>
ETDT_ENABLEAEROWIZARDTAB = ( ETDT_ENABLE | ETDT_USEAEROWIZARDTABTEXTURE ) ,
/// <summary>ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE.</summary>
ETDT_VALIDBITS = ( ETDT_DISABLE | ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_USEAEROWIZARDTABTEXTURE ) ,
}
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern HRESULT EnableThemeDialogTexture ( HandleRef hwnd , ThemeDialogTextureFlags dwFlags ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern HRESULT EnableTheming ( [ MarshalAs ( UnmanagedType . Bool ) ] bool fEnable ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern HRESULT GetCurrentThemeName ( [ MarshalAs ( UnmanagedType . LPWStr ) ] StringBuilder pszThemeFileName , int dwMaxNameChars , [ MarshalAs ( UnmanagedType . LPWStr ) ] StringBuilder pszColorBuff , int cchMaxColorChars , [ MarshalAs ( UnmanagedType . LPWStr ) ] StringBuilder pszSizeBuff , int cchMaxSizeChars ) ;
[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 ,
}
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[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 ;
}
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeAnimationTransform ( SafeThemeHandle hTheme , int iStoryboardId , int iTargetId , TA_PROPERTY eProperty , IntPtr pvProperty , uint cbSize , out uint pcbSizeOut ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[Flags]
public enum ThemeAppProperties : uint
{
/// <summary>Specifies that the non-client areas of application windows have visual styles applied.</summary>
STAP_ALLOW_NONCLIENT = ( 1 U < < 0 ) ,
/// <summary>Specifies that controls in application windows have visual styles applied.</summary>
STAP_ALLOW_CONTROLS = ( 1 U < < 1 ) ,
/// <summary>Specifies that all web content displayed in an application is rendered using visual styles.</summary>
STAP_ALLOW_WEBCONTENT = ( 1 U < < 2 ) ,
}
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern ThemeAppProperties GetThemeAppProperties ( ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeBackgroundContentRect ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pBoundingRect , out RECT pContentRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeBackgroundExtent ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pContentRect , out RECT pExtentRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeBackgroundRegion ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , ref RECT pRect , out IntPtr pRegion ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeBitmap ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , int iPropId , int dwFlags , out IntPtr phBitmap ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeBool ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , [ MarshalAs ( UnmanagedType . Bool ) ] out bool pfVal ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeColor ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out int pColor ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern HRESULT GetThemeDocumentationProperty ( string pszThemeName , string pszPropertyName , out StringBuilder pszValueBuff , int cchMaxValChars ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeEnumValue ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out int piVal ) ;
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeFilename ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , ref System . Text . StringBuilder pszBuff , int buffLength ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeInt ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out int piVal ) ;
2017-11-27 13:11:20 -05:00
public static int [ ] GetThemeIntList ( SafeThemeHandle hTheme , int partId , int stateId , int propId )
{
if ( Environment . OSVersion . Version . Major < 6 )
{
INTLIST_OLD l ;
if ( 0 ! = GetThemeIntListPreVista ( hTheme , partId , stateId , propId , out l ) )
return null ;
var outlist = new int [ l . iValueCount ] ;
Array . Copy ( l . iValues , outlist , l . iValueCount ) ;
return outlist ;
}
else
{
INTLIST l ;
if ( 0 ! = GetThemeIntList ( hTheme , partId , stateId , propId , out l ) )
return null ;
var outlist = new int [ l . iValueCount ] ;
Array . Copy ( l . iValues , outlist , l . iValueCount ) ;
return outlist ;
}
}
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeMargins ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , int iPropId , IntPtr prc , out RECT pMargins ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeMetric ( SafeThemeHandle hTheme , SafeDCHandle hdc , int iPartId , int iStateId , int iPropId , out int piVal ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemePartSize ( SafeThemeHandle hTheme , SafeDCHandle hdc , int part , int state , PRECT pRect , ThemeSize eSize , out Size size ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemePosition ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out Point piVal ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemePropertyOrigin ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out ThemePropertyOrigin pOrigin ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeRect ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out RECT pRect ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
2017-12-24 12:25:05 -05:00
public static extern HRESULT GetThemeStream ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , [ MarshalAs ( UnmanagedType . LPArray , ArraySubType = UnmanagedType . U1 , SizeParamIndex = 5 ) ] out byte [ ] pvStream , out int cbStream , IntPtr hInst ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeString ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , [ MarshalAs ( UnmanagedType . LPWStr ) ] StringBuilder themeString , int themeStringLength ) ;
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[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 ) ;
2017-11-27 13:11:20 -05:00
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeSysInt ( SafeThemeHandle hTheme , int iIntID , out int piVal ) ;
[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 ) ;
[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 ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsThemeBackgroundPartiallyTransparent ( SafeThemeHandle hTheme , int iPartId , int iStateId ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsThemePartDefined ( SafeThemeHandle hTheme , int iPartId , int iStateId ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern IntPtr OpenThemeData ( HandleRef hWnd , string classList ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern IntPtr OpenThemeDataEx ( HandleRef hWnd , string classList , OpenThemeDataOptions dwFlags ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
[System.Security.SecurityCritical]
public static extern int SetWindowTheme ( HandleRef hWnd , string pszSubAppName , string pszSubIdList ) ;
/// <summary>
/// Sets attributes to control how visual styles are applied to a specified window.
/// </summary>
/// <param name="hWnd">Handle to a window to apply changes to.</param>
/// <param name="wtype">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.</param>
/// <param name="attributes">A pointer that specifies attributes to set. Type is determined by the value of the eAttribute value.</param>
/// <param name="size">Specifies the size, in bytes, of the data pointed to by pvAttribute.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int SetWindowThemeAttribute ( HandleRef hWnd , WindowThemeAttributeType wtype , ref WTA_OPTIONS attributes , int size ) ;
/// <summary>
/// Sets attributes to control how visual styles are applied to a specified window.
/// </summary>
/// <param name="hWnd">Handle to a window to apply changes to.</param>
/// <param name="ncAttrs">A combination of flags that modify window visual style attributes.</param>
/// <param name="activate">if set to <c>true</c> add the flag to the window attributes, otherwise remove the flag.</param>
public static void SetWindowThemeAttribute ( HandleRef hWnd , WindowThemeNonClientAttributes 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 ) ;
}
[DllImport(Lib.UxTheme, ExactSpelling = true)]
private static extern int GetThemeIntList ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out INTLIST pIntList ) ;
[DllImport(Lib.UxTheme, ExactSpelling = true, EntryPoint = "GetThemeIntList")]
private static extern int GetThemeIntListPreVista ( SafeThemeHandle hTheme , int iPartId , int iStateId , int iPropId , out INTLIST_OLD pIntList ) ;
/// <summary>Defines the options for the <see cref="DrawThemeTextEx"/> function.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct DrawThemeTextOptions
{
public int dwSize ;
public DrawThemeTextOptionsMasks dwMasks ;
public int crText ;
public int crBorder ;
public int 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 ;
/// <summary>Initializes a new instance of the <see cref="DrawThemeTextOptions"/> struct.</summary>
/// <param name="shouldBeNull">This value must be specified to initialize. Use null.</param>
public DrawThemeTextOptions ( byte? shouldBeNull ) : this ( )
{
dwSize = Marshal . SizeOf ( typeof ( DrawThemeTextOptions ) ) ;
}
/// <summary>Gets or sets a value that specifies an alternate color property to use when drawing text.</summary>
/// <value>The alternate color of the text.</value>
public Color AlternateColor
{
get = > ColorTranslator . FromWin32 ( iColorPropId ) ; set
{
iColorPropId = ColorTranslator . ToWin32 ( value ) ;
dwMasks | = DrawThemeTextOptionsMasks . ColorProp ;
}
}
/// <summary>Gets or sets an alternate font property to use when drawing text.</summary>
/// <value>The alternate font.</value>
public DrawThemeTextSystemFonts AlternateFont
{
get = > ( DrawThemeTextSystemFonts ) iFontPropId ; set
{
iFontPropId = ( int ) value ;
dwMasks | = DrawThemeTextOptionsMasks . FontProp ;
}
}
/// <summary>
/// Gets or sets a value indicating whether to draw text with antialiased alpha. Use of this flag requires a top-down DIB section. This flag works
/// only if the HDC passed to function DrawThemeTextEx has a top-down DIB section currently selected in it. For more information, see
/// Device-Independent Bitmaps.
/// </summary>
/// <value><c>true</c> if antialiased alpha; otherwise, <c>false</c>.</value>
public bool AntiAliasedAlpha
{
get = > ( dwMasks & DrawThemeTextOptionsMasks . Composited ) = = DrawThemeTextOptionsMasks . Composited ; set = > SetFlag ( DrawThemeTextOptionsMasks . Composited , value ) ;
}
/// <summary>
/// Gets or sets a value indicating whether text will be drawn on top of the shadow and outline effects ( <c>true</c>) or if just the shadow and
/// outline effects will be drawn ( <c>false</c>).
/// </summary>
/// <value><c>true</c> if drawn on top; otherwise, <c>false</c>.</value>
public bool ApplyOverlay
{
get = > fApplyOverlay ; set
{
fApplyOverlay = value ;
dwMasks | = DrawThemeTextOptionsMasks . ApplyOverlay ;
}
}
/// <summary>Gets or sets the color of the outline that will be drawn around the text.</summary>
/// <value>The color of the border.</value>
public Color BorderColor
{
get = > ColorTranslator . FromWin32 ( crBorder ) ; set
{
crBorder = ColorTranslator . ToWin32 ( value ) ;
dwMasks | = DrawThemeTextOptionsMasks . BorderColor ;
}
}
/// <summary>Gets or sets the radius of the outline that will be drawn around the text.</summary>
/// <value>The size of the border.</value>
public int BorderSize
{
get = > iBorderSize ; set
{
iBorderSize = value ;
dwMasks | = DrawThemeTextOptionsMasks . BorderSize ;
}
}
/// <summary>Gets or sets the callback function.</summary>
/// <value>The callback function.</value>
public DrawThemeTextCallback Callback
{
get = > pfnDrawTextCallback ; set
{
pfnDrawTextCallback = value ;
dwMasks | = DrawThemeTextOptionsMasks . Callback ;
}
}
/// <summary>Gets or sets the size of a glow that will be drawn on the background prior to any text being drawn.</summary>
/// <value>The size of the glow.</value>
public int GlowSize
{
get = > iGlowSize ; set
{
iGlowSize = value ;
dwMasks | = DrawThemeTextOptionsMasks . GlowSize ;
}
}
/// <summary>Gets or sets the parameter for callback back function specified by <see cref="Callback"/>.</summary>
/// <value>The parameter.</value>
public IntPtr LParam
{
get = > lParam ; set = > lParam = value ;
}
/// <summary>
/// Gets or sets a value indicating whether the pRect parameter of the <see cref="DrawThemeTextEx"/> function that uses this structure will be used
/// as both an in and an out parameter. After the function returns, the pRect parameter will contain the rectangle that corresponds to the region
/// calculated to be drawn.
/// </summary>
/// <value><c>true</c> if returning the calculated rectangle; otherwise, <c>false</c>.</value>
public bool ReturnCalculatedRectangle
{
get = > ( dwMasks & DrawThemeTextOptionsMasks . CalcRect ) = = DrawThemeTextOptionsMasks . CalcRect ; set = > SetFlag ( DrawThemeTextOptionsMasks . CalcRect , value ) ;
}
/// <summary>Gets or sets the color of the shadow drawn behind the text.</summary>
/// <value>The color of the shadow.</value>
public Color ShadowColor
{
get = > ColorTranslator . FromWin32 ( crShadow ) ; set
{
crShadow = ColorTranslator . ToWin32 ( value ) ;
dwMasks | = DrawThemeTextOptionsMasks . ShadowColor ;
}
}
/// <summary>Gets or sets the amount of offset, in logical coordinates, between the shadow and the text.</summary>
/// <value>The shadow offset.</value>
public Point ShadowOffset
{
get = > new Point ( ptShadowOffset . X , ptShadowOffset . Y ) ; set
{
ptShadowOffset = value ;
dwMasks | = DrawThemeTextOptionsMasks . ShadowOffset ;
}
}
/// <summary>Gets or sets the type of the shadow that will be drawn behind the text.</summary>
/// <value>The type of the shadow.</value>
public TextShadowType ShadowType
{
get = > iTextShadowType ; set
{
iTextShadowType = value ;
dwMasks | = DrawThemeTextOptionsMasks . ShadowType ;
}
}
/// <summary>Gets or sets the color of the text that will be drawn.</summary>
/// <value>The color of the text.</value>
public Color TextColor
{
get = > ColorTranslator . FromWin32 ( crText ) ; set
{
crText = ColorTranslator . ToWin32 ( value ) ;
dwMasks | = DrawThemeTextOptionsMasks . TextColor ;
}
}
/// <summary>Gets an instance with default values set.</summary>
public static DrawThemeTextOptions Default = > new DrawThemeTextOptions ( null ) ;
private void SetFlag ( DrawThemeTextOptionsMasks f , bool value )
{
if ( value ) dwMasks | = f ; else dwMasks & = ~ f ;
}
}
/// <summary>The Options of What Attributes to Add/Remove</summary>
[StructLayout(LayoutKind.Sequential)]
public struct WTA_OPTIONS
{
public WindowThemeNonClientAttributes Flags ;
public int Mask ;
}
[StructLayout(LayoutKind.Sequential)]
private struct INTLIST
{
public int iValueCount ;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 402)]
public int [ ] iValues ;
}
[StructLayout(LayoutKind.Sequential)]
private struct INTLIST_OLD
{
public int iValueCount ;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public int [ ] iValues ;
}
/// <summary>Defines the options for the DrawThemeBackgroundEx function.</summary>
[StructLayout(LayoutKind.Sequential)]
public class DrawThemeBackgroundOptions
{
public int dwSize ;
public int dwFlags ;
public RECT rcClip ;
[Flags]
private enum DrawThemeBackgroundFlags
{
None = 0 ,
/// <summary>The ClipRectangle value is defined.</summary>
ClipRect = 1 ,
/// <summary>Deprecated. Draw transparent and alpha images as solid.</summary>
DrawSolid = 2 ,
/// <summary>Do not draw the border of the part (currently this value is only supported for bgtype=borderfill).</summary>
OmitBorder = 4 ,
/// <summary>Do not draw the content area of the part (currently this value is only supported for bgtype=borderfill).</summary>
OmitContent = 8 ,
/// <summary>Deprecated.</summary>
ComputingRegion = 16 ,
/// <summary>Assume the hdc is mirrored and flip images as appropriate (currently this value is only supported for bgtype=imagefile).</summary>
HasMirroredDC = 32 ,
/// <summary>Do not mirror the output; even in right-to-left (RTL) layout.</summary>
DoNotMirror = 64
}
/// <summary>Initializes a new instance of the <see cref="DrawThemeBackgroundOptions"/> class.</summary>
/// <param name="clipRect">The rectangle to which drawing is clipped.</param>
public DrawThemeBackgroundOptions ( Rectangle ? clipRect )
{
dwSize = Marshal . SizeOf ( this ) ;
ClipRectangle = clipRect ;
}
/// <summary>Gets or sets the bounding rectangle of the clip region.</summary>
/// <value>The clip rectangle.</value>
public Rectangle ? ClipRectangle
{
get
{
Rectangle r = rcClip ;
return r . IsEmpty ? ( Rectangle ? ) null : r ;
}
set
{
rcClip = value ? ? default ( RECT ) ;
SetFlag ( DrawThemeBackgroundFlags . ClipRect , value . HasValue ) ;
}
}
/// <summary>Gets or sets a value indicating whether omit drawing the border.</summary>
/// <value><c>true</c> if omit border; otherwise, <c>false</c>.</value>
public bool OmitBorder { get = > GetFlag ( DrawThemeBackgroundFlags . OmitBorder ) ; set = > SetFlag ( DrawThemeBackgroundFlags . OmitBorder , value ) ; }
/// <summary>Gets or sets a value indicating whether omit drawing the content area of the part.</summary>
/// <value><c>true</c> if omit content area of the part; otherwise, <c>false</c>.</value>
public bool OmitContent { get = > GetFlag ( DrawThemeBackgroundFlags . OmitContent ) ; set = > SetFlag ( DrawThemeBackgroundFlags . OmitContent , value ) ; }
/// <summary>Gets or sets a value indicating the hdc is mirrored and flip images as appropriate.</summary>
/// <value><c>true</c> if mirrored; otherwise, <c>false</c>.</value>
public bool HasMirroredDC { get = > GetFlag ( DrawThemeBackgroundFlags . HasMirroredDC ) ; set = > SetFlag ( DrawThemeBackgroundFlags . HasMirroredDC , value ) ; }
/// <summary>Gets or sets a value indicating whether to mirror the output; even in right-to-left (RTL) layout.</summary>
/// <value><c>true</c> if not mirroring; otherwise, <c>false</c>.</value>
public bool DoNotMirror { get = > GetFlag ( DrawThemeBackgroundFlags . DoNotMirror ) ; set = > SetFlag ( DrawThemeBackgroundFlags . DoNotMirror , value ) ; }
/// <summary>Performs an implicit conversion from <see cref="Rectangle"/> to <see cref="DrawThemeBackgroundOptions"/>.</summary>
/// <param name="clipRectangle">The clipping rectangle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator DrawThemeBackgroundOptions ( Rectangle clipRectangle ) = > new DrawThemeBackgroundOptions ( clipRectangle ) ;
private bool GetFlag ( DrawThemeBackgroundFlags f ) = > ( dwFlags & ( int ) f ) = = ( int ) f ;
private void SetFlag ( DrawThemeBackgroundFlags f , bool value )
{
if ( value ) dwFlags | = ( int ) f ; else dwFlags & = ~ ( int ) f ;
}
}
/// <summary>
/// Represents a safe handle for a token. Use in place of HTOKEN or HANDLE.
/// </summary>
/// <seealso cref="Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid" />
public class SafeThemeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public SafeThemeHandle ( IntPtr hTheme , bool ownsHandle = true ) : base ( ownsHandle )
{
SetHandle ( hTheme ) ;
}
protected override bool ReleaseHandle ( ) = > CloseThemeData ( handle ) = = 0 ;
}
}
}