using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Magnification API functions and structures.
///
/// The Magnification API enables applications to magnify the entire screen or portions of the screen, and to apply color effects
///
public static partial class Magnification
{
/// The magnifier class window name.
public const string WC_MAGNIFIER = "Magnifier";
private const string Lib_Magnification = "magnification.dll";
///
///
/// hwnd
///
/// Type: HWND
/// The magnification window.
///
/// srcdata
///
///
/// srcheader
///
/// Type: MAGIMAGEHEADER
/// The description of the input format.
///
/// destdata
///
///
/// destheader
///
/// Type: MAGIMAGEHEADER
/// The description of the output format.
///
/// unclipped
///
/// Type: RECT
/// The coordinates of the scaled version of the source bitmap.
///
/// clipped
///
/// Type: RECT
/// The coordinates of the window to which the scaled bitmap is clipped.
///
/// dirty
///
/// Type: HRGN
/// The region that needs to be refreshed.
///
///
/// Type: HWND
/// The magnification window.
///
///
///
/// Type: MAGIMAGEHEADER
/// The description of the input format.
///
///
///
/// Type: MAGIMAGEHEADER
/// The description of the output format.
///
///
/// Type: RECT
/// The coordinates of the scaled version of the source bitmap.
///
///
/// Type: RECT
/// The coordinates of the window to which the scaled bitmap is clipped.
///
///
/// Type: HRGN
/// The region that needs to be refreshed.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nc-magnification-magimagescalingcallback MagImageScalingCallback
// Magimagescalingcallback; BOOL Magimagescalingcallback( HWND hwnd, void *srcdata, MAGIMAGEHEADER srcheader, void *destdata,
// MAGIMAGEHEADER destheader, RECT unclipped, RECT clipped, HRGN dirty ) {...}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
[PInvokeData("magnification.h", MSDNShortId = "NC:magnification.MagImageScalingCallback")]
[return: MarshalAs(UnmanagedType.Bool)]
public delegate bool MagImageScalingCallback(HWND hwnd, IntPtr srcdata, MAGIMAGEHEADER srcheader, IntPtr destdata, MAGIMAGEHEADER destheader, RECT unclipped, RECT clipped, HRGN dirty);
///
/// This topic describes the styles used with the magnifier control. To create a magnifier control, use the CreateWindowEx
/// function and specify the WC_MAGNIFIER window class, along with a combination of the following magnifier styles.
///
// https://docs.microsoft.com/en-us/windows/win32/winauto/magapi/magapi-magnifier-styles
[PInvokeData("magnification.h")]
public enum MagnifierStyles
{
/// Displays the magnified system cursor along with the magnified screen content.
MS_SHOWMAGNIFIEDCURSOR = 0x0001,
///
/// Clips the area of the magnifier window that surrounds the system cursor. This style enables the user to see screen content
/// that is behind the magnifier window.
///
MS_CLIPAROUNDCURSOR = 0x0002,
/// Displays the magnified screen content using inverted colors.
MS_INVERTCOLORS = 0x0004,
}
/// The magnification filter mode.
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetWindowFilterList")]
public enum MW_FILTERMODE
{
/// Exclude the windows from magnification.
MW_FILTERMODE_EXCLUDE = 0,
/// Magnify the windows.
MW_FILTERMODE_INCLUDE = 1
}
/// Gets the color transformation matrix for a magnifier control.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: PMAGCOLOREFFECT
/// The color transformation matrix, or NULL if no color effect has been set.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// The magnifier control uses the color transformation matrix to apply a color effect to the entire magnifier window.
/// This function requires Windows Display Driver Model (WDDM)-capable video cards.
/// Examples
/// The following example retrieves the color transformation matrix.
///
/// // Description: // Retrieves the color transformation matrix from a magnifier control. // Parameters: // hwndMag - handle of the magnifier control. // BOOL GetMagnifierColorTransform(HWND hwndMag) { MAGCOLOREFFECT effect; BOOL ret = MagGetColorEffect(hwndMag, &effect); // // Do something with the color data. // return ret; }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetcoloreffect BOOL MagGetColorEffect( HWND
// hwnd, PMAGCOLOREFFECT pEffect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetColorEffect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetColorEffect(HWND hwnd, out MAGCOLOREFFECT pEffect);
/// Retrieves the color transformation matrix associated with the full-screen magnifier.
///
/// Type: PMAGCOLOREFFECT
/// The color transformation matrix, or the identity matrix if no color effect has been set.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// The full-screen magnifier uses the color transformation matrix to apply a color effect to the entire screen.
/// Examples
/// The following example retrieves the color transformation matrix associated with the full-screen magnifier.
///
/// // Get the current color effect. MAGCOLOREFFECT magEffect; if (!MagGetFullscreenColorEffect(&magEffect)) return E_FAIL;
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetfullscreencoloreffect BOOL
// MagGetFullscreenColorEffect( PMAGCOLOREFFECT pEffect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetFullscreenColorEffect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetFullscreenColorEffect(out MAGCOLOREFFECT pEffect);
/// Retrieves the magnification settings for the full-screen magnifier.
///
/// Type: float*
///
/// The current magnification factor for the full-screen magnifier. A value of 1.0 indicates that the screen content is not being
/// magnified. A value above 1.0 indicates the scale factor for magnification. A value less than 1.0 is not valid.
///
///
///
/// Type: int*
///
/// The x-coordinate offset for the upper-left corner of the unmagnified view. The offset is relative to the upper-left corner of
/// the primary monitor, in unmagnified coordinates.
///
///
///
/// Type: int*
///
/// The y-coordinate offset for the upper-left corner of the unmagnified view. The offset is relative to the upper-left corner of
/// the primary monitor, in unmagnified coordinates.
///
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// The offsets are not affected by the current dots per inch (dpi) setting.
/// Examples
/// The following code snippet retrieves the magnification value and offsets for the full-screen magnifier.
///
/// // Get the current magnification level and offset. float magLevel; int xOffset, yOffset; if (!MagGetFullscreenTransform(&magLevel, &xOffset, &yOffset)) { return E_FAIL; } // // Do something with the magnification settings. //
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetfullscreentransform BOOL
// MagGetFullscreenTransform( float *pMagLevel, int *pxOffset, int *pyOffset );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetFullscreenTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetFullscreenTransform(out float pMagLevel, out int pxOffset, out int pyOffset);
/// Retrieves the registered callback function that implements a custom transform for image scaling.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: MagImageScalingCallback
/// Returns the registered MagImageScalingCallback callback function, or NULL if no callback is registered.
///
///
/// This function returns NULL if Windows Display Driver Model (WDDM) is not supported.
/// This function works only when Desktop Window Manager (DWM) is off.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetimagescalingcallback
// MagImageScalingCallback MagGetImageScalingCallback( HWND hwnd );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetImageScalingCallback")]
public static extern MagImageScalingCallback MagGetImageScalingCallback(HWND hwnd);
///
/// Retrieves the current input transformation for pen and touch input, represented as a source rectangle and a destination rectangle.
///
///
/// Type: BOOL*
/// TRUE if input translation is enabled, or FALSE if not.
///
///
/// Type: LPRECT
/// The source rectangle, in unmagnified screen coordinates, that defines the area of the screen that is magnified.
///
///
/// Type: LPRECT
///
/// The destination rectangle, in screen coordinates, that defines the area of the screen where the magnified screen content is
/// displayed. Pen and touch input in this rectangle is mapped to the source rectangle.
///
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The input transformation maps the coordinate space of the magnified screen content to the actual (unmagnified) screen coordinate
/// space. This enables the system to pass touch and pen input that is entered in magnified screen content, to the correct UI
/// element on the screen. For example, without input transformation, input is passed to the element located at the unmagnified
/// screen coordinates, not to the item that appears in the magnified screen content.
///
/// Examples
/// The following example retrieves the current input translation settings.
///
/// // Description: // Retrieves the current input transform. // BOOL GetInputTranform() { BOOL fInputTransformEnabled; RECT rcSource; RECT rcTarget; BOOL fResult = MagGetInputTransform(&fInputTransformEnabled, &rcSource, &rcTarget); if (fResult) { // // Do something with the input transform data. // } return fResult; }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetinputtransform BOOL MagGetInputTransform(
// BOOL *pfEnabled, LPRECT pRectSource, LPRECT pRectDest );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetInputTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetInputTransform([MarshalAs(UnmanagedType.Bool)] out bool pfEnabled, out RECT pRectSource, out RECT pRectDest);
/// Retrieves the list of windows that are magnified or excluded from magnification.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: DWORD*
/// The filter mode, as set by MagSetWindowFilterList.
///
///
/// Type: int
/// The number of windows to retrieve, or 0 to retrieve a count of windows in the filter list.
///
///
/// Type: HWND*
/// The list of window handles.
///
///
/// Type: int
/// Returns the count of window handles in the filter list, or -1 if the hwnd parameter is not valid.
///
///
///
/// First call the method with a count of 0 to retrieve the count of windows in the filter list. Use the retrieved count to allocate
/// sufficient memory for the retrieved list of window handles.
///
/// This function requires Windows Display Driver Model (WDDM)-capable video cards.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetwindowfilterlist int
// MagGetWindowFilterList( HWND hwnd, DWORD *pdwFilterMode, int count, HWND *pHWND );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetWindowFilterList")]
public static extern int MagGetWindowFilterList(HWND hwnd, out MW_FILTERMODE pdwFilterMode, int count, [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 2)] HWND[] pHWND);
/// Gets the rectangle of the area that is being magnified.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: RECT*
/// The rectangle that is being magnified, in desktop coordinates.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetwindowsource BOOL MagGetWindowSource(
// HWND hwnd, RECT *pRect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetWindowSource")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetWindowSource(HWND hwnd, out RECT pRect);
/// Retrieves the transformation matrix associated with a magnifier control.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: PMAGTRANSFORM
/// The transformation matrix.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// The transformation matrix specifies the magnification factor that the magnifier control applies to the contents of the source rectangle.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maggetwindowtransform BOOL
// MagGetWindowTransform( HWND hwnd, PMAGTRANSFORM pTransform );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagGetWindowTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagGetWindowTransform(HWND hwnd, out MAGTRANSFORM pTransform);
/// Creates and initializes the magnifier run-time objects.
///
/// Type: BOOL
/// Returns TRUE if initialization was successful; otherwise FALSE.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maginitialize BOOL MagInitialize();
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagInitialize")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagInitialize();
/// Sets the color transformation matrix for a magnifier control.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: PMAGCOLOREFFECT
/// The color transformation matrix, or NULL to remove the current color effect, if any.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The magnifier control uses the color transformation matrix to apply a color effect to the entire magnifier window. If the
/// function is called multiple times, the most recent color transform is used.
///
/// This function requires Windows Display Driver Model (WDDM)-capable video cards.
/// Examples
/// The following example sets a color transformation matrix that converts the colors displayed in the magnifier to grayscale.
///
/// // Description: // Converts the colors displayed in the magnifier window to grayscale, or // returns the colors to normal. // Parameters: // hwndMag - Handle of the magnifier control. // fInvert - TRUE to convert to grayscale, or FALSE for normal colors. // BOOL ConvertToGrayscale(HWND hwndMag, BOOL fConvert) { // Convert the screen colors in the magnifier window. if (fConvert) { MAGCOLOREFFECT magEffectGrayscale = {{ // MagEffectGrayscale { 0.3f, 0.3f, 0.3f, 0.0f, 0.0f }, { 0.6f, 0.6f, 0.6f, 0.0f, 0.0f }, { 0.1f, 0.1f, 0.1f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }}; return MagSetColorEffect(hwndMag, &magEffectGrayscale); } // Return the colors to normal. else { return MagSetColorEffect(hwndMag, NULL); } }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetcoloreffect BOOL MagSetColorEffect( HWND
// hwnd, PMAGCOLOREFFECT pEffect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetColorEffect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetColorEffect(HWND hwnd, in MAGCOLOREFFECT pEffect);
/// Changes the color transformation matrix associated with the full-screen magnifier.
///
/// Type: PMAGCOLOREFFECT
/// The new color transformation matrix. This parameter must not be NULL.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The full-screen magnifier uses the color transformation matrix to apply a color effect to the entire desktop. If the function is
/// called multiple times, the most recent color transform is used.
///
/// Examples
/// The following example defines two color transformation matrices for use with MagSetFullscreenColorEffect. The
/// g_MagEffectGrayscale
/// matrix converts the screen colors to grayscale. The
/// g_MagEffectIdentity
/// matrix is the identity matrix, which restores the original screen colors.
///
///
/// // Initialize color transformation matrices used to apply grayscale and to // restore the original screen color. MAGCOLOREFFECT g_MagEffectGrayscale = {0.3f, 0.3f, 0.3f, 0.0f, 0.0f, 0.6f, 0.6f, 0.6f, 0.0f, 0.0f, 0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; MAGCOLOREFFECT g_MagEffectIdentity = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; BOOL SetColorGrayscale(__in BOOL fGrayscaleOn) { // Apply the color matrix required to either apply grayscale to the screen // colors or to show the regular colors. PMAGCOLOREFFECT pEffect = (fGrayscaleOn ? &g_MagEffectGrayscale : &g_MagEffectIdentity); return MagSetFullscreenColorEffect(pEffect); }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetfullscreencoloreffect BOOL
// MagSetFullscreenColorEffect( PMAGCOLOREFFECT pEffect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetFullscreenColorEffect")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetFullscreenColorEffect(in MAGCOLOREFFECT pEffect);
/// Changes the magnification settings for the full-screen magnifier.
///
/// Type: float
///
/// The new magnification factor for the full-screen magnifier. The minimum value of this parameter is 1.0, and the maximum value is
/// 4096.0. If this value is 1.0, the screen content is not magnified and no offsets are applied.
///
///
///
/// Type: int
///
/// The new x-coordinate offset, in pixels, for the upper-left corner of the magnified view. The offset is relative to the
/// upper-left corner of the primary monitor, in unmagnified coordinates. The minimum value of the parameter is -262144, and the
/// maximum value is 262144.
///
///
///
/// Type: int
///
/// The new y-coordinate offset, in pixels, for the upper-left corner of the magnified view. The offset is relative to the
/// upper-left corner of the primary monitor, in unmagnified coordinates. The minimum value of the parameter is -262144, and the
/// maximum value is 262144.
///
///
///
/// Type: BOOL
/// Returns TRUE if successful. Otherwise, FALSE.
///
///
/// The offsets are not affected by the current dots per inch (dpi) settings.
///
/// The magnification factor is applied to the current mouse cursor visuals, including cursor visuals affected by the mouse-related
/// settings in the Ease of Access control panel.
///
///
/// In a multiple monitor environment, to position the upper-left corner of the magnified view to the left of the primary monitor,
/// the offsets must be adjusted by the upper-left corner of the virtual screen and the magnification factor being applied. (The
/// virtual screen is the bounding rectangle of all display monitors.) For an example that shows how to position the upper-left
/// corner of the magnified view to the left of the primary monitor, see Examples.
///
///
/// Beginning with Windows 10 Creators Update (version 1703), you must use the MagSetInputTransform function for input to route to
/// the magnified element.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetfullscreentransform BOOL
// MagSetFullscreenTransform( float magLevel, int xOffset, int yOffset );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetFullscreenTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetFullscreenTransform(float magLevel, int xOffset, int yOffset);
/// Sets the callback function for external image filtering and scaling.
///
/// Type: HWND
/// The handle of the magnification window.
///
///
/// Type: MagImageScalingCallback
/// The callback function, or NULL to remove a callback that was previously set.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// This function requires Windows Display Driver Model (WDDM)-capable video cards.
/// This function works only when Desktop Window Manager (DWM) is off.
///
/// This callback mechanism enables custom image filtering and scaling mechanisms. Filtering might include bilinear, trilinear,
/// bicubic, and flat. The mechanism also enables edge detection and enhancement.
///
///
/// The only transform that can be performed within the callback is scaling. Rotations and skews that may compose the arbitrary
/// transform passed to the MagSetWindowTransform function are performed after the callback function returns.
///
///
/// The specified function is called by the magnification engine for all rasterized Windows Graphics Device Interface (GDI) bitmaps
/// before they are composited.
///
/// After the callback function returns, the bitmap in video memory can have one of the following size states:
///
/// -
///
/// Unscaled. The returned bitmap is the same size as the bitmap passed by the caller. The magnification engine does the scaling by
/// the transform specified in the MagSetWindowTransform function.
///
///
/// -
/// Scaled. The returned bitmap is scaled by the transform specified in MagSetWindowTransform.
///
///
/// If no callback is registered, the magnification engine scales bitmaps by the transform specified in MagSetWindowTransform.
///
/// Windows Presentation Foundation (WPF) bitmaps can be scaled automatically using flat, bilinear, bicubic filtering and
/// consequently do not use this callback mechanism.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetimagescalingcallback BOOL
// MagSetImageScalingCallback( HWND hwnd, MagImageScalingCallback callback );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetImageScalingCallback")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetImageScalingCallback(HWND hwnd, MagImageScalingCallback callback);
///
/// Sets the current active input transformation for pen and touch input, represented as a source rectangle and a destination rectangle.
///
///
/// Type: BOOL
/// TRUE to enable input transformation, or FALSE to disable it.
///
///
/// Type: const LPRECT
///
/// The new source rectangle, in unmagnified screen coordinates, that defines the area of the screen to magnify. This parameter is
/// ignored if bEnabled is FALSE.
///
///
///
/// Type: const LPRECT
///
/// The new destination rectangle, in unmagnified screen coordinates, that defines the area of the screen where the magnified screen
/// content is displayed. Pen and touch input in this rectangle is mapped to the source rectangle. This parameter is ignored if
/// bEnabled is FALSE.
///
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The input transformation maps the coordinate space of the magnified screen content to the actual (unmagnified) screen coordinate
/// space. This enables the system to pass pen and touch input that is entered in magnified screen content, to the correct UI
/// element on the screen. For example, without input transformation, input is passed to the element located at the unmagnified
/// screen coordinates, not to the item that appears in the magnified screen content.
///
///
/// This function requires the calling process to have UIAccess privileges. If the caller does not have UIAccess privileges, the
/// call to MagSetInputTransform fails, and the GetLastError function returns ERROR_ACCESS_DENIED. For more information, see
/// UI Automation Security Considerations and /MANIFESTUAC (Embeds UAC information in manifest).
///
///
/// Beginning with Windows 10 Creators Update (version 1703), you must use the MagSetInputTransform function for mouse input to
/// route to the magnified element (in addition to pen and touch input).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetinputtransform BOOL MagSetInputTransform(
// BOOL fEnabled, const LPRECT pRectSource, const LPRECT pRectDest );
[DllImport(Lib_Magnification, SetLastError = true, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetInputTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetInputTransform([MarshalAs(UnmanagedType.Bool)] bool fEnabled, [Optional] in RECT pRectSource, [Optional] in RECT pRectDest);
/// Sets the list of windows to be magnified or the list of windows to be excluded from magnification.
///
/// Type: HWND
/// The handle of the magnification window.
///
///
/// Type: DWORD
/// The magnification filter mode. It can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// MW_FILTERMODE_INCLUDE
/// Magnify the windows.
///
/// -
/// MW_FILTERMODE_EXCLUDE
/// Exclude the windows from magnification.
///
///
///
///
/// Type: int
/// The number of window handles in the list.
///
///
/// Type: HWND*
/// The list of window handles.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
/// This function requires Windows Display Driver Model (WDDM)-capable video cards.
///
/// Only one window list is used. You can specify either MW_FILTERMODE_INCLUDE or MW_FILTERMODE_EXCLUDE, depending on whether it is
/// more convenient to list included windows or excluded windows.
///
/// The magnification window itself is automatically excluded.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetwindowfilterlist BOOL
// MagSetWindowFilterList( HWND hwnd, DWORD dwFilterMode, int count, HWND *pHWND );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetWindowFilterList")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetWindowFilterList(HWND hwnd, MW_FILTERMODE dwFilterMode, int count, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 2)] HWND[] pHWND);
/// Sets the source rectangle for the magnification window.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: RECT
/// The rectangle to be magnified, in desktop coordinates.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetwindowsource BOOL MagSetWindowSource(
// HWND hwnd, RECT rect );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetWindowSource")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetWindowSource(HWND hwnd, RECT rect);
/// Sets the transformation matrix for a magnifier control.
///
/// Type: HWND
/// The magnification window.
///
///
/// Type: PMAGTRANSFORM
/// A transformation matrix.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// The transformation matrix specifies the magnification factor that the magnifier control applies to the contents of the source rectangle.
///
/// Examples
/// The following example shows how to set the magnification factor for a magnifier control.
///
/// // Description: // Sets the magnification factor for a magnifier control. // Parameters: // hwndMag - Handle of the magnifier control. // magFactor - New magnification factor. // BOOL SetMagnificationFactor(HWND hwndMag, float magFactor) { MAGTRANSFORM matrix; memset(&matrix, 0, sizeof(matrix)); matrix.v[0][0] = magFactor; matrix.v[1][1] = magFactor; matrix.v[2][2] = 1.0f; return MagSetWindowTransform(hwndMag, &matrix); }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magsetwindowtransform BOOL
// MagSetWindowTransform( HWND hwnd, PMAGTRANSFORM pTransform );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagSetWindowTransform")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagSetWindowTransform(HWND hwnd, in MAGTRANSFORM pTransform);
/// Shows or hides the system cursor.
///
/// Type: BOOL
/// TRUE to show the system cursor, or FALSE to hide it.
///
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
///
///
/// This function does not associate a reference count with the visibility state of the system cursor. Instead, the specified
/// visibility state takes effect immediately, regardless of any previous calls to MagShowSystemCursor.
///
/// The system cursor is always magnified when it is shown while the full-screen magnifier is active.
///
/// When used with a magnifier control, calls to MagShowSystemCursor have no effect on the magnified system cursor. The
/// visibility of the magnified system cursor depends on whether the magnifier control has the MS_SHOWMAGNIFIEDCURSOR style. If it
/// has this style, the magnifier control displays the magnified system cursor, along with the magnified screen content, whenever
/// the system cursor enters the source rectangle.
///
/// Examples
/// The following example uses the MagShowSystemCursor function to set the visibility state of the system cursor.
///
/// // Description: // Show or hide the system cursor. // // Parameters: // fShow - TRUE to show the system cursor, FALSE to hide it. // BOOL ShowSystemCursor(BOOL fShow) { BOOL fResult = MagShowSystemCursor(fShow); return fResult; }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-magshowsystemcursor BOOL MagShowSystemCursor(
// BOOL fShowCursor );
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagShowSystemCursor")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagShowSystemCursor([MarshalAs(UnmanagedType.Bool)] bool fShowCursor);
/// Destroys the magnifier run-time objects.
///
/// Type: BOOL
/// Returns TRUE if successful, or FALSE otherwise.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/nf-magnification-maguninitialize BOOL MagUninitialize();
[DllImport(Lib_Magnification, SetLastError = false, ExactSpelling = true)]
[PInvokeData("magnification.h", MSDNShortId = "NF:magnification.MagUninitialize")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MagUninitialize();
///
/// Describes a color transformation matrix that a magnifier control uses to apply a color effect to magnified screen content.
///
///
/// The values in the matrix are for red, blue, green, alpha, and color translation. For more information, see Using a Color Matrix
/// to Transform a Single Color in the Windows GDI+ documentation.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/ns-magnification-magcoloreffect typedef struct tagMAGCOLOREFFECT
// { float transform[5][5]; } MAGCOLOREFFECT, *PMAGCOLOREFFECT;
[PInvokeData("magnification.h", MSDNShortId = "NS:magnification.tagMAGCOLOREFFECT")]
[StructLayout(LayoutKind.Sequential)]
public struct MAGCOLOREFFECT
{
private const int dimLen = 5;
private float transform00;
private float transform01;
private float transform02;
private float transform03;
private float transform04;
private float transform10;
private float transform11;
private float transform12;
private float transform13;
private float transform14;
private float transform20;
private float transform21;
private float transform22;
private float transform23;
private float transform24;
private float transform30;
private float transform31;
private float transform32;
private float transform33;
private float transform34;
private float transform40;
private float transform41;
private float transform42;
private float transform43;
private float transform44;
/// Initializes a new instance of the struct with initial values.
/// The values.
public MAGCOLOREFFECT(float[,] values) : this() => transform = values;
///
/// Type: float[5,5]
/// The transformation matrix.
///
public float this[int x, int y]
{
get
{
if (x < 0 || x >= dimLen || y < 0 || y >= dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
return f[x * dimLen + y];
}
}
}
set
{
if (x < 0 || x >= dimLen || y < 0 || y >= dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
f[x * dimLen + y] = value;
}
}
}
}
///
/// Type: float[5,5]
/// The transformation matrix.
///
public float[,] transform
{
get => new float[,] { { transform00, transform01, transform02, transform03, transform04 },
{ transform10, transform11, transform12, transform13, transform14 },
{ transform20, transform21, transform22, transform23, transform24 },
{ transform30, transform31, transform32, transform33, transform34 },
{ transform40, transform41, transform42, transform43, transform44 } };
set
{
if (value is null) throw new ArgumentNullException();
if (value.Rank != 2 && value.GetLength(0) != dimLen && value.GetLength(1) != dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
f[x * dimLen + y] = value[x, y];
}
}
}
}
/// Gets a value indicating whether this is empty (all values are zero).
/// This property is if this is empty; otherwise, .
public bool IsEmpty
{
get
{
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f[x * dimLen + y] != 0f)
return false;
return true;
}
}
}
}
/// Gets a value indicating whether this is the identity matrix.
/// This property is if this is identity; otherwise, .
public bool IsIdentity
{
get
{
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f[x * dimLen + y] != (x == y ? 1f : 0f))
return false;
return true;
}
}
}
}
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
///
/// if the specified is equal to this instance; otherwise, .
///
public override bool Equals(object obj) => obj is MAGCOLOREFFECT m && Equals(m);
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
///
/// if the specified is equal to this instance; otherwise, .
///
public bool Equals(MAGCOLOREFFECT effect)
{
unsafe
{
fixed (float* f1 = &transform00)
{
float* f2 = &effect.transform00;
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f1[x * dimLen + y] != f2[x * dimLen + y])
return false;
return true;
}
}
}
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => transform.GetHashCode();
/// Implements the operator ==.
/// The left-hand side argument.
/// The right-hand side argument.
/// The result of the operator.
public static bool operator ==(MAGCOLOREFFECT lhs, MAGCOLOREFFECT rhs) => lhs.Equals(rhs);
/// Implements the operator !=.
/// The left-hand side argument.
/// The right-hand side argument.
/// The result of the operator.
public static bool operator !=(MAGCOLOREFFECT lhs, MAGCOLOREFFECT rhs) => !(lhs == rhs);
/// An Identity Matrix for MAGCOLOREFFECT.
public static readonly MAGCOLOREFFECT Identity = new MAGCOLOREFFECT { transform00 = 1, transform11 = 1, transform22 = 1, transform33 = 1, transform44 = 1 };
}
///
///
/// width
///
/// Type: UINT
/// The width of the image.
///
/// height
///
/// Type: UINT
/// The height of the image.
///
/// format
///
/// Type: WICPixelFormatGUID
///
/// A WICPixelFormatGUID (declared in wincodec.h) that specifies the pixel format of the image. For a list of available pixel
/// formats, see the Native Pixel Formats topic.
///
///
/// stride
///
/// Type: UINT
/// The stride, or number of bytes in a row of the image.
///
/// offset
///
/// Type: UINT
/// The offset of the start of the image data from the beginning of the file.
///
/// cbSize
///
/// Type: SIZE_T
/// The size of the data.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/ns-magnification-magimageheader typedef struct tagMAGIMAGEHEADER
// { UINT width; UINT height; WICPixelFormatGUID format; UINT stride; UINT offset; SIZE_T cbSize; } MAGIMAGEHEADER, *PMAGIMAGEHEADER;
[PInvokeData("magnification.h", MSDNShortId = "NS:magnification.tagMAGIMAGEHEADER")]
[StructLayout(LayoutKind.Sequential)]
public struct MAGIMAGEHEADER
{
///
/// Type: UINT
/// The width of the image.
///
public uint width;
///
/// Type: UINT
/// The height of the image.
///
public uint height;
///
/// Type: WICPixelFormatGUID
///
/// A WICPixelFormatGUID (declared in wincodec.h) that specifies the pixel format of the image. For a list of available pixel
/// formats, see the Native Pixel Formats topic.
///
///
public Guid format;
///
/// Type: UINT
/// The stride, or number of bytes in a row of the image.
///
public uint stride;
///
/// Type: UINT
/// The offset of the start of the image data from the beginning of the file.
///
public uint offset;
///
/// Type: SIZE_T
/// The size of the data.
///
public SizeT cbSize;
}
/// Describes a transformation matrix that a magnifier control uses to magnify screen content.
///
/// The transformation matrix is
/// (n, 0.0, 0.0)
/// (0.0, n, 0.0)
/// (0.0, 0.0, 1.0)
/// where n is the magnification factor.
///
// https://docs.microsoft.com/en-us/windows/win32/api/magnification/ns-magnification-magtransform typedef struct tagMAGTRANSFORM {
// float v[3][3]; } MAGTRANSFORM, *PMAGTRANSFORM;
[PInvokeData("magnification.h", MSDNShortId = "NS:magnification.tagMAGTRANSFORM")]
[StructLayout(LayoutKind.Sequential)]
public struct MAGTRANSFORM : IEquatable
{
private const int dimLen = 3;
private float transform00;
private float transform01;
private float transform02;
private float transform10;
private float transform11;
private float transform12;
private float transform20;
private float transform21;
private float transform22;
/// Initializes a new instance of the struct with initial values.
/// The values.
public MAGTRANSFORM(float[,] values) : this() => transform = values;
///
/// Initializes a new instance of the struct with the magnification value set into the transformation matrix.
///
/// The magnification value.
public MAGTRANSFORM(float magnification) : this() { transform00 = transform11 = magnification; transform22 = 1f; }
///
/// Type: float[3,3]
/// The transformation matrix.
///
public float this[int x, int y]
{
get
{
if (x < 0 || x >= dimLen || y < 0 || y >= dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
return f[x * dimLen + y];
}
}
}
set
{
if (x < 0 || x >= dimLen || y < 0 || y >= dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
f[x * dimLen + y] = value;
}
}
}
}
///
/// Type: float[3,3]
/// The transformation matrix.
///
public float[,] transform
{
get => new float[,] { { transform00, transform01, transform02 },
{ transform10, transform11, transform12 },
{ transform20, transform21, transform22 } };
set
{
if (value is null) throw new ArgumentNullException();
if (value.Rank != 2 && value.GetLength(0) != dimLen && value.GetLength(1) != dimLen)
throw new ArgumentOutOfRangeException();
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
f[x * dimLen + y] = value[x, y];
}
}
}
}
/// Gets a value indicating whether this is empty (all values are zero).
/// This property is if this is empty; otherwise, .
public bool IsEmpty
{
get
{
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f[x * dimLen + y] != 0f)
return false;
return true;
}
}
}
}
/// Gets a value indicating whether this is the identity matrix.
/// This property is if this is identity; otherwise, .
public bool IsIdentity
{
get
{
unsafe
{
fixed (float* f = &transform00)
{
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f[x * dimLen + y] != (x == y ? 1f : 0f))
return false;
return true;
}
}
}
}
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
///
/// if the specified is equal to this instance; otherwise, .
///
public override bool Equals(object obj) => obj is MAGTRANSFORM m && Equals(m);
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
///
/// if the specified is equal to this instance; otherwise, .
///
public bool Equals(MAGTRANSFORM effect)
{
unsafe
{
fixed (float* f1 = &transform00)
{
float* f2 = &effect.transform00;
for (int x = 0; x < dimLen; x++)
for (int y = 0; y < dimLen; y++)
if (f1[x * dimLen + y] != f2[x * dimLen + y])
return false;
return true;
}
}
}
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => transform.GetHashCode();
/// Implements the operator ==.
/// The left-hand side argument.
/// The right-hand side argument.
/// The result of the operator.
public static bool operator ==(MAGTRANSFORM lhs, MAGTRANSFORM rhs) => lhs.Equals(rhs);
/// Implements the operator !=.
/// The left-hand side argument.
/// The right-hand side argument.
/// The result of the operator.
public static bool operator !=(MAGTRANSFORM lhs, MAGTRANSFORM rhs) => !(lhs == rhs);
/// An Identity Matrix for MAGTRANSFORM.
public static readonly MAGTRANSFORM Identity = new MAGTRANSFORM { transform00 = 1, transform11 = 1, transform22 = 1 };
}
}
}