Added more functions from UxTheme.h

pull/10/head
David Hall 2017-12-24 10:25:05 -07:00
parent 13af3cd273
commit 1bfe3bde67
4 changed files with 370 additions and 47 deletions

View File

@ -2,8 +2,10 @@
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32.SafeHandles;
using static Vanara.PInvoke.Gdi32;
using static Vanara.PInvoke.User32_Gdi;
// ReSharper disable FieldCanBeMadeReadOnly.Global
// ReSharper disable InconsistentNaming
@ -80,6 +82,27 @@ namespace Vanara.PInvoke
NonClient = 2
}
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,
}
public enum TextShadowType
{
/// <summary>No shadow will be drawn.</summary>
@ -154,56 +177,173 @@ namespace Vanara.PInvoke
NoMirrorHelp = 0x00000008
}
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int CloseThemeData(IntPtr hTheme);
public static extern HRESULT CloseThemeData(IntPtr hTheme);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int DrawThemeBackground(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, PRECT pClipRect);
public static extern HRESULT DrawThemeBackground(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, PRECT pClipRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int 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, DrawThemeBackgroundOptions opts);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int DrawThemeIcon(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, IntPtr himl, int iImageIndex);
public static extern HRESULT DrawThemeEdge(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pDestRect, BorderStyles3D uEdge, BorderFlags uFlags, out RECT pContentRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int DrawThemeParentBackground(HandleRef hwnd, SafeDCHandle hdc, PRECT pRect);
public static extern HRESULT DrawThemeIcon(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, IntPtr himl, int iImageIndex);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int DrawThemeParentBackgroundEx(HandleRef hwnd, SafeDCHandle hdc, DrawThemeParentBackgroundFlags dwFlags, PRECT pRect);
public static extern HRESULT DrawThemeParentBackground(HandleRef hwnd, SafeDCHandle hdc, PRECT pRect);
[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")]
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern int DrawThemeText(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int textLength, DrawTextFlags textFlags, int textFlags2, ref RECT pRect);
public static extern HRESULT DrawThemeText(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int textLength, DrawTextFlags textFlags, int textFlags2, ref RECT pRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
[System.Security.SecurityCritical]
public static extern int DrawThemeTextEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int iCharCount, DrawTextFlags dwFlags, ref RECT pRect, ref DrawThemeTextOptions pOptions);
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)]
public static extern int GetThemeBackgroundContentRect(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pBoundingRect, out RECT pContentRect);
[System.Security.SecurityCritical]
public static extern HRESULT EnableThemeDialogTexture(HandleRef hwnd, ThemeDialogTextureFlags dwFlags);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeBitmap(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, int dwFlags, out IntPtr phBitmap);
[System.Security.SecurityCritical]
public static extern HRESULT EnableTheming([MarshalAs(UnmanagedType.Bool)] bool fEnable);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeBool(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, [MarshalAs(UnmanagedType.Bool)] out bool pfVal);
[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 int GetThemeColor(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int pColor);
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;
}
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeEnumValue(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int piVal);
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
{
/// <summary>Specifies that the non-client areas of application windows have visual styles applied.</summary>
STAP_ALLOW_NONCLIENT = (1U << 0),
/// <summary>Specifies that controls in application windows have visual styles applied.</summary>
STAP_ALLOW_CONTROLS = (1U << 1),
/// <summary>Specifies that all web content displayed in an application is rendered using visual styles.</summary>
STAP_ALLOW_WEBCONTENT = (1U << 2),
}
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern ThemeAppProperties GetThemeAppProperties();
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeBackgroundContentRect(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pBoundingRect, out RECT pContentRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeBackgroundExtent(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pContentRect, out RECT pExtentRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeBackgroundRegion(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pRect, out IntPtr pRegion);
[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 int GetThemeFilename(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref System.Text.StringBuilder pszBuff, int buffLength);
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 int GetThemeInt(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int piVal);
public static extern HRESULT GetThemeEnumValue(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int piVal);
[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);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeInt(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int piVal);
public static int[] GetThemeIntList(SafeThemeHandle hTheme, int partId, int stateId, int propId)
{
@ -227,30 +367,46 @@ namespace Vanara.PInvoke
}
}
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[System.Security.SecurityCritical]
public static extern int 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, IntPtr prc, out RECT pMargins);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeMetric(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, out int piVal);
[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);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemePosition(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out Point piVal);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemePropertyOrigin(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out ThemePropertyOrigin pOrigin);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetThemeRect(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out RECT pRect);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
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);
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeMetric(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, out int piVal);
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)]
public static extern int GetThemePartSize(SafeThemeHandle hTheme, SafeDCHandle hdc, int part, int state, PRECT pRect, ThemeSize eSize, out Size size);
[return: [MarshalAs(UnmanagedType.Bool)]]
public static extern bool GetThemeSysBool(SafeThemeHandle hTheme, int iBoolID);
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemePosition(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out Point piVal);
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemePropertyOrigin(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out ThemePropertyOrigin pOrigin);
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeRect(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out RECT pRect);
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int 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);
[DllImport(Lib.UxTheme, ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern int GetThemeString(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref System.Text.StringBuilder themeString, int themeStringLength);
public static extern COLORREF GetThemeSysColor(SafeThemeHandle hTheme, int iColorID);
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern int GetThemeSysInt(SafeThemeHandle hTheme, int iIntID, out int piVal);

View File

@ -0,0 +1,35 @@
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class UxTheme
{
/// <summary>Must be called on a window to use the UpdatePanningFeedback method for boundary feedback.</summary>
/// <param name="hwnd">A handle to the window that will have boundary feedback on it.</param>
/// <returns>Indicates whether the function was successful.</returns>
[PInvokeData("UxTheme.h", MinClient = PInvokeClient.Windows7)]
[DllImport(Lib.UxTheme, ExactSpelling = true, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BeginPanningFeedback(HandleRef hwnd);
/// <summary>Initializes the window position information for window panning.</summary>
/// <param name="hwnd">A handle to the window to end boundary feedback on.</param>
/// <param name="fAnimateBack">Indicates whether the window positioning reset should incorporate a smooth animation.</param>
/// <returns>Indicates whether the function succeeded. Returns TRUE on success; otherwise, returns FALSE.</returns>
[PInvokeData("UxTheme.h", MinClient = PInvokeClient.Windows7)]
[DllImport(Lib.UxTheme, ExactSpelling = true, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndPanningFeedback(HandleRef hwnd, [MarshalAs(UnmanagedType.Bool)] bool fAnimateBack);
/// <summary>Triggers repositioning on a window's position when a user pans past a boundary.</summary>
/// <param name="hwnd">A handle to the window that will have boundary feedback on it.</param>
/// <param name="lTotalOverpanOffsetX">Indicates how far past the horizontal end of the pannable region the pan has gone.</param>
/// <param name="lTotalOverpanOffsetY">Indicates how far past the vertical end of the pannable region the pan has gone.</param>
/// <param name="fInInertia">A flag indicating whether the boundary feedback incorporates inertia.</param>
/// <returns>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, use the GetLastError function.</returns>
[PInvokeData("UxTheme.h", MinClient = PInvokeClient.Windows7)]
[DllImport(Lib.UxTheme, ExactSpelling = true, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdatePanningFeedback(HandleRef hwnd, int lTotalOverpanOffsetX, int lTotalOverpanOffsetY, [MarshalAs(UnmanagedType.Bool)] bool fInInertia);
}
}

View File

@ -11,94 +11,216 @@ namespace Vanara.PInvoke
{
public static partial class UxTheme
{
/// <summary>Used in the BP_ANIMATIONPARAMS structure to declare animation options.</summary>
[PInvokeData("UxTheme.h")]
[Flags]
public enum BP_ANIMATIONSTYLE
{
/// <summary>No animation. Not implemented in Windows Vista.</summary>
BPAS_NONE,
/// <summary>Linear fade animation.</summary>
BPAS_LINEAR,
/// <summary>Cubic fade animation. Not implemented in Windows Vista.</summary>
BPAS_CUBIC,
/// <summary>Sinusoid fade animation. Not implemented in Windows Vista.</summary>
BPAS_SINE
}
/// <summary>Specifies the format of the buffer. Used by BeginBufferedAnimation and BeginBufferedPaint.</summary>
[PInvokeData("UxTheme.h")]
public enum BP_BUFFERFORMAT
{
/// <summary>Compatible bitmap. The number of bits per pixel is based on the color format of the device associated with the HDC specified with BeginBufferedPaint or BeginBufferedAnimation—typically, this is the display device.</summary>
BPBF_COMPATIBLEBITMAP,
/// <summary>Bottom-up device-independent bitmap. The origin of the bitmap is the lower-left corner. Uses 32 bits per pixel.</summary>
BPBF_DIB,
/// <summary>Top-down device-independent bitmap. The origin of the bitmap is the upper-left corner. Uses 32 bits per pixel.</summary>
BPBF_TOPDOWNDIB,
/// <summary>Top-down, monochrome, device-independent bitmap. Uses 1 bit per pixel.</summary>
BPBF_TOPDOWNMONODIB
}
/// <summary>Used in BP_PAINTPARAMS</summary>
[PInvokeData("UxTheme.h")]
[Flags]
public enum BufferedPaintParamsFlags
{
/// <summary>No flag.</summary>
BPPF_NONE = 0,
/// <summary>Initialize the buffer to ARGB = {0, 0, 0, 0} during BeginBufferedPaint. This erases the previous contents of the buffer.</summary>
BPPF_ERASE = 1,
/// <summary>Do not apply the clip region of the target DC to the double buffer. If this flag is not set and if the target DC is a window DC, then clipping due to overlapping windows is applied to the double buffer.</summary>
BPPF_NOCLIP = 2,
/// <summary>A non-client DC is being used.</summary>
BPPF_NONCLIENT = 4,
}
/// <summary>Begins a buffered animation operation. The animation consists of a cross-fade between the contents of two buffers over a specified period of time.</summary>
/// <param name="hwnd">A handle to the window in which the animations play.</param>
/// <param name="hdcTarget">A handle of the target DC on which the buffer is animated.</param>
/// <param name="rcTarget">A pointer to a structure that specifies the area of the target DC in which to draw.</param>
/// <param name="dwFormat">The format of the buffer.</param>
/// <param name="pPaintParams">A pointer to a structure that defines the paint operation parameters. This value can be NULL.</param>
/// <param name="pAnimationParams">A pointer to a structure that defines the animation operation parameters.</param>
/// <param name="phdcFrom">When this function returns, this value points to the handle of the DC where the application should paint the initial state of the animation, if not NULL.</param>
/// <param name="phdcTo">When this function returns, this value points to the handle of the DC where the application should paint the final state of the animation, if not NULL.</param>
/// <returns>A handle to the buffered paint animation.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr BeginBufferedAnimation(HandleRef hwnd, SafeDCHandle hdcTarget, [In] ref RECT rcTarget, BP_BUFFERFORMAT dwFormat,
[In] BP_PAINTPARAMS pPaintParams, [In] ref BP_ANIMATIONPARAMS pAnimationParams, out IntPtr phdcFrom, out IntPtr phdcTo);
/// <summary>Begins a buffered paint operation.</summary>
/// <param name="hdcTarget">The handle of the target DC on which the buffer will be painted.</param>
/// <param name="prcTarget">A pointer to a RECT structure that specifies the area of the target DC in which to paint.</param>
/// <param name="dwFormat">A member of the BP_BUFFERFORMAT enumeration that specifies the format of the buffer.</param>
/// <param name="pPaintParams">A pointer to a BP_PAINTPARAMS structure that defines the paint operation parameters. This value can be NULL.</param>
/// <param name="phdc">When this function returns, points to the handle of the new device context.</param>
/// <returns>A handle to the buffered paint context. If this function fails, the return value is NULL, and phdc is NULL. To get extended error information, call GetLastError.
/// <para>The returned handle is freed when EndBufferedPaint is called.</para>
/// <para>An application should call BufferedPaintInit on the calling thread before calling BeginBufferedPaint, and BufferedPaintUnInit before the thread is terminated.Failure to call BufferedPaintInit may result in degraded performance due to internal data being initialized and destroyed for each buffered paint operation.</para></returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr BeginBufferedPaint(SafeDCHandle hdcTarget, [In] ref RECT prcTarget, BP_BUFFERFORMAT dwFormat, [In] BP_PAINTPARAMS pPaintParams, out IntPtr phdc);
/// <summary>Clears a specified rectangle in the buffer to ARGB = {0,0,0,0}.</summary>
/// <param name="hBufferedPaint">The handle of the buffered paint context, obtained through BeginBufferedPaint.</param>
/// <param name="prc">A pointer to a RECT structure that specifies the rectangle to clear. Set this parameter to NULL to specify the entire buffer.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT BufferedPaintClear(IntPtr hBufferedPaint, ref RECT prc);
/// <summary>Initialize buffered painting for the current thread.</summary>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT BufferedPaintInit();
/// <summary>Paints the next frame of a buffered paint animation.</summary>
/// <param name="hwnd">Handle to the window in which the animations play.</param>
/// <param name="hdcTarget">Handle of the target DC on which the buffer is animated.</param>
/// <returns>Returns TRUE if the frame has been painted, or FALSE otherwise.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BufferedPaintRenderAnimation(HandleRef hwnd, SafeDCHandle hdcTarget);
/// <summary>Sets the alpha to a specified value in a given rectangle. The alpha controls the amount of transparency applied when blending with the buffer onto the destination target device context (DC).</summary>
/// <param name="hBufferedPaint">The handle of the buffered paint context, obtained through BeginBufferedPaint.</param>
/// <param name="prc">A pointer to a RECT structure that specifies the rectangle in which to set the alpha. Set this parameter to NULL to specify the entire buffer.</param>
/// <param name="alpha">The alpha value to set. The alpha value can range from zero (fully transparent) to 255 (fully opaque).</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT BufferedPaintSetAlpha(IntPtr hBufferedPaint, ref RECT prc, byte alpha);
/// <summary>Stops all buffered animations for the given window.</summary>
/// <param name="hwnd">The handle of the window in which to stop all animations.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT BufferedPaintStopAllAnimations(HandleRef hwnd);
/// <summary>Closes down buffered painting for the current thread. Called once for each call to BufferedPaintInit after calls to BeginBufferedPaint are no longer needed.</summary>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT BufferedPaintUnInit();
/// <summary>Renders the first frame of a buffered animation operation and starts the animation timer.</summary>
/// <param name="hbpAnimation">The handle to the buffered animation context that was returned by BeginBufferedAnimation.</param>
/// <param name="fUpdateTarget">If TRUE, updates the target DC with the animation. If FALSE, the animation is not started, the target DC is not updated, and the hbpAnimation parameter is freed.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT EndBufferedAnimation(IntPtr hbpAnimation, [MarshalAs(UnmanagedType.Bool)] bool fUpdateTarget);
/// <summary>Completes a buffered paint operation and frees the associated buffered paint handle.</summary>
/// <param name="hbp">The handle of the buffered paint context, obtained through BeginBufferedPaint.</param>
/// <param name="fUpdateTarget">TRUE to copy the buffer to the target DC.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT EndBufferedPaint(IntPtr hbp, [MarshalAs(UnmanagedType.Bool)] bool fUpdateTarget);
/// <summary>Retrieves a pointer to the buffer bitmap if the buffer is a device-independent bitmap (DIB).</summary>
/// <param name="hBufferedPaint">The handle of the buffered paint context, obtained through BeginBufferedPaint.</param>
/// <param name="ppbBuffer">When this function returns, contains a pointer to the address of the buffer bitmap pixels.</param>
/// <param name="pcxRow">When this function returns, contains a pointer to the width, in pixels, of the buffer bitmap. This value is not necessarily equal to the buffer width. It may be larger.</param>
/// <returns>Returns S_OK if successful, or an error value otherwise. If an error occurs, ppbBuffer is set to NULL and pcxRow is set to zero.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetBufferedPaintBits(IntPtr hBufferedPaint, out IntPtr ppbBuffer, out int pcxRow);
/// <summary>Gets the paint device context (DC). This is the same value retrieved by BeginBufferedPaint.</summary>
/// <param name="hBufferedPaint">Handle of the buffered paint context, obtained through BeginBufferedPaint.</param>
/// <returns>Handle of the requested DC. This is the same DC that is returned by BeginBufferedPaint. Returns NULL upon failure.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern IntPtr GetBufferedPaintDC(IntPtr hBufferedPaint);
/// <summary>Retrieves the target device context (DC).</summary>
/// <param name="hBufferedPaint">A handle to the buffered paint context obtained through BeginBufferedPaint.</param>
/// <returns>A handle to the requested DC, or NULL otherwise.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern IntPtr GetBufferedPaintTargetDC(IntPtr hBufferedPaint);
/// <summary>Retrieves the target rectangle specified by BeginBufferedPaint.</summary>
/// <param name="hBufferedPaint">Handle to the buffered paint context obtained through BeginBufferedPaint.</param>
/// <param name="prc">When this function returns, contains the requested rectangle.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[PInvokeData("UxTheme.h")]
[DllImport(Lib.UxTheme, ExactSpelling = true)]
public static extern HRESULT GetBufferedPaintTargetRect(IntPtr hBufferedPaint, out RECT prc);
/// <summary>Defines animation parameters for the BP_PAINTPARAMS structure used by BeginBufferedPaint.</summary>
[PInvokeData("UxTheme.h")]
[StructLayout(LayoutKind.Sequential)]
public struct BP_ANIMATIONPARAMS
{
public int cbSize, dwFlags;
/// <summary>The size, in bytes, of this structure.</summary>
public uint cbSize;
/// <summary>Reserved.</summary>
public uint dwFlags;
/// <summary>Animation style.</summary>
public BP_ANIMATIONSTYLE style;
public int dwDuration;
/// <summary>Length of the animation, in milliseconds.</summary>
public uint dwDuration;
public BP_ANIMATIONPARAMS(BP_ANIMATIONSTYLE animStyle, int dur = 0)
/// <summary>Initializes a new instance of the <see cref="BP_ANIMATIONPARAMS"/> struct.</summary>
/// <param name="animStyle">The animation style.</param>
/// <param name="dur">The duration.</param>
public BP_ANIMATIONPARAMS(BP_ANIMATIONSTYLE animStyle, uint dur = 0)
{
cbSize = Marshal.SizeOf(typeof(BP_ANIMATIONPARAMS));
cbSize = (uint)Marshal.SizeOf(typeof(BP_ANIMATIONPARAMS));
dwFlags = 0;
dwDuration = dur;
style = animStyle;
}
public BP_ANIMATIONSTYLE AnimationStyle
{
get => style; set => style = value;
}
public int Duration
{
get => dwDuration; set => dwDuration = value;
}
public static BP_ANIMATIONPARAMS Empty => new BP_ANIMATIONPARAMS { cbSize = Marshal.SizeOf(typeof(BP_ANIMATIONPARAMS)) };
/// <summary>Gets an instance of an empty structure with cbSize set.</summary>
public static BP_ANIMATIONPARAMS Empty => new BP_ANIMATIONPARAMS { cbSize = (uint)Marshal.SizeOf(typeof(BP_ANIMATIONPARAMS)) };
}
/// <summary>Defines paint operation parameters for BeginBufferedPaint.</summary>
/// <seealso cref="System.IDisposable"/>
[PInvokeData("UxTheme.h")]
[StructLayout(LayoutKind.Sequential)]
public class BP_PAINTPARAMS : IDisposable
{
/// <summary>The size, in bytes, of this structure.</summary>
public int cbSize;
/// <summary>One or more of the following values.</summary>
public BufferedPaintParamsFlags Flags;
/// <summary>A pointer to exclusion RECT structure. This rectangle is excluded from the clipping region. May be NULL for no exclusion rectangle.</summary>
public IntPtr prcExclude;
/// <summary>A pointer to BLENDFUNCTION structure, which controls blending by specifying the blending functions for source and destination bitmaps. If NULL, the source buffer is copied to the destination with no blending.</summary>
public IntPtr pBlendFunction;
/// <summary>Initializes a new instance of the <see cref="BP_PAINTPARAMS"/> class.</summary>
/// <param name="flags">The flags.</param>
public BP_PAINTPARAMS(BufferedPaintParamsFlags flags = BufferedPaintParamsFlags.BPPF_NONE)
{
cbSize = Marshal.SizeOf(typeof(BP_PAINTPARAMS));
@ -106,6 +228,8 @@ namespace Vanara.PInvoke
prcExclude = pBlendFunction = IntPtr.Zero;
}
/// <summary>Gets or sets the rectangle that is excluded from the clipping region.</summary>
/// <value>The rectangle.</value>
public Rectangle? Exclude
{
get => prcExclude.ToNullableStructure<Rectangle>();
@ -117,6 +241,8 @@ namespace Vanara.PInvoke
}
}
/// <summary>Gets or sets the blend function.</summary>
/// <value>The blend function.</value>
public BLENDFUNCTION? BlendFunction
{
get => pBlendFunction.ToNullableStructure<BLENDFUNCTION>();
@ -128,15 +254,20 @@ namespace Vanara.PInvoke
}
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (prcExclude != IntPtr.Zero) Marshal.FreeCoTaskMem(prcExclude);
if (pBlendFunction != IntPtr.Zero) Marshal.FreeCoTaskMem(pBlendFunction);
}
/// <summary>Gets an instance of this structure set to define no clipping.</summary>
public static BP_PAINTPARAMS NoClip => new BP_PAINTPARAMS(BufferedPaintParamsFlags.BPPF_NOCLIP);
/// <summary>Gets an instance of this structure set to define clearing the background.</summary>
public static BP_PAINTPARAMS ClearBg => new BP_PAINTPARAMS(BufferedPaintParamsFlags.BPPF_ERASE);
}
}
}
}

View File

@ -52,5 +52,6 @@ DrawThemeTextOptions, WTA_OPTIONS, DrawThemeBackgroundOptions, BP_ANIMATIONPARAM
<ProjectReference Include="..\..\Core\Vanara.Core.csproj" />
<ProjectReference Include="..\Gdi32\Vanara.PInvoke.Gdi32.csproj" />
<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj" />
<ProjectReference Include="..\User32.Gdi\Vanara.PInvoke.User32.Gdi.csproj" />
</ItemGroup>
</Project>