2017-11-27 13:11:20 -05:00
using System ;
using System.Drawing ;
using System.Runtime.InteropServices ;
using Vanara.Extensions ;
2018-06-27 15:14:43 -04:00
using Vanara.InteropServices ;
2017-11-27 13:11:20 -05:00
using static Vanara . PInvoke . Gdi32 ;
namespace Vanara.PInvoke
{
public static partial class UxTheme
{
2017-12-24 12:25:05 -05:00
/// <summary>Used in the BP_ANIMATIONPARAMS structure to declare animation options.</summary>
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[Flags]
public enum BP_ANIMATIONSTYLE
{
2017-12-24 12:25:05 -05:00
/// <summary>No animation. Not implemented in Windows Vista.</summary>
2017-11-27 13:11:20 -05:00
BPAS_NONE ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Linear fade animation.</summary>
2017-11-27 13:11:20 -05:00
BPAS_LINEAR ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Cubic fade animation. Not implemented in Windows Vista.</summary>
2017-11-27 13:11:20 -05:00
BPAS_CUBIC ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Sinusoid fade animation. Not implemented in Windows Vista.</summary>
2017-11-27 13:11:20 -05:00
BPAS_SINE
}
2017-12-24 12:25:05 -05:00
/// <summary>Specifies the format of the buffer. Used by BeginBufferedAnimation and BeginBufferedPaint.</summary>
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
public enum BP_BUFFERFORMAT
{
2018-11-19 23:18:50 -05:00
/// <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>
2017-11-27 13:11:20 -05:00
BPBF_COMPATIBLEBITMAP ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Bottom-up device-independent bitmap. The origin of the bitmap is the lower-left corner. Uses 32 bits per pixel.</summary>
2017-11-27 13:11:20 -05:00
BPBF_DIB ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Top-down device-independent bitmap. The origin of the bitmap is the upper-left corner. Uses 32 bits per pixel.</summary>
2017-11-27 13:11:20 -05:00
BPBF_TOPDOWNDIB ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Top-down, monochrome, device-independent bitmap. Uses 1 bit per pixel.</summary>
2017-11-27 13:11:20 -05:00
BPBF_TOPDOWNMONODIB
}
2017-12-24 12:25:05 -05:00
/// <summary>Used in BP_PAINTPARAMS</summary>
[PInvokeData("UxTheme.h")]
2017-11-27 13:11:20 -05:00
[Flags]
public enum BufferedPaintParamsFlags
{
2017-12-24 12:25:05 -05:00
/// <summary>No flag.</summary>
2017-11-27 13:11:20 -05:00
BPPF_NONE = 0 ,
2018-11-19 23:18:50 -05:00
/// <summary>
/// Initialize the buffer to ARGB = {0, 0, 0, 0} during BeginBufferedPaint. This erases the previous contents of the buffer.
/// </summary>
2017-11-27 13:11:20 -05:00
BPPF_ERASE = 1 ,
2018-11-19 23:18:50 -05:00
/// <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>
2017-11-27 13:11:20 -05:00
BPPF_NOCLIP = 2 ,
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>A non-client DC is being used.</summary>
2017-11-27 13:11:20 -05:00
BPPF_NONCLIENT = 4 ,
}
2018-06-27 15:14:43 -04:00
/// <summary>
2018-11-19 23:18:50 -05:00
/// Begins a buffered animation operation. The animation consists of a cross-fade between the contents of two buffers over a
/// specified period of time.
2018-06-27 15:14:43 -04:00
/// </summary>
/// <param name="hwnd">
/// <para>Type: <c><c>HWND</c></c></para>
/// <para>A handle to the window in which the animations play.</para>
/// </param>
/// <param name="hdcTarget">
/// <para>Type: <c><c>HDC</c></c></para>
/// <para>A handle of the target DC on which the buffer is animated.</para>
/// </param>
/// <param name="rcTarget">
/// <para>Type: <c>const <c>RECT</c>*</c></para>
/// <para>A pointer to a structure that specifies the area of the target DC in which to draw.</para>
/// </param>
/// <param name="dwFormat">
/// <para>Type: <c><c>BP_BUFFERFORMAT</c></c></para>
/// <para>The format of the buffer.</para>
/// </param>
/// <param name="pPaintParams">
/// <para>Type: <c><c>BP_PAINTPARAMS</c>*</c></para>
/// <para>A pointer to a structure that defines the paint operation parameters. This value can be <c>NULL</c>.</para>
/// </param>
/// <param name="pAnimationParams">
/// <para>Type: <c><c>BP_ANIMATIONPARAMS</c>*</c></para>
/// <para>A pointer to a structure that defines the animation operation parameters.</para>
/// </param>
/// <param name="phdcFrom">
/// <para>Type: <c><c>HDC</c>*</c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// 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 <c>NULL</c>.
2018-06-27 15:14:43 -04:00
/// </para>
/// </param>
/// <param name="phdcTo">
/// <para>Type: <c><c>HDC</c>*</c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// 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 <c>NULL</c>.
2018-06-27 15:14:43 -04:00
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c>HANIMATIONBUFFER</c></para>
/// <para>A handle to the buffered paint animation.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HANIMATIONBUFFER BeginBufferedAnimation( HWND hwnd, HDC hdcTarget, const RECT *rcTarget, BP_BUFFERFORMAT dwFormat, _In_
// BP_PAINTPARAMS *pPaintParams, _In_ BP_ANIMATIONPARAMS *pAnimationParams, _Out_ HDC *phdcFrom, _Out_ HDC *phdcTo); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773252(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773252")]
2018-11-19 23:18:50 -05:00
public static extern SafeHANIMATIONBUFFER BeginBufferedAnimation ( HWND hwnd , HDC hdcTarget , in RECT rcTarget , BP_BUFFERFORMAT dwFormat ,
2018-10-26 14:24:07 -04:00
[In] BP_PAINTPARAMS pPaintParams , in BP_ANIMATIONPARAMS pAnimationParams , out HDC phdcFrom , out HDC phdcTo ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Begins a buffered paint operation.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hdcTarget">
/// <para>Type: <c><c>HDC</c></c></para>
/// <para>The handle of the target DC on which the buffer will be painted.</para>
/// </param>
/// <param name="prcTarget">
/// <para>Type: <c>const <c>RECT</c>*</c></para>
/// <para>A pointer to a <c>RECT</c> structure that specifies the area of the target DC in which to paint.</para>
/// </param>
/// <param name="dwFormat">
/// <para>Type: <c><c>BP_BUFFERFORMAT</c></c></para>
/// <para>A member of the <c>BP_BUFFERFORMAT</c> enumeration that specifies the format of the buffer.</para>
/// </param>
/// <param name="pPaintParams">
/// <para>Type: <c><c>BP_PAINTPARAMS</c>*</c></para>
/// <para>A pointer to a <c>BP_PAINTPARAMS</c> structure that defines the paint operation parameters. This value can be <c>NULL</c>.</para>
/// </param>
/// <param name="phdc">
/// <para>Type: <c><c>HDC</c>*</c></para>
/// <para>When this function returns, points to the handle of the new device context.</para>
/// </param>
/// <returns>
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// A handle to the buffered paint context. If this function fails, the return value is <c>NULL</c>, and phdc is <c>NULL</c>. To get
/// extended error information, call <c>GetLastError</c>.
2018-06-27 15:14:43 -04:00
/// </para>
/// <para>The returned handle is freed when <c>EndBufferedPaint</c> is called.</para>
/// <para>
2018-11-19 23:18:50 -05:00
/// An application should call <c>BufferedPaintInit</c> on the calling thread before calling <c>BeginBufferedPaint</c>, and
/// <c>BufferedPaintUnInit</c> before the thread is terminated. Failure to call <c>BufferedPaintInit</c> may result in degraded
/// performance due to internal data being initialized and destroyed for each buffered paint operation.
2018-06-27 15:14:43 -04:00
/// </para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HPAINTBUFFER BeginBufferedPaint( HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, _In_ BP_PAINTPARAMS
// *pPaintParams, _Out_ HDC *phdc); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773257(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773257")]
2018-11-19 23:18:50 -05:00
public static extern SafeHPAINTBUFFER BeginBufferedPaint ( HDC hdcTarget , in RECT prcTarget , BP_BUFFERFORMAT dwFormat , [ In ] BP_PAINTPARAMS pPaintParams , out HDC phdc ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Clears a specified rectangle in the buffer to ARGB = {0,0,0,0}.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>The handle of the buffered paint context, obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <param name="prc">
/// <para>Type: <c>const <c>RECT</c>*</c></para>
2018-11-19 23:18:50 -05:00
/// <para>
/// A pointer to a <c>RECT</c> structure that specifies the rectangle to clear. Set this parameter to <c>NULL</c> to specify the
/// entire buffer.
/// </para>
2018-06-27 15:14:43 -04:00
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT BufferedPaintClear( HPAINTBUFFER hBufferedPaint, _In_ const RECT *prc); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773262(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773262")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT BufferedPaintClear ( HPAINTBUFFER hBufferedPaint , in RECT prc ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Initialize buffered painting for the current thread.</summary>
2018-06-27 15:14:43 -04:00
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT BufferedPaintInit(void); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773266(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773266")]
2017-11-27 13:11:20 -05:00
public static extern HRESULT BufferedPaintInit ( ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Paints the next frame of a buffered paint animation.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hwnd">
/// <para>Type: <c><c>HWND</c></c></para>
/// <para>Handle to the window in which the animations play.</para>
/// </param>
/// <param name="hdcTarget">
/// <para>Type: <c><c>HDC</c></c></para>
/// <para>Handle of the target DC on which the buffer is animated.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>BOOL</c></c></para>
/// <para>Returns <c>TRUE</c> if the frame has been painted, or <c>FALSE</c> otherwise.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// BOOL BufferedPaintRenderAnimation( HWND hwnd, HDC hdcTarget); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773271(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773271")]
2017-11-27 13:11:20 -05:00
[return: MarshalAs(UnmanagedType.Bool)]
2018-09-22 00:35:34 -04:00
public static extern bool BufferedPaintRenderAnimation ( HWND hwnd , HDC hdcTarget ) ;
2017-11-27 13:11:20 -05:00
2018-06-27 15:14:43 -04:00
/// <summary>
2018-11-19 23:18:50 -05:00
/// 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).
2018-06-27 15:14:43 -04:00
/// </summary>
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>The handle of the buffered paint context, obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <param name="prc">
/// <para>Type: <c>const <c>RECT</c>*</c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// A pointer to a <c>RECT</c> structure that specifies the rectangle in which to set the alpha. Set this parameter to <c>NULL</c> to
/// specify the entire buffer.
2018-06-27 15:14:43 -04:00
/// </para>
/// </param>
/// <param name="alpha">
/// <para>Type: <c><c>BYTE</c></c></para>
/// <para>The alpha value to set. The alpha value can range from zero (fully transparent) to 255 (fully opaque).</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT BufferedPaintSetAlpha( HPAINTBUFFER hBufferedPaint, _In_ const RECT *prc, BYTE alpha); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773276(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773276")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT BufferedPaintSetAlpha ( HPAINTBUFFER hBufferedPaint , in RECT prc , byte alpha ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Stops all buffered animations for the given window.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hwnd">
/// <para>Type: <c><c>HWND</c></c></para>
/// <para>The handle of the window in which to stop all animations.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT BufferedPaintStopAllAnimations( HWND hwnd); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773280(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773280")]
2018-09-22 00:35:34 -04:00
public static extern HRESULT BufferedPaintStopAllAnimations ( HWND hwnd ) ;
2017-11-27 13:11:20 -05:00
2018-06-27 15:14:43 -04:00
/// <summary>
2018-11-19 23:18:50 -05:00
/// Closes down buffered painting for the current thread. Called once for each call to <c>BufferedPaintInit</c> after calls to
/// <c>BeginBufferedPaint</c> are no longer needed.
2018-06-27 15:14:43 -04:00
/// </summary>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT BufferedPaintUnInit(void); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773284(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773284")]
2017-11-27 13:11:20 -05:00
public static extern HRESULT BufferedPaintUnInit ( ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Renders the first frame of a buffered animation operation and starts the animation timer.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hbpAnimation">
/// <para>Type: <c>HANIMATIONBUFFER</c></para>
/// <para>The handle to the buffered animation context that was returned by <c>BeginBufferedAnimation</c>.</para>
/// </param>
/// <param name="fUpdateTarget">
/// <para>Type: <c><c>BOOL</c></c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// If <c>TRUE</c>, updates the target DC with the animation. If <c>FALSE</c>, the animation is not started, the target DC is not
/// updated, and the hbpAnimation parameter is freed.
2018-06-27 15:14:43 -04:00
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT EndBufferedAnimation( HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773328(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773328")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT EndBufferedAnimation ( HANIMATIONBUFFER hbpAnimation , [ MarshalAs ( UnmanagedType . Bool ) ] bool fUpdateTarget ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Completes a buffered paint operation and frees the associated buffered paint handle.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>The handle of the buffered paint context, obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <param name="fUpdateTarget">
/// <para>Type: <c><c>BOOL</c></c></para>
/// <para><c>TRUE</c> to copy the buffer to the target DC.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT EndBufferedPaint( HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773343(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773343")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT EndBufferedPaint ( HPAINTBUFFER hBufferedPaint , [ MarshalAs ( UnmanagedType . Bool ) ] bool fUpdateTarget ) ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Retrieves a pointer to the buffer bitmap if the buffer is a device-independent bitmap (DIB).</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>The handle of the buffered paint context, obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <param name="ppbBuffer">
/// <para>Type: <c><c>RGBQUAD</c>**</c></para>
/// <para>When this function returns, contains a pointer to the address of the buffer bitmap pixels.</para>
/// </param>
/// <param name="pcxRow">
/// <para>Type: <c>int*</c></para>
/// <para>
2018-11-19 23:18:50 -05:00
/// 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.
2018-06-27 15:14:43 -04:00
/// </para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
2018-11-19 23:18:50 -05:00
/// <para>
/// Returns S_OK if successful, or an error value otherwise. If an error occurs, ppbBuffer is set to <c>NULL</c> and pcxRow is set to zero.
/// </para>
2018-06-27 15:14:43 -04:00
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT GetBufferedPaintBits( HPAINTBUFFER hBufferedPaint, _Out_ RGBQUAD **ppbBuffer, _Out_ int *pcxRow); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773348(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773348")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT GetBufferedPaintBits ( HPAINTBUFFER hBufferedPaint , out IntPtr ppbBuffer , out int pcxRow ) ;
2017-12-24 12:25:05 -05:00
2018-06-27 15:14:43 -04:00
/// <summary>Gets the paint device context (DC). This is the same value retrieved by <c>BeginBufferedPaint</c>.</summary>
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>Handle of the buffered paint context, obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HDC</c></c></para>
2018-11-19 23:18:50 -05:00
/// <para>
/// Handle of the requested DC. This is the same DC that is returned by <c>BeginBufferedPaint</c>. Returns <c>NULL</c> upon failure.
/// </para>
2018-06-27 15:14:43 -04:00
/// </returns>
2018-11-19 23:18:50 -05:00
// HDC GetBufferedPaintDC( HPAINTBUFFER hBufferedPaint); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773351(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773351")]
2018-11-19 23:18:50 -05:00
public static extern HDC GetBufferedPaintDC ( HPAINTBUFFER hBufferedPaint ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Retrieves the target device context (DC).</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>A handle to the buffered paint context obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HDC</c></c></para>
/// <para>A handle to the requested DC, or <c>NULL</c> otherwise.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HDC GetBufferedPaintTargetDC( HPAINTBUFFER hBufferedPaint); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773356(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773356")]
2018-11-19 23:18:50 -05:00
public static extern HDC GetBufferedPaintTargetDC ( HPAINTBUFFER hBufferedPaint ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Retrieves the target rectangle specified by BeginBufferedPaint.</summary>
2018-06-27 15:14:43 -04:00
/// <param name="hBufferedPaint">
/// <para>Type: <c>HPAINTBUFFER</c></para>
/// <para>Handle to the buffered paint context obtained through <c>BeginBufferedPaint</c>.</para>
/// </param>
/// <param name="prc">
/// <para>Type: <c><c>RECT</c>*</c></para>
/// <para>When this function returns, contains the requested rectangle.</para>
/// </param>
/// <returns>
/// <para>Type: <c><c>HRESULT</c></c></para>
/// <para>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</para>
/// </returns>
2018-11-19 23:18:50 -05:00
// HRESULT GetBufferedPaintTargetRect( HPAINTBUFFER hBufferedPaint, _Out_ RECT *prc); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773361(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[DllImport(Lib.UxTheme, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773361")]
2018-11-19 23:18:50 -05:00
public static extern HRESULT GetBufferedPaintTargetRect ( HPAINTBUFFER hBufferedPaint , out RECT prc ) ;
2017-12-24 12:25:05 -05:00
2018-06-27 15:14:43 -04:00
/// <summary>Defines animation parameters for the <c>BP_PAINTPARAMS</c> structure used by <c>BeginBufferedPaint</c>.</summary>
2018-11-19 23:18:50 -05:00
// typedef struct _BP_ANIMATIONPARAMS { DWORD cbSize; DWORD dwFlags; BP_ANIMATIONSTYLE style; DWORD dwDuration;} BP_ANIMATIONPARAMS,
// *PBP_ANIMATIONPARAMS; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773224(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773224")]
2017-11-27 13:11:20 -05:00
[StructLayout(LayoutKind.Sequential)]
public struct BP_ANIMATIONPARAMS
{
2017-12-24 12:25:05 -05:00
/// <summary>The size, in bytes, of this structure.</summary>
public uint cbSize ;
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Reserved.</summary>
public uint dwFlags ;
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Animation style.</summary>
2017-11-27 13:11:20 -05:00
public BP_ANIMATIONSTYLE style ;
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>Length of the animation, in milliseconds.</summary>
public uint dwDuration ;
2017-11-27 13:11:20 -05:00
2017-12-24 12:25:05 -05:00
/// <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>
2017-12-27 19:16:49 -05:00
public BP_ANIMATIONPARAMS ( BP_ANIMATIONSTYLE animStyle , int dur = 0 )
2017-11-27 13:11:20 -05:00
{
2017-12-24 12:25:05 -05:00
cbSize = ( uint ) Marshal . SizeOf ( typeof ( BP_ANIMATIONPARAMS ) ) ;
2017-11-27 13:11:20 -05:00
dwFlags = 0 ;
2017-12-27 19:16:49 -05:00
dwDuration = ( uint ) dur ;
2017-11-27 13:11:20 -05:00
style = animStyle ;
}
2017-12-24 12:25:05 -05:00
/// <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 ) ) } ;
2017-11-27 13:11:20 -05:00
}
2018-11-19 23:18:50 -05:00
/// <summary>Provides a handle to an animation buffer.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct HANIMATIONBUFFER : IHandle
{
private IntPtr handle ;
/// <summary>Initializes a new instance of the <see cref="HANIMATIONBUFFER"/> struct.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
public HANIMATIONBUFFER ( IntPtr preexistingHandle ) = > handle = preexistingHandle ;
/// <summary>Returns an invalid handle by instantiating a <see cref="HANIMATIONBUFFER"/> object with <see cref="IntPtr.Zero"/>.</summary>
public static HANIMATIONBUFFER NULL = > new HANIMATIONBUFFER ( IntPtr . Zero ) ;
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
public bool IsNull = > handle = = IntPtr . Zero ;
/// <summary>Performs an explicit conversion from <see cref="HANIMATIONBUFFER"/> to <see cref="IntPtr"/>.</summary>
/// <param name="h">The handle.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator IntPtr ( HANIMATIONBUFFER h ) = > h . handle ;
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HANIMATIONBUFFER"/>.</summary>
/// <param name="h">The pointer to a handle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HANIMATIONBUFFER ( IntPtr h ) = > new HANIMATIONBUFFER ( h ) ;
/// <summary>Implements the operator !=.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ! = ( HANIMATIONBUFFER h1 , HANIMATIONBUFFER h2 ) = > ! ( h1 = = h2 ) ;
/// <summary>Implements the operator ==.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator = = ( HANIMATIONBUFFER h1 , HANIMATIONBUFFER h2 ) = > h1 . Equals ( h2 ) ;
/// <inheritdoc/>
public override bool Equals ( object obj ) = > obj is HANIMATIONBUFFER h ? handle = = h . handle : false ;
/// <inheritdoc/>
public override int GetHashCode ( ) = > handle . GetHashCode ( ) ;
/// <inheritdoc/>
public IntPtr DangerousGetHandle ( ) = > handle ;
}
/// <summary>Provides a handle to a paint buffer.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct HPAINTBUFFER : IHandle
{
private IntPtr handle ;
/// <summary>Initializes a new instance of the <see cref="HPAINTBUFFER"/> struct.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
public HPAINTBUFFER ( IntPtr preexistingHandle ) = > handle = preexistingHandle ;
/// <summary>Returns an invalid handle by instantiating a <see cref="HPAINTBUFFER"/> object with <see cref="IntPtr.Zero"/>.</summary>
public static HPAINTBUFFER NULL = > new HPAINTBUFFER ( IntPtr . Zero ) ;
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
public bool IsNull = > handle = = IntPtr . Zero ;
/// <summary>Performs an explicit conversion from <see cref="HPAINTBUFFER"/> to <see cref="IntPtr"/>.</summary>
/// <param name="h">The handle.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator IntPtr ( HPAINTBUFFER h ) = > h . handle ;
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HPAINTBUFFER"/>.</summary>
/// <param name="h">The pointer to a handle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HPAINTBUFFER ( IntPtr h ) = > new HPAINTBUFFER ( h ) ;
/// <summary>Implements the operator !=.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ! = ( HPAINTBUFFER h1 , HPAINTBUFFER h2 ) = > ! ( h1 = = h2 ) ;
/// <summary>Implements the operator ==.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator = = ( HPAINTBUFFER h1 , HPAINTBUFFER h2 ) = > h1 . Equals ( h2 ) ;
/// <inheritdoc/>
public override bool Equals ( object obj ) = > obj is HPAINTBUFFER h ? handle = = h . handle : false ;
/// <inheritdoc/>
public override int GetHashCode ( ) = > handle . GetHashCode ( ) ;
/// <inheritdoc/>
public IntPtr DangerousGetHandle ( ) = > handle ;
}
2018-06-27 15:14:43 -04:00
/// <summary>Defines paint operation parameters for <c>BeginBufferedPaint</c>.</summary>
2018-11-19 23:18:50 -05:00
// typedef struct _BP_PAINTPARAMS { DWORD cbSize; DWORD dwFlags; const RECT *prcExclude; const BLENDFUNCTION *pBlendFunction;}
// BP_PAINTPARAMS, *PBP_PAINTPARAMS; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773228(v=vs.85).aspx
2018-06-27 15:14:43 -04:00
[PInvokeData("Uxtheme.h", MSDNShortId = "bb773228")]
2017-11-27 13:11:20 -05:00
[StructLayout(LayoutKind.Sequential)]
public class BP_PAINTPARAMS : IDisposable
{
2017-12-24 12:25:05 -05:00
/// <summary>The size, in bytes, of this structure.</summary>
2017-11-27 13:11:20 -05:00
public int cbSize ;
2018-11-19 23:18:50 -05:00
2017-12-24 12:25:05 -05:00
/// <summary>One or more of the following values.</summary>
2017-11-27 13:11:20 -05:00
public BufferedPaintParamsFlags Flags ;
2018-11-19 23:18:50 -05:00
/// <summary>
/// A pointer to exclusion RECT structure. This rectangle is excluded from the clipping region. May be NULL for no exclusion rectangle.
/// </summary>
2017-11-27 13:11:20 -05:00
public IntPtr prcExclude ;
2018-11-19 23:18:50 -05:00
/// <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>
2017-11-27 13:11:20 -05:00
public IntPtr pBlendFunction ;
2017-12-24 12:25:05 -05:00
/// <summary>Initializes a new instance of the <see cref="BP_PAINTPARAMS"/> class.</summary>
/// <param name="flags">The flags.</param>
2017-11-27 13:11:20 -05:00
public BP_PAINTPARAMS ( BufferedPaintParamsFlags flags = BufferedPaintParamsFlags . BPPF_NONE )
{
cbSize = Marshal . SizeOf ( typeof ( BP_PAINTPARAMS ) ) ;
Flags = flags ;
prcExclude = pBlendFunction = IntPtr . Zero ;
}
2017-12-24 12:25:05 -05:00
/// <summary>Gets or sets the rectangle that is excluded from the clipping region.</summary>
/// <value>The rectangle.</value>
2017-11-27 13:11:20 -05:00
public Rectangle ? Exclude
{
get = > prcExclude . ToNullableStructure < Rectangle > ( ) ;
set
{
if ( prcExclude ! = IntPtr . Zero ) Marshal . FreeCoTaskMem ( prcExclude ) ;
if ( value . HasValue & & ! value . Value . IsEmpty )
2018-11-19 23:18:50 -05:00
prcExclude = value . StructureToPtr ( Marshal . AllocCoTaskMem , out var _ ) ;
2017-11-27 13:11:20 -05:00
}
}
2017-12-24 12:25:05 -05:00
/// <summary>Gets or sets the blend function.</summary>
/// <value>The blend function.</value>
2017-11-27 13:11:20 -05:00
public BLENDFUNCTION ? BlendFunction
{
get = > pBlendFunction . ToNullableStructure < BLENDFUNCTION > ( ) ;
set
{
if ( pBlendFunction ! = IntPtr . Zero ) Marshal . FreeCoTaskMem ( pBlendFunction ) ;
if ( value . HasValue & & ! value . Value . IsEmpty )
2018-11-19 23:18:50 -05:00
pBlendFunction = value . StructureToPtr ( Marshal . AllocCoTaskMem , out var _ ) ;
2017-11-27 13:11:20 -05:00
}
}
2018-11-19 23:18:50 -05:00
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
2017-11-27 13:11:20 -05:00
public void Dispose ( )
{
if ( prcExclude ! = IntPtr . Zero ) Marshal . FreeCoTaskMem ( prcExclude ) ;
if ( pBlendFunction ! = IntPtr . Zero ) Marshal . FreeCoTaskMem ( pBlendFunction ) ;
}
2017-12-24 12:25:05 -05:00
/// <summary>Gets an instance of this structure set to define no clipping.</summary>
2017-11-27 13:11:20 -05:00
public static BP_PAINTPARAMS NoClip = > new BP_PAINTPARAMS ( BufferedPaintParamsFlags . BPPF_NOCLIP ) ;
2017-12-24 12:25:05 -05:00
/// <summary>Gets an instance of this structure set to define clearing the background.</summary>
2017-11-27 13:11:20 -05:00
public static BP_PAINTPARAMS ClearBg = > new BP_PAINTPARAMS ( BufferedPaintParamsFlags . BPPF_ERASE ) ;
}
2018-06-27 15:14:43 -04:00
/// <summary>
2018-11-19 23:18:50 -05:00
/// Automated initialization and uninitialization of buffered painting for the current thread. Automatically calls <see
/// cref="BufferedPaintInit"/> on construction and <see cref="BufferedPaintUnInit"/> on disposal.
2018-06-27 15:14:43 -04:00
/// </summary>
/// <example>
2018-11-19 23:18:50 -05:00
/// Best used by declaring a static field within the class that calls buffered paint methods. This will ensure that the
/// initialization only happens once per thread and then is uninitialized when all methods are complete.
2018-06-27 15:14:43 -04:00
/// <code lang="cs">
/// private static BufferedPaintBlock buffPaintBlock = new BufferedPaintBlock();
/// </code>
/// </example>
/// <seealso cref="System.IDisposable"/>
public class BufferedPaintBlock : IDisposable
{
/// <summary>Initializes a new instance of the <see cref="BufferedPaintBlock"/> class calling <see cref="BufferedPaintInit"/>.</summary>
2018-11-19 23:18:50 -05:00
public BufferedPaintBlock ( ) = > BufferedPaintInit ( ) . ThrowIfFailed ( ) ;
2018-06-27 15:14:43 -04:00
/// <summary>Automatically calls <see cref="BufferedPaintUnInit"/>.</summary>
2018-11-19 23:18:50 -05:00
public void Dispose ( ) = > BufferedPaintUnInit ( ) ;
2018-06-27 15:14:43 -04:00
}
2018-11-19 23:18:50 -05:00
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HANIMATIONBUFFER"/> that is disposed using <see cref="EndBufferedAnimation"/>.</summary>
public class SafeHANIMATIONBUFFER : HANDLE
2018-06-27 15:14:43 -04:00
{
2018-11-19 23:18:50 -05:00
private readonly bool fUpdateTarget = true ;
/// <summary>Initializes a new instance of the <see cref="SafeHANIMATIONBUFFER"/> class and assigns an existing handle.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2018-11-28 14:33:55 -05:00
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedAnimation"/> when closing this handle.</param>
2018-11-19 23:18:50 -05:00
/// <param name="ownsHandle">
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
/// </param>
public SafeHANIMATIONBUFFER ( IntPtr preexistingHandle , bool updateTargetDC = true , bool ownsHandle = true ) : base ( preexistingHandle , ownsHandle ) = > fUpdateTarget = updateTargetDC ;
/// <summary>Initializes a new instance of the <see cref="SafeHANIMATIONBUFFER"/> class.</summary>
private SafeHANIMATIONBUFFER ( ) : base ( ) { }
/// <summary>Performs an implicit conversion from <see cref="SafeHANIMATIONBUFFER"/> to <see cref="HANIMATIONBUFFER"/>.</summary>
/// <param name="h">The safe handle instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HANIMATIONBUFFER ( SafeHANIMATIONBUFFER h ) = > h . handle ;
/// <inheritdoc/>
protected override bool InternalReleaseHandle ( ) = > EndBufferedAnimation ( this , fUpdateTarget ) . Succeeded ;
2018-06-27 15:14:43 -04:00
}
2018-11-19 23:18:50 -05:00
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPAINTBUFFER"/> that is disposed using <see cref="EndBufferedPaint"/>.</summary>
public class SafeHPAINTBUFFER : HANDLE
2018-06-27 15:14:43 -04:00
{
2018-11-19 23:18:50 -05:00
private readonly bool fUpdateTarget = true ;
/// <summary>Initializes a new instance of the <see cref="SafeHPAINTBUFFER"/> class and assigns an existing handle.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2018-11-28 14:33:55 -05:00
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedPaint"/> when closing this handle.</param>
2018-11-19 23:18:50 -05:00
/// <param name="ownsHandle">
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
/// </param>
public SafeHPAINTBUFFER ( IntPtr preexistingHandle , bool updateTargetDC = true , bool ownsHandle = true ) : base ( preexistingHandle , ownsHandle ) = > fUpdateTarget = updateTargetDC ;
/// <summary>Initializes a new instance of the <see cref="SafeHPAINTBUFFER"/> class.</summary>
private SafeHPAINTBUFFER ( ) : base ( ) { }
/// <summary>Performs an implicit conversion from <see cref="SafeHPAINTBUFFER"/> to <see cref="HPAINTBUFFER"/>.</summary>
/// <param name="h">The safe handle instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HPAINTBUFFER ( SafeHPAINTBUFFER h ) = > h . handle ;
/// <inheritdoc/>
protected override bool InternalReleaseHandle ( ) = > EndBufferedPaint ( this , fUpdateTarget ) . Succeeded ;
2018-06-27 15:14:43 -04:00
}
2017-11-27 13:11:20 -05:00
}
2017-12-24 12:25:05 -05:00
}