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