using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; using Vanara.InteropServices; using static Vanara.PInvoke.Gdi32; namespace Vanara.PInvoke { /// User32.dll function with GDI params. public static partial class User32 { /// public const int OCM_NOTIFY = 0x204E; // WM_NOTIFY + WM_REFLECT /// Flags used by . [PInvokeData("winuser.h", MSDNShortId = "208bf1cc-c03c-4d03-92e4-32fcf856b4d8")] [Flags] public enum ChangeDisplaySettingsFlags { /// The graphics mode for the current screen will be changed dynamically. CDS_DEFAULT = 0, /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. /// The mode information is stored in the USER profile. /// CDS_UPDATEREGISTRY = 0x00000001, /// The system tests if the requested graphics mode could be set. CDS_TEST = 0x00000002, /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. CDS_FULLSCREEN = 0x00000004, /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// CDS_GLOBAL = 0x00000008, /// This device will become the primary device. CDS_SET_PRIMARY = 0x00000010, /// When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure. CDS_VIDEOPARAMETERS = 0x00000020, /// Enables settings changes to unsafe graphics modes. CDS_ENABLE_UNSAFE_MODES = 0x00000100, /// Disables settings changes to unsafe graphics modes. CDS_DISABLE_UNSAFE_MODES = 0x00000200, /// The settings should be changed, even if the requested settings are the same as the current settings. CDS_RESET = 0x40000000, /// Undocumented CDS_RESET_EX = 0x20000000, /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// CDS_NORESET = 0x10000000, } /// Options for CopyImage. [Flags] public enum CopyImageOptions { /// /// Returns the original hImage if it satisfies the criteria for the copy—that is, correct dimensions and color depth—in which /// case the LR_COPYDELETEORG flag is ignored. If this flag is not specified, a new object is always created. /// LR_COPYRETURNORG = 0x00000004, /// Deletes the original image after creating the copy. LR_COPYDELETEORG = 0x00000008, /// /// Tries to reload an icon or cursor resource from the original resource file rather than simply copying the current image. This /// is useful for creating a different-sized copy when the resource file contains multiple sizes of the resource. Without this /// flag, CopyImage stretches the original image to the new size. If this flag is set, CopyImage uses the size in the resource /// file closest to the desired size. This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with /// the LR_SHARED flag. /// LR_COPYFROMRESOURCE = 0x00004000, /// /// When the uType parameter specifies IMAGE_BITMAP, causes the function to return a DIB section bitmap rather than a compatible /// bitmap. This flag is useful for loading a bitmap without mapping it to the colors of the display device. /// LR_CREATEDIBSECTION = 0x00002000, /// /// Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are /// set to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource /// size. If the resource contains multiple images, the function uses the size of the first image. /// LR_DEFAULTSIZE = 0x00000040, /// Loads the image in black and white. LR_MONOCHROME = 0x00000001, } /// Flags used by . [PInvokeData("winuser.h", MSDNShortId = "590cf928-0ad6-43f8-97e9-1dafbcfa9f49")] [Flags] public enum DCX { /// Returns a DC that corresponds to the window rectangle rather than the client rectangle. DCX_WINDOW = 0x00000001, /// Returns a DC from the cache, rather than the OWNDC or CLASSDC window. Essentially overrides CS_OWNDC and CS_CLASSDC. DCX_CACHE = 0x00000002, /// This flag is ignored. DCX_NORESETATTRS = 0x00000004, /// Excludes the visible regions of all child windows below the window identified by hWnd. DCX_CLIPCHILDREN = 0x00000008, /// Excludes the visible regions of all sibling windows above the window identified by hWnd. DCX_CLIPSIBLINGS = 0x00000010, /// /// Uses the visible region of the parent window. The parent's WS_CLIPCHILDREN and CS_PARENTDC style bits are ignored. The origin /// is set to the upper-left corner of the window identified by hWnd. /// DCX_PARENTCLIP = 0x00000020, /// The clipping region identified by hrgnClip is excluded from the visible region of the returned DC. DCX_EXCLUDERGN = 0x00000040, /// The clipping region identified by hrgnClip is intersected with the visible region of the returned DC. DCX_INTERSECTRGN = 0x00000080, /// Returns a region that excludes the window's update region. DCX_EXCLUDEUPDATE = 0x00000100, /// Returns a region that includes the window's update region. DCX_INTERSECTUPDATE = 0x00000200, /// /// Allows drawing even if there is a LockWindowUpdate call in effect that would otherwise exclude this window. Used for drawing /// during tracking. /// DCX_LOCKWINDOWUPDATE = 0x00000400, /// /// When specified with DCX_INTERSECTUPDATE, causes the device context to be completely validated. /// Using this function with both DCX_INTERSECTUPDATE and DCX_VALIDATE is identical to using the BeginPaint function. /// DCX_VALIDATE = 0x00200000, } /// Flags for [PInvokeData("winuser.h", MSDNShortId = "55fbb7e8-79b4-4011-b522-25ea5a928b86")] [Flags] public enum GR { /// Return the count of GDI objects. GR_GDIOBJECTS = 0, /// /// Return the peak count of GDI objects. /// /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not supported until Windows 7 and /// Windows Server 2008 R2. /// /// GR_GDIOBJECTS_PEAK = 2, /// Return the count of USER objects. GR_USEROBJECTS = 1, /// /// Return the peak count of USER objects. /// /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not supported until Windows 7 and /// Windows Server 2008 R2. /// /// GR_USEROBJECTS_PEAK = 4, } /// Values to use a return codes when handling the WM_HCHITTEST message. public enum HitTestValues : short { /// In the border of a window that does not have a sizing border. HTBORDER = 18, /// In the lower-horizontal border of a resizable window (the user can click the mouse to resize the window vertically). HTBOTTOM = 15, /// /// In the lower-left corner of a border of a resizable window (the user can click the mouse to resize the window diagonally). /// HTBOTTOMLEFT = 16, /// /// In the lower-right corner of a border of a resizable window (the user can click the mouse to resize the window diagonally). /// HTBOTTOMRIGHT = 17, /// In a title bar. HTCAPTION = 2, /// In a client area. HTCLIENT = 1, /// In a Close button. HTCLOSE = 20, /// /// On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the DefWindowProc function /// produces a system beep to indicate an error). /// HTERROR = -2, /// In a size box (same as HTSIZE). HTGROWBOX = 4, /// In a Help button. HTHELP = 21, /// In a horizontal scroll bar. HTHSCROLL = 6, /// In the left border of a resizable window (the user can click the mouse to resize the window horizontally). HTLEFT = 10, /// In a menu. HTMENU = 5, /// In a Maximize button. HTMAXBUTTON = 9, /// In a Minimize button. HTMINBUTTON = 8, /// On the screen background or on a dividing line between windows. HTNOWHERE = 0, /* /// Not implemented. HTOBJECT = 19, */ /// In a Minimize button. HTREDUCE = HTMINBUTTON, /// In the right border of a resizable window (the user can click the mouse to resize the window horizontally). HTRIGHT = 11, /// In a size box (same as HTGROWBOX). HTSIZE = HTGROWBOX, /// In a window menu or in a Close button in a child window. HTSYSMENU = 3, /// In the upper-horizontal border of a window. HTTOP = 12, /// In the upper-left corner of a window border. HTTOPLEFT = 13, /// In the upper-right corner of a window border. HTTOPRIGHT = 14, /// /// In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the /// same thread until one of them returns a code that is not HTTRANSPARENT). /// HTTRANSPARENT = -1, /// In the vertical scroll bar. HTVSCROLL = 7, /// In a Maximize button. HTZOOM = HTMAXBUTTON, } /// /// Flags used for and methods to retrieve information about a window. /// public enum WindowLongFlags { /// The extended window styles GWL_EXSTYLE = -20, /// The application instance handle GWL_HINSTANCE = -6, /// The parent window handle GWL_HWNDPARENT = -8, /// The window identifier GWL_ID = -12, /// The window styles GWL_STYLE = -16, /// The window user data GWL_USERDATA = -21, /// The window procedure address or handle GWL_WNDPROC = -4, /// The dialog user data DWLP_USER = 0x8, /// The dialog procedure message result DWLP_MSGRESULT = 0x0, /// The dialog procedure address or handle DWLP_DLGPROC = 0x4 } /// /// /// The ChangeDisplaySettings function changes the settings of the default display device to the specified graphics mode. /// /// To change the settings of a specified display device, use the ChangeDisplaySettingsEx function. /// /// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 /// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 /// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates /// these modes but still runs in 32-bit color mode. /// /// /// /// /// A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in /// the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags /// parameter is the easiest way to return to the default mode after a dynamic mode change. /// /// /// The dmSize member of DEVMODE must be initialized to the size, in bytes, of the DEVMODE structure. The /// dmDriverExtra member of DEVMODE must be initialized to indicate the number of bytes of private driver data /// following the DEVMODE structure. In addition, you can use any or all of the following members of the DEVMODE structure. /// /// /// /// Member /// Meaning /// /// /// dmBitsPerPel /// Bits per pixel /// /// /// dmPelsWidth /// Pixel width /// /// /// dmPelsHeight /// Pixel height /// /// /// dmDisplayFlags /// Mode flags /// /// /// dmDisplayFrequency /// Mode frequency /// /// /// dmPosition /// Position of the device in a multi-monitor configuration. /// /// /// /// In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the /// dmFields member to change the display setting. /// /// /// /// Indicates how the graphics mode should be changed. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// The graphics mode for the current screen will be changed dynamically. /// /// /// CDS_FULLSCREEN /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. /// /// /// CDS_GLOBAL /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_NORESET /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_RESET /// The settings should be changed, even if the requested settings are the same as the current settings. /// /// /// CDS_SET_PRIMARY /// This device will become the primary device. /// /// /// CDS_TEST /// The system tests if the requested graphics mode could be set. /// /// /// CDS_UPDATEREGISTRY /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The /// mode information is stored in the USER profile. /// /// /// /// /// Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to /// change to that graphics mode. /// /// /// If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the /// registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information /// is stored in the registry and DISP_CHANGE_RESTART is returned. /// /// /// If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and /// DISP_CHANGE_NOTUPDATED is returned. /// /// /// /// The ChangeDisplaySettings function returns one of the following values. /// /// /// Return code /// Description /// /// /// DISP_CHANGE_SUCCESSFUL /// The settings change was successful. /// /// /// DISP_CHANGE_BADDUALVIEW /// The settings change was unsuccessful because the system is DualView capable. /// /// /// DISP_CHANGE_BADFLAGS /// An invalid set of flags was passed in. /// /// /// DISP_CHANGE_BADMODE /// The graphics mode is not supported. /// /// /// DISP_CHANGE_BADPARAM /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. /// /// /// DISP_CHANGE_FAILED /// The display driver failed the specified graphics mode. /// /// /// DISP_CHANGE_NOTUPDATED /// Unable to write settings to the registry. /// /// /// DISP_CHANGE_RESTART /// The computer must be restarted for the graphics mode to work. /// /// /// /// /// /// To ensure that the DEVMODE structure passed to ChangeDisplaySettings is valid and contains only values supported by the /// display driver, use the DEVMODE returned by the EnumDisplaySettings function. /// /// /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following /// message parameters. /// /// /// /// Parameters /// Meaning /// /// /// wParam /// New bits per pixel /// /// /// LOWORD(lParam) /// New pixel width /// /// /// HIWORD(lParam) /// New pixel height /// /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The input given is always in terms of physical pixels, and is not related to /// the calling context. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-changedisplaysettingsa LONG ChangeDisplaySettingsA( // DEVMODEA *lpDevMode, DWORD dwFlags ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "208bf1cc-c03c-4d03-92e4-32fcf856b4d8")] public static extern int ChangeDisplaySettings(in DEVMODE lpDevMode, ChangeDisplaySettingsFlags dwFlags); /// /// /// The ChangeDisplaySettings function changes the settings of the default display device to the specified graphics mode. /// /// To change the settings of a specified display device, use the ChangeDisplaySettingsEx function. /// /// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 /// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 /// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates /// these modes but still runs in 32-bit color mode. /// /// /// /// /// A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in /// the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags /// parameter is the easiest way to return to the default mode after a dynamic mode change. /// /// /// The dmSize member of DEVMODE must be initialized to the size, in bytes, of the DEVMODE structure. The /// dmDriverExtra member of DEVMODE must be initialized to indicate the number of bytes of private driver data /// following the DEVMODE structure. In addition, you can use any or all of the following members of the DEVMODE structure. /// /// /// /// Member /// Meaning /// /// /// dmBitsPerPel /// Bits per pixel /// /// /// dmPelsWidth /// Pixel width /// /// /// dmPelsHeight /// Pixel height /// /// /// dmDisplayFlags /// Mode flags /// /// /// dmDisplayFrequency /// Mode frequency /// /// /// dmPosition /// Position of the device in a multi-monitor configuration. /// /// /// /// In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the /// dmFields member to change the display setting. /// /// /// /// Indicates how the graphics mode should be changed. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// The graphics mode for the current screen will be changed dynamically. /// /// /// CDS_FULLSCREEN /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. /// /// /// CDS_GLOBAL /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_NORESET /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_RESET /// The settings should be changed, even if the requested settings are the same as the current settings. /// /// /// CDS_SET_PRIMARY /// This device will become the primary device. /// /// /// CDS_TEST /// The system tests if the requested graphics mode could be set. /// /// /// CDS_UPDATEREGISTRY /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The /// mode information is stored in the USER profile. /// /// /// /// /// Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to /// change to that graphics mode. /// /// /// If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the /// registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information /// is stored in the registry and DISP_CHANGE_RESTART is returned. /// /// /// If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and /// DISP_CHANGE_NOTUPDATED is returned. /// /// /// /// The ChangeDisplaySettings function returns one of the following values. /// /// /// Return code /// Description /// /// /// DISP_CHANGE_SUCCESSFUL /// The settings change was successful. /// /// /// DISP_CHANGE_BADDUALVIEW /// The settings change was unsuccessful because the system is DualView capable. /// /// /// DISP_CHANGE_BADFLAGS /// An invalid set of flags was passed in. /// /// /// DISP_CHANGE_BADMODE /// The graphics mode is not supported. /// /// /// DISP_CHANGE_BADPARAM /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. /// /// /// DISP_CHANGE_FAILED /// The display driver failed the specified graphics mode. /// /// /// DISP_CHANGE_NOTUPDATED /// Unable to write settings to the registry. /// /// /// DISP_CHANGE_RESTART /// The computer must be restarted for the graphics mode to work. /// /// /// /// /// /// To ensure that the DEVMODE structure passed to ChangeDisplaySettings is valid and contains only values supported by the /// display driver, use the DEVMODE returned by the EnumDisplaySettings function. /// /// /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following /// message parameters. /// /// /// /// Parameters /// Meaning /// /// /// wParam /// New bits per pixel /// /// /// LOWORD(lParam) /// New pixel width /// /// /// HIWORD(lParam) /// New pixel height /// /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The input given is always in terms of physical pixels, and is not related to /// the calling context. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-changedisplaysettingsa LONG ChangeDisplaySettingsA( // DEVMODEA *lpDevMode, DWORD dwFlags ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "208bf1cc-c03c-4d03-92e4-32fcf856b4d8")] public static extern int ChangeDisplaySettings([Optional] IntPtr lpDevMode, ChangeDisplaySettingsFlags dwFlags); /// /// /// The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. /// /// /// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 /// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 /// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates /// these modes but still runs in 32-bit color mode. /// /// /// /// /// A pointer to a null-terminated string that specifies the display device whose graphics mode will change. Only display device /// names as returned by EnumDisplayDevices are valid. See EnumDisplayDevices for further information on the names associated /// with these display devices. /// /// /// The lpszDeviceName parameter can be NULL. A NULL value specifies the default display device. The default device can /// be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag. /// /// /// /// /// A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in /// the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags /// parameter is the easiest way to return to the default mode after a dynamic mode change. /// /// /// The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member /// must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure. In addition, /// you can use any of the following members of the DEVMODE structure. /// /// /// /// Member /// Meaning /// /// /// dmBitsPerPel /// Bits per pixel /// /// /// dmPelsWidth /// Pixel width /// /// /// dmPelsHeight /// Pixel height /// /// /// dmDisplayFlags /// Mode flags /// /// /// dmDisplayFrequency /// Mode frequency /// /// /// dmPosition /// Position of the device in a multi-monitor configuration. /// /// /// /// In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the /// dmFields member to change the display settings. /// /// /// /// Value /// Meaning /// /// /// DM_BITSPERPEL /// Use the dmBitsPerPel value. /// /// /// DM_PELSWIDTH /// Use the dmPelsWidth value. /// /// /// DM_PELSHEIGHT /// Use the dmPelsHeight value. /// /// /// DM_DISPLAYFLAGS /// Use the dmDisplayFlags value. /// /// /// DM_DISPLAYFREQUENCY /// Use the dmDisplayFrequency value. /// /// /// DM_POSITION /// Use the dmPosition value. /// /// /// /// Reserved; must be NULL. /// /// Indicates how the graphics mode should be changed. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// The graphics mode for the current screen will be changed dynamically. /// /// /// CDS_FULLSCREEN /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. /// /// /// CDS_GLOBAL /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_NORESET /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_RESET /// The settings should be changed, even if the requested settings are the same as the current settings. /// /// /// CDS_SET_PRIMARY /// This device will become the primary device. /// /// /// CDS_TEST /// The system tests if the requested graphics mode could be set. /// /// /// CDS_UPDATEREGISTRY /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The /// mode information is stored in the USER profile. /// /// /// /// CDS_VIDEOPARAMETERS /// When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure. /// /// /// CDS_ENABLE_UNSAFE_MODES /// Enables settings changes to unsafe graphics modes. /// /// /// CDS_DISABLE_UNSAFE_MODES /// Disables settings changes to unsafe graphics modes. /// /// /// /// Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to /// change to them. /// /// /// If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the /// registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information /// is stored in the registry and DISP_CHANGE_RESTART is returned. /// /// /// If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and /// DISP_CHANGE_NOTUPDATED is returned. /// /// /// /// If dwFlags is CDS_VIDEOPARAMETERS, lParam is a pointer to a VIDEOPARAMETERS structure. Otherwise lParam must be NULL. /// /// /// The ChangeDisplaySettingsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// DISP_CHANGE_SUCCESSFUL /// The settings change was successful. /// /// /// DISP_CHANGE_BADDUALVIEW /// The settings change was unsuccessful because the system is DualView capable. /// /// /// DISP_CHANGE_BADFLAGS /// An invalid set of flags was passed in. /// /// /// DISP_CHANGE_BADMODE /// The graphics mode is not supported. /// /// /// DISP_CHANGE_BADPARAM /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. /// /// /// DISP_CHANGE_FAILED /// The display driver failed the specified graphics mode. /// /// /// DISP_CHANGE_NOTUPDATED /// Unable to write settings to the registry. /// /// /// DISP_CHANGE_RESTART /// The computer must be restarted for the graphics mode to work. /// /// /// /// /// /// To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx is valid and contains only values supported by the /// display driver, use the DEVMODE returned by the EnumDisplaySettings function. /// /// /// When adding a display monitor to a multiple-monitor system programmatically, set DEVMODE.dmFields to DM_POSITION and /// specify a position (in DEVMODE.dmPosition) for the monitor you are adding that is adjacent to at least one pixel of the /// display area of an existing monitor. To detach the monitor, set DEVMODE.dmFields to DM_POSITION but set /// DEVMODE.dmPelsWidth and DEVMODE.dmPelsHeight to zero. For more information, see Multiple Display Monitors. /// /// /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following /// message parameters. /// /// /// /// Parameters /// Meaning /// /// /// wParam /// New bits per pixel /// /// /// LOWORD(lParam) /// New pixel width /// /// /// HIWORD(lParam) /// New pixel height /// /// /// /// To change the settings for more than one display at the same time, first call ChangeDisplaySettingsEx for each device /// individually to update the registry without applying the changes. Then call ChangeDisplaySettingsEx once more, with a /// NULL device, to apply the changes. For example, to change the settings for two displays, do the following: /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The input given is always in terms of physical pixels, and is not related to /// the calling context. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-changedisplaysettingsexa LONG ChangeDisplaySettingsExA( // LPCSTR lpszDeviceName, DEVMODEA *lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "1448e04c-1452-4eab-bda4-4d249cb67a24")] public static extern int ChangeDisplaySettingsEx([Optional] string lpszDeviceName, in DEVMODE lpDevMode, [Optional] HWND hwnd, [Optional] ChangeDisplaySettingsFlags dwflags, [Optional] IntPtr lParam); /// /// /// The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. /// /// /// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 /// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 /// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates /// these modes but still runs in 32-bit color mode. /// /// /// /// /// A pointer to a null-terminated string that specifies the display device whose graphics mode will change. Only display device /// names as returned by EnumDisplayDevices are valid. See EnumDisplayDevices for further information on the names associated /// with these display devices. /// /// /// The lpszDeviceName parameter can be NULL. A NULL value specifies the default display device. The default device can /// be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag. /// /// /// /// /// A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in /// the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags /// parameter is the easiest way to return to the default mode after a dynamic mode change. /// /// /// The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member /// must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure. In addition, /// you can use any of the following members of the DEVMODE structure. /// /// /// /// Member /// Meaning /// /// /// dmBitsPerPel /// Bits per pixel /// /// /// dmPelsWidth /// Pixel width /// /// /// dmPelsHeight /// Pixel height /// /// /// dmDisplayFlags /// Mode flags /// /// /// dmDisplayFrequency /// Mode frequency /// /// /// dmPosition /// Position of the device in a multi-monitor configuration. /// /// /// /// In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the /// dmFields member to change the display settings. /// /// /// /// Value /// Meaning /// /// /// DM_BITSPERPEL /// Use the dmBitsPerPel value. /// /// /// DM_PELSWIDTH /// Use the dmPelsWidth value. /// /// /// DM_PELSHEIGHT /// Use the dmPelsHeight value. /// /// /// DM_DISPLAYFLAGS /// Use the dmDisplayFlags value. /// /// /// DM_DISPLAYFREQUENCY /// Use the dmDisplayFrequency value. /// /// /// DM_POSITION /// Use the dmPosition value. /// /// /// /// Reserved; must be NULL. /// /// Indicates how the graphics mode should be changed. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// The graphics mode for the current screen will be changed dynamically. /// /// /// CDS_FULLSCREEN /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. /// /// /// CDS_GLOBAL /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_NORESET /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_RESET /// The settings should be changed, even if the requested settings are the same as the current settings. /// /// /// CDS_SET_PRIMARY /// This device will become the primary device. /// /// /// CDS_TEST /// The system tests if the requested graphics mode could be set. /// /// /// CDS_UPDATEREGISTRY /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The /// mode information is stored in the USER profile. /// /// /// /// CDS_VIDEOPARAMETERS /// When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure. /// /// /// CDS_ENABLE_UNSAFE_MODES /// Enables settings changes to unsafe graphics modes. /// /// /// CDS_DISABLE_UNSAFE_MODES /// Disables settings changes to unsafe graphics modes. /// /// /// /// Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to /// change to them. /// /// /// If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the /// registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information /// is stored in the registry and DISP_CHANGE_RESTART is returned. /// /// /// If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and /// DISP_CHANGE_NOTUPDATED is returned. /// /// /// /// If dwFlags is CDS_VIDEOPARAMETERS, lParam is a pointer to a VIDEOPARAMETERS structure. Otherwise lParam must be NULL. /// /// /// The ChangeDisplaySettingsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// DISP_CHANGE_SUCCESSFUL /// The settings change was successful. /// /// /// DISP_CHANGE_BADDUALVIEW /// The settings change was unsuccessful because the system is DualView capable. /// /// /// DISP_CHANGE_BADFLAGS /// An invalid set of flags was passed in. /// /// /// DISP_CHANGE_BADMODE /// The graphics mode is not supported. /// /// /// DISP_CHANGE_BADPARAM /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. /// /// /// DISP_CHANGE_FAILED /// The display driver failed the specified graphics mode. /// /// /// DISP_CHANGE_NOTUPDATED /// Unable to write settings to the registry. /// /// /// DISP_CHANGE_RESTART /// The computer must be restarted for the graphics mode to work. /// /// /// /// /// /// To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx is valid and contains only values supported by the /// display driver, use the DEVMODE returned by the EnumDisplaySettings function. /// /// /// When adding a display monitor to a multiple-monitor system programmatically, set DEVMODE.dmFields to DM_POSITION and /// specify a position (in DEVMODE.dmPosition) for the monitor you are adding that is adjacent to at least one pixel of the /// display area of an existing monitor. To detach the monitor, set DEVMODE.dmFields to DM_POSITION but set /// DEVMODE.dmPelsWidth and DEVMODE.dmPelsHeight to zero. For more information, see Multiple Display Monitors. /// /// /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following /// message parameters. /// /// /// /// Parameters /// Meaning /// /// /// wParam /// New bits per pixel /// /// /// LOWORD(lParam) /// New pixel width /// /// /// HIWORD(lParam) /// New pixel height /// /// /// /// To change the settings for more than one display at the same time, first call ChangeDisplaySettingsEx for each device /// individually to update the registry without applying the changes. Then call ChangeDisplaySettingsEx once more, with a /// NULL device, to apply the changes. For example, to change the settings for two displays, do the following: /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The input given is always in terms of physical pixels, and is not related to /// the calling context. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-changedisplaysettingsexa LONG ChangeDisplaySettingsExA( // LPCSTR lpszDeviceName, DEVMODEA *lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "1448e04c-1452-4eab-bda4-4d249cb67a24")] public static extern int ChangeDisplaySettingsEx([Optional] string lpszDeviceName, [Optional] IntPtr lpDevMode, [Optional] HWND hwnd, [Optional] ChangeDisplaySettingsFlags dwflags, [Optional] IntPtr lParam); /// /// /// The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. /// /// /// Note Apps that you design to target Windows 8 and later can no longer query or set display modes that are less than 32 /// bits per pixel (bpp); these operations will fail. These apps have a compatibility manifest that targets Windows 8. Windows 8 /// still supports 8-bit and 16-bit color modes for desktop apps that were built without a Windows 8 manifest; Windows 8 emulates /// these modes but still runs in 32-bit color mode. /// /// /// /// /// A pointer to a null-terminated string that specifies the display device whose graphics mode will change. Only display device /// names as returned by EnumDisplayDevices are valid. See EnumDisplayDevices for further information on the names associated /// with these display devices. /// /// /// The lpszDeviceName parameter can be NULL. A NULL value specifies the default display device. The default device can /// be determined by calling EnumDisplayDevices and checking for the DISPLAY_DEVICE_PRIMARY_DEVICE flag. /// /// /// /// /// A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in /// the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags /// parameter is the easiest way to return to the default mode after a dynamic mode change. /// /// /// The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member /// must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure. In addition, /// you can use any of the following members of the DEVMODE structure. /// /// /// /// Member /// Meaning /// /// /// dmBitsPerPel /// Bits per pixel /// /// /// dmPelsWidth /// Pixel width /// /// /// dmPelsHeight /// Pixel height /// /// /// dmDisplayFlags /// Mode flags /// /// /// dmDisplayFrequency /// Mode frequency /// /// /// dmPosition /// Position of the device in a multi-monitor configuration. /// /// /// /// In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the /// dmFields member to change the display settings. /// /// /// /// Value /// Meaning /// /// /// DM_BITSPERPEL /// Use the dmBitsPerPel value. /// /// /// DM_PELSWIDTH /// Use the dmPelsWidth value. /// /// /// DM_PELSHEIGHT /// Use the dmPelsHeight value. /// /// /// DM_DISPLAYFLAGS /// Use the dmDisplayFlags value. /// /// /// DM_DISPLAYFREQUENCY /// Use the dmDisplayFrequency value. /// /// /// DM_POSITION /// Use the dmPosition value. /// /// /// /// Reserved; must be NULL. /// /// Indicates how the graphics mode should be changed. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// 0 /// The graphics mode for the current screen will be changed dynamically. /// /// /// CDS_FULLSCREEN /// The mode is temporary in nature. If you change to and from another desktop, this mode will not be reset. /// /// /// CDS_GLOBAL /// /// The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the /// settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_NORESET /// /// The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the /// CDS_UPDATEREGISTRY flag. /// /// /// /// CDS_RESET /// The settings should be changed, even if the requested settings are the same as the current settings. /// /// /// CDS_SET_PRIMARY /// This device will become the primary device. /// /// /// CDS_TEST /// The system tests if the requested graphics mode could be set. /// /// /// CDS_UPDATEREGISTRY /// /// The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The /// mode information is stored in the USER profile. /// /// /// /// CDS_VIDEOPARAMETERS /// When set, the lParam parameter is a pointer to a VIDEOPARAMETERS structure. /// /// /// CDS_ENABLE_UNSAFE_MODES /// Enables settings changes to unsafe graphics modes. /// /// /// CDS_DISABLE_UNSAFE_MODES /// Disables settings changes to unsafe graphics modes. /// /// /// /// Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to /// change to them. /// /// /// If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the /// registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information /// is stored in the registry and DISP_CHANGE_RESTART is returned. /// /// /// If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and /// DISP_CHANGE_NOTUPDATED is returned. /// /// /// /// If dwFlags is CDS_VIDEOPARAMETERS, lParam is a pointer to a VIDEOPARAMETERS structure. Otherwise lParam must be NULL. /// /// /// The ChangeDisplaySettingsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// DISP_CHANGE_SUCCESSFUL /// The settings change was successful. /// /// /// DISP_CHANGE_BADDUALVIEW /// The settings change was unsuccessful because the system is DualView capable. /// /// /// DISP_CHANGE_BADFLAGS /// An invalid set of flags was passed in. /// /// /// DISP_CHANGE_BADMODE /// The graphics mode is not supported. /// /// /// DISP_CHANGE_BADPARAM /// An invalid parameter was passed in. This can include an invalid flag or combination of flags. /// /// /// DISP_CHANGE_FAILED /// The display driver failed the specified graphics mode. /// /// /// DISP_CHANGE_NOTUPDATED /// Unable to write settings to the registry. /// /// /// DISP_CHANGE_RESTART /// The computer must be restarted for the graphics mode to work. /// /// /// /// /// /// To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx is valid and contains only values supported by the /// display driver, use the DEVMODE returned by the EnumDisplaySettings function. /// /// /// When adding a display monitor to a multiple-monitor system programmatically, set DEVMODE.dmFields to DM_POSITION and /// specify a position (in DEVMODE.dmPosition) for the monitor you are adding that is adjacent to at least one pixel of the /// display area of an existing monitor. To detach the monitor, set DEVMODE.dmFields to DM_POSITION but set /// DEVMODE.dmPelsWidth and DEVMODE.dmPelsHeight to zero. For more information, see Multiple Display Monitors. /// /// /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following /// message parameters. /// /// /// /// Parameters /// Meaning /// /// /// wParam /// New bits per pixel /// /// /// LOWORD(lParam) /// New pixel width /// /// /// HIWORD(lParam) /// New pixel height /// /// /// /// To change the settings for more than one display at the same time, first call ChangeDisplaySettingsEx for each device /// individually to update the registry without applying the changes. Then call ChangeDisplaySettingsEx once more, with a /// NULL device, to apply the changes. For example, to change the settings for two displays, do the following: /// /// DPI Virtualization /// /// This API does not participate in DPI virtualization. The input given is always in terms of physical pixels, and is not related to /// the calling context. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-changedisplaysettingsexa LONG ChangeDisplaySettingsExA( // LPCSTR lpszDeviceName, DEVMODEA *lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "1448e04c-1452-4eab-bda4-4d249cb67a24")] public static extern int ChangeDisplaySettingsEx([Optional] string lpszDeviceName, in DEVMODE lpDevMode, [Optional] HWND hwnd, [Optional] ChangeDisplaySettingsFlags dwflags, in VIDEOPARAMETERS lParam); /// /// Creates a new image (icon, cursor, or bitmap) and copies the attributes of the specified image to the new one. If necessary, the /// function stretches the bits to fit the desired size of the new image. /// /// /// Type: HANDLE /// A handle to the image to be copied. /// /// /// Type: UINT /// The type of image to be copied. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// IMAGE_BITMAP 0 /// Copies a bitmap. /// /// /// IMAGE_CURSOR 2 /// Copies a cursor. /// /// /// IMAGE_ICON 1 /// Copies an icon. /// /// /// /// /// Type: int /// /// The desired width, in pixels, of the image. If this is zero, then the returned image will have the same width as the original hImage. /// /// /// /// Type: int /// /// The desired height, in pixels, of the image. If this is zero, then the returned image will have the same height as the original hImage. /// /// /// /// Type: UINT /// This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// LR_COPYDELETEORG 0x00000008 /// Deletes the original image after creating the copy. /// /// /// LR_COPYFROMRESOURCE 0x00004000 /// /// Tries to reload an icon or cursor resource from the original resource file rather than simply copying the current image. This is /// useful for creating a different-sized copy when the resource file contains multiple sizes of the resource. Without this flag, /// CopyImage stretches the original image to the new size. If this flag is set, CopyImage uses the size in the resource file closest /// to the desired size. This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with the LR_SHARED flag. /// /// /// /// LR_COPYRETURNORG 0x00000004 /// /// Returns the original hImage if it satisfies the criteria for the copy—that is, correct dimensions and color depth—in which case /// the LR_COPYDELETEORG flag is ignored. If this flag is not specified, a new object is always created. /// /// /// /// LR_CREATEDIBSECTION 0x00002000 /// /// If this is set and a new bitmap is created, the bitmap is created as a DIB section. Otherwise, the bitmap image is created as a /// device-dependent bitmap. This flag is only valid if uType is IMAGE_BITMAP. /// /// /// /// LR_DEFAULTSIZE 0x00000040 /// /// Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set /// to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. /// If the resource contains multiple images, the function uses the size of the first image. /// /// /// /// LR_MONOCHROME 0x00000001 /// Creates a new monochrome image. /// /// /// /// /// Type: HANDLE /// If the function succeeds, the return value is the handle to the newly created image. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// /// When you are finished using the resource, you can release its associated memory by calling one of the functions in the following table. /// /// /// /// Resource /// Release function /// /// /// Bitmap /// DeleteObject /// /// /// Cursor /// DestroyCursor /// /// /// Icon /// DestroyIcon /// /// /// /// The system automatically deletes the resource when its process terminates, however, calling the appropriate function saves memory /// and decreases the size of the process's working set. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-copyimage HANDLE CopyImage( HANDLE h, UINT type, int cx, // int cy, UINT flags ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h")] public static extern HANDLE CopyImage(HANDLE h, LoadImageType type, [Optional] int cx, [Optional] int cy, [Optional] CopyImageOptions flags); /// /// The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method /// (expanding tabs, justifying characters, breaking lines, and so forth). /// /// A handle to the device context. /// /// A pointer to the string that specifies the text to be drawn. If the nCount parameter is -1, the string must be null-terminated. /// If uFormat includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer /// containing the string should be large enough to accommodate these extra characters. /// /// /// The length, in characters, of the string. If nCount is -1, then the lpchText parameter is assumed to be a pointer to a /// null-terminated string and DrawText computes the character count automatically. /// /// /// A pointer to a RECT structure that contains the rectangle (in logical coordinates) in which the text is to be formatted. /// /// The method of formatting the text. /// /// If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, /// the return value is the offset from lpRect->top to the bottom of the drawn text. If the function fails, the return value is zero. /// [PInvokeData("WinUser.h", MSDNShortId = "dd162498")] [DllImport(Lib.User32, CharSet = CharSet.Auto, SetLastError = true)] public static extern int DrawText(HDC hDC, string lpchText, int nCount, in RECT lpRect, DrawTextFlags uFormat); /// /// The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method /// (expanding tabs, justifying characters, breaking lines, and so forth). /// /// A handle to the device context. /// /// A pointer to the string that specifies the text to be drawn. If the nCount parameter is -1, the string must be null-terminated. /// If uFormat includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer /// containing the string should be large enough to accommodate these extra characters. /// /// /// The length, in characters, of the string. If nCount is -1, then the lpchText parameter is assumed to be a pointer to a /// null-terminated string and DrawText computes the character count automatically. /// /// /// A pointer to a RECT structure that contains the rectangle (in logical coordinates) in which the text is to be formatted. /// /// The method of formatting the text. /// /// If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, /// the return value is the offset from lpRect->top to the bottom of the drawn text. If the function fails, the return value is zero. /// [PInvokeData("WinUser.h", MSDNShortId = "dd162498")] [DllImport(Lib.User32, CharSet = CharSet.Auto, SetLastError = true)] public static extern int DrawText(HDC hDC, StringBuilder lpchText, int nCount, in RECT lpRect, DrawTextFlags uFormat); /// The DrawTextEx function draws formatted text in the specified rectangle. /// A handle to the device context in which to draw. /// /// A pointer to the string that contains the text to draw. If the cchText parameter is -1, the string must be null-terminated. /// /// If dwDTFormat includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer /// containing the string should be large enough to accommodate these extra characters. /// /// /// /// The length of the string pointed to by lpchText. If cchText is -1, then the lpchText parameter is assumed to be a pointer to a /// null-terminated string and DrawTextEx computes the character count automatically. /// /// /// A pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. /// /// /// The formatting options. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// DT_BOTTOM /// Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value. /// /// /// DT_CALCRECT /// /// Determines the width and height of the rectangle. If there are multiple lines of text, DrawTextEx uses the width of the rectangle /// pointed to by the lprc parameter and extends the base of the rectangle to bound the last line of text. If there is only one line /// of text, DrawTextEx modifies the right side of the rectangle so that it bounds the last character in the line. In either case, /// DrawTextEx returns the height of the formatted text, but does not draw the text. /// /// /// /// DT_CENTER /// Centers text horizontally in the rectangle. /// /// /// DT_EDITCONTROL /// /// Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is /// calculated in the same manner as for an edit control, and the function does not display a partially visible last line. /// /// /// /// DT_END_ELLIPSIS /// /// For displayed text, replaces the end of a string with ellipses so that the result fits in the specified rectangle. Any word (not /// at the end of the string) that goes beyond the limits of the rectangle is truncated without ellipses. The string is not modified /// unless the DT_MODIFYSTRING flag is specified. Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS. /// /// /// /// DT_EXPANDTABS /// Expands tab characters. The default number of characters per tab is eight. /// /// /// DT_EXTERNALLEADING /// /// Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text. /// /// /// /// DT_HIDEPREFIX /// /// Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other /// mnemonic-prefix characters are still processed. Example: input string: "A&bc&&d" normal: "Ac&d" DT_HIDEPREFIX: /// "Abc&d" Compare with DT_NOPREFIX and DT_PREFIXONLY. /// /// /// /// DT_INTERNAL /// Uses the system font to calculate text metrics. /// /// /// DT_LEFT /// Aligns text to the left. /// /// /// DT_MODIFYSTRING /// /// Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified. /// /// /// /// DT_NOCLIP /// Draws without clipping. DrawTextEx is somewhat faster when DT_NOCLIP is used. /// /// /// DT_NOFULLWIDTHCHARBREAK /// /// Prevents a line break at a DBCS (double-wide character string), so that the line-breaking rule is equivalent to SBCS strings. For /// example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified. /// /// /// /// DT_NOPREFIX /// /// Turns off processing of prefix characters. Normally, DrawTextEx interprets the ampersand (&) mnemonic-prefix character as a /// directive to underscore the character that follows, and the double-ampersand (&&) mnemonic-prefix characters as a /// directive to print a single ampersand. By specifying DT_NOPREFIX, this processing is turned off. Compare with DT_HIDEPREFIX and DT_PREFIXONLY /// /// /// /// DT_PATH_ELLIPSIS /// /// For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified /// rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the /// last backslash. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS. /// /// /// /// DT_PREFIXONLY /// /// Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any /// character in the string. Example: input string: "A&bc&&d" normal: "Ac&d" PREFIXONLY: " _ " Compare with /// DT_NOPREFIX and DT_HIDEPREFIX. /// /// /// /// DT_RIGHT /// Aligns text to the right. /// /// /// DT_RTLREADING /// /// Layout in right-to-left reading order for bidirectional text when the font selected into the hdc is a Hebrew or Arabic font. The /// default reading order for all text is left-to-right. /// /// /// /// DT_SINGLELINE /// Displays text on a single line only. Carriage returns and line feeds do not break the line. /// /// /// DT_TABSTOP /// /// Sets tab stops. The DRAWTEXTPARAMS structure pointed to by the lpDTParams parameter specifies the number of average character /// widths per tab stop. /// /// /// /// DT_TOP /// Justifies the text to the top of the rectangle. /// /// /// DT_VCENTER /// Centers text vertically. This value is used only with the DT_SINGLELINE value. /// /// /// DT_WORDBREAK /// /// Breaks words. Lines are automatically broken between words if a word extends past the edge of the rectangle specified by the lprc /// parameter. A carriage return-line feed sequence also breaks the line. /// /// /// /// DT_WORD_ELLIPSIS /// Truncates any word that does not fit in the rectangle and adds ellipses. Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS. /// /// /// /// /// A pointer to a DRAWTEXTPARAMS structure that specifies additional formatting options. This parameter can be NULL. /// /// /// /// If the function succeeds, the return value is the text height in logical units. If DT_VCENTER or DT_BOTTOM is specified, the /// return value is the offset from to the bottom of the drawn text /// /// If the function fails, the return value is zero. /// /// /// The DrawTextEx function supports only fonts whose escapement and orientation are both zero. /// The text alignment mode for the device context must include the TA_LEFT, TA_TOP, and TA_NOUPDATECP flags. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-drawtextexa int DrawTextExA( HDC hdc, LPSTR lpchText, int // cchText, LPRECT lprc, UINT format, LPDRAWTEXTPARAMS lpdtp ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "77b9973b-77f1-4508-a021-52d61d576c23")] public static extern int DrawTextEx(HDC hdc, string lpchText, int cchText, in RECT lprc, DrawTextFlags format, [Optional] DRAWTEXTPARAMS lpdtp); /// The DrawTextEx function draws formatted text in the specified rectangle. /// A handle to the device context in which to draw. /// /// A pointer to the string that contains the text to draw. If the cchText parameter is -1, the string must be null-terminated. /// /// If dwDTFormat includes DT_MODIFYSTRING, the function could add up to four additional characters to this string. The buffer /// containing the string should be large enough to accommodate these extra characters. /// /// /// /// The length of the string pointed to by lpchText. If cchText is -1, then the lpchText parameter is assumed to be a pointer to a /// null-terminated string and DrawTextEx computes the character count automatically. /// /// /// A pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. /// /// /// The formatting options. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// DT_BOTTOM /// Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value. /// /// /// DT_CALCRECT /// /// Determines the width and height of the rectangle. If there are multiple lines of text, DrawTextEx uses the width of the rectangle /// pointed to by the lprc parameter and extends the base of the rectangle to bound the last line of text. If there is only one line /// of text, DrawTextEx modifies the right side of the rectangle so that it bounds the last character in the line. In either case, /// DrawTextEx returns the height of the formatted text, but does not draw the text. /// /// /// /// DT_CENTER /// Centers text horizontally in the rectangle. /// /// /// DT_EDITCONTROL /// /// Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is /// calculated in the same manner as for an edit control, and the function does not display a partially visible last line. /// /// /// /// DT_END_ELLIPSIS /// /// For displayed text, replaces the end of a string with ellipses so that the result fits in the specified rectangle. Any word (not /// at the end of the string) that goes beyond the limits of the rectangle is truncated without ellipses. The string is not modified /// unless the DT_MODIFYSTRING flag is specified. Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS. /// /// /// /// DT_EXPANDTABS /// Expands tab characters. The default number of characters per tab is eight. /// /// /// DT_EXTERNALLEADING /// /// Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text. /// /// /// /// DT_HIDEPREFIX /// /// Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other /// mnemonic-prefix characters are still processed. Example: input string: "A&bc&&d" normal: "Ac&d" DT_HIDEPREFIX: /// "Abc&d" Compare with DT_NOPREFIX and DT_PREFIXONLY. /// /// /// /// DT_INTERNAL /// Uses the system font to calculate text metrics. /// /// /// DT_LEFT /// Aligns text to the left. /// /// /// DT_MODIFYSTRING /// /// Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified. /// /// /// /// DT_NOCLIP /// Draws without clipping. DrawTextEx is somewhat faster when DT_NOCLIP is used. /// /// /// DT_NOFULLWIDTHCHARBREAK /// /// Prevents a line break at a DBCS (double-wide character string), so that the line-breaking rule is equivalent to SBCS strings. For /// example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified. /// /// /// /// DT_NOPREFIX /// /// Turns off processing of prefix characters. Normally, DrawTextEx interprets the ampersand (&) mnemonic-prefix character as a /// directive to underscore the character that follows, and the double-ampersand (&&) mnemonic-prefix characters as a /// directive to print a single ampersand. By specifying DT_NOPREFIX, this processing is turned off. Compare with DT_HIDEPREFIX and DT_PREFIXONLY /// /// /// /// DT_PATH_ELLIPSIS /// /// For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified /// rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the /// last backslash. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS. /// /// /// /// DT_PREFIXONLY /// /// Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any /// character in the string. Example: input string: "A&bc&&d" normal: "Ac&d" PREFIXONLY: " _ " Compare with /// DT_NOPREFIX and DT_HIDEPREFIX. /// /// /// /// DT_RIGHT /// Aligns text to the right. /// /// /// DT_RTLREADING /// /// Layout in right-to-left reading order for bidirectional text when the font selected into the hdc is a Hebrew or Arabic font. The /// default reading order for all text is left-to-right. /// /// /// /// DT_SINGLELINE /// Displays text on a single line only. Carriage returns and line feeds do not break the line. /// /// /// DT_TABSTOP /// /// Sets tab stops. The DRAWTEXTPARAMS structure pointed to by the lpDTParams parameter specifies the number of average character /// widths per tab stop. /// /// /// /// DT_TOP /// Justifies the text to the top of the rectangle. /// /// /// DT_VCENTER /// Centers text vertically. This value is used only with the DT_SINGLELINE value. /// /// /// DT_WORDBREAK /// /// Breaks words. Lines are automatically broken between words if a word extends past the edge of the rectangle specified by the lprc /// parameter. A carriage return-line feed sequence also breaks the line. /// /// /// /// DT_WORD_ELLIPSIS /// Truncates any word that does not fit in the rectangle and adds ellipses. Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS. /// /// /// /// /// A pointer to a DRAWTEXTPARAMS structure that specifies additional formatting options. This parameter can be NULL. /// /// /// /// If the function succeeds, the return value is the text height in logical units. If DT_VCENTER or DT_BOTTOM is specified, the /// return value is the offset from to the bottom of the drawn text /// /// If the function fails, the return value is zero. /// /// /// The DrawTextEx function supports only fonts whose escapement and orientation are both zero. /// The text alignment mode for the device context must include the TA_LEFT, TA_TOP, and TA_NOUPDATECP flags. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-drawtextexa int DrawTextExA( HDC hdc, LPSTR lpchText, int // cchText, LPRECT lprc, UINT format, LPDRAWTEXTPARAMS lpdtp ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "77b9973b-77f1-4508-a021-52d61d576c23")] public static extern int DrawTextEx(HDC hdc, StringBuilder lpchText, int cchText, in RECT lprc, DrawTextFlags format, [Optional] DRAWTEXTPARAMS lpdtp); /// /// The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire /// screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data /// structure, whose values are used internally by GDI. /// /// /// A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen. /// /// /// If the function succeeds, the return value is a handle to the DC for the specified window's client area. If the function fails, /// the return value is NULL. /// // https://msdn.microsoft.com/en-us/library/windows/desktop/dd144871(v=vs.85).aspx [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winuser.h", MSDNShortId = "dd144871")] public static extern SafeHDC GetDC([In, Optional] HWND ptr); /// /// /// The GetDCEx function retrieves a handle to a device context (DC) for the client area of a specified window or for the /// entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque /// data structure, whose values are used internally by GDI. /// /// /// This function is an extension to the GetDC function, which gives an application more control over how and whether clipping occurs /// in the client area. /// /// /// /// A handle to the window whose DC is to be retrieved. If this value is NULL, GetDCEx retrieves the DC for the entire screen. /// /// /// A clipping region that may be combined with the visible region of the DC. If the value of flags is DCX_INTERSECTRGN or /// DCX_EXCLUDERGN, then the operating system assumes ownership of the region and will automatically delete it when it is no longer /// needed. In this case, the application should not use or delete the region after a successful call to GetDCEx. /// /// /// Specifies how the DC is created. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// DCX_WINDOW /// Returns a DC that corresponds to the window rectangle rather than the client rectangle. /// /// /// DCX_CACHE /// Returns a DC from the cache, rather than the OWNDC or CLASSDC window. Essentially overrides CS_OWNDC and CS_CLASSDC. /// /// /// DCX_PARENTCLIP /// /// Uses the visible region of the parent window. The parent's WS_CLIPCHILDREN and CS_PARENTDC style bits are ignored. The origin is /// set to the upper-left corner of the window identified by hWnd. /// /// /// /// DCX_CLIPSIBLINGS /// Excludes the visible regions of all sibling windows above the window identified by hWnd. /// /// /// DCX_CLIPCHILDREN /// Excludes the visible regions of all child windows below the window identified by hWnd. /// /// /// DCX_NORESETATTRS /// This flag is ignored. /// /// /// DCX_LOCKWINDOWUPDATE /// /// Allows drawing even if there is a LockWindowUpdate call in effect that would otherwise exclude this window. Used for drawing /// during tracking. /// /// /// /// DCX_EXCLUDERGN /// The clipping region identified by hrgnClip is excluded from the visible region of the returned DC. /// /// /// DCX_INTERSECTRGN /// The clipping region identified by hrgnClip is intersected with the visible region of the returned DC. /// /// /// DCX_INTERSECTUPDATE /// Reserved; do not use. /// /// /// DCX_VALIDATE /// Reserved; do not use. /// /// /// /// /// If the function succeeds, the return value is the handle to the DC for the specified window. /// /// If the function fails, the return value is NULL. An invalid value for the hWnd parameter will cause the function to fail. /// /// /// /// /// Unless the display DC belongs to a window class, the ReleaseDC function must be called to release the DC after painting. Also, /// ReleaseDC must be called from the same thread that called GetDCEx. The number of DCs is limited only by available memory. /// /// /// The function returns a handle to a DC that belongs to the window's class if CS_CLASSDC, CS_OWNDC or CS_PARENTDC was specified as /// a style in the WNDCLASS structure when the class was registered. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdcex HDC GetDCEx( HWND hWnd, HRGN hrgnClip, DWORD flags ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "590cf928-0ad6-43f8-97e9-1dafbcfa9f49")] public static extern HDC GetDCEx([In, Optional] HWND hWnd, [In, Optional] HRGN hrgnClip, DCX flags); /// Retrieves the count of handles to graphical user interface (GUI) objects in use by the specified process. /// /// A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION access right. For more information, see /// Process Security and Access Rights. /// /// /// The GUI object type. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// GR_GDIOBJECTS 0 /// Return the count of GDI objects. /// /// /// GR_GDIOBJECTS_PEAK 2 /// /// Return the peak count of GDI objects. Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not /// supported until Windows 7 and Windows Server 2008 R2. /// /// /// /// GR_USEROBJECTS 1 /// Return the count of USER objects. /// /// /// GR_USEROBJECTS_PEAK 4 /// /// Return the peak count of USER objects. Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not /// supported until Windows 7 and Windows Server 2008 R2. /// /// /// /// /// /// /// If the function succeeds, the return value is the count of handles to GUI objects in use by the process. If no GUI objects are in /// use, the return value is zero. /// /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// A process without a graphical user interface does not use GUI resources, therefore, GetGuiResources will return zero. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getguiresources DWORD GetGuiResources( HANDLE hProcess, // DWORD uiFlags ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "55fbb7e8-79b4-4011-b522-25ea5a928b86")] public static extern uint GetGuiResources(HPROCESS hProcess, GR uiFlags); /// /// Retrieves the current color of the specified display element. Display elements are the parts of a window and the display that /// appear on the system display screen. /// /// The display element whose color is to be retrieved. /// /// The function returns the red, green, blue (RGB) color value of the given element. /// /// If the nIndex parameter is out of range, the return value is zero.Because zero is also a valid RGB value, you cannot use /// GetSysColor to determine whether a system color is supported by the current platform.Instead, use the GetSysColorBrush function, /// which returns NULL if the color is not supported. /// /// [PInvokeData("WinUser.h", MSDNShortId = "ms724371")] [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] public static extern COLORREF GetSysColor(SystemColorIndex nIndex); /// /// The GetSysColorBrush function retrieves a handle identifying a logical brush that corresponds to the specified color index. /// /// /// A color index. This value corresponds to the color used to paint one of the window elements. See GetSysColor for system color /// index values. /// /// /// he return value identifies a logical brush if the nIndex parameter is supported by the current platform. Otherwise, it returns NULL. /// [PInvokeData("WinUser.h", MSDNShortId = "dd144927")] [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] public static extern HBRUSH GetSysColorBrush(SystemColorIndex nIndex); /// /// The GetTabbedTextExtent function computes the width and height of a character string. If the string contains one or more /// tab characters, the width of the string is based upon the specified tab stops. The GetTabbedTextExtent function uses the /// currently selected font to compute the dimensions of the string. /// /// A handle to the device context. /// A pointer to a character string. /// /// The length of the text string. For the ANSI function it is a BYTE count and for the Unicode function it is a WORD count. Note /// that for the ANSI function, characters in SBCS code pages take one byte each, while most characters in DBCS code pages take two /// bytes; for the Unicode function, most currently defined Unicode characters (those in the Basic Multilingual Plane (BMP)) are one /// WORD while Unicode surrogates are two WORDs. /// /// The number of tab-stop positions in the array pointed to by the lpnTabStopPositions parameter. /// /// A pointer to an array containing the tab-stop positions, in device units. The tab stops must be sorted in increasing order; the /// smallest x-value should be the first item in the array. /// /// /// /// If the function succeeds, the return value is the dimensions of the string in logical units. The height is in the high-order word /// and the width is in the low-order word. /// /// /// If the function fails, the return value is 0. GetTabbedTextExtent will fail if hDC is invalid and if nTabPositions is less /// than 0. /// /// /// /// The current clipping region does not affect the width and height returned by the GetTabbedTextExtent function. /// /// Because some devices do not place characters in regular cell arrays (that is, they kern the characters), the sum of the extents /// of the characters in a string may not be equal to the extent of the string. /// /// /// If the nTabPositions parameter is zero and the lpnTabStopPositions parameter is NULL, tabs are expanded to eight times the /// average character width. /// /// /// If nTabPositions is 1, the tab stops are separated by the distance specified by the first value in the array to which /// lpnTabStopPositions points. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-gettabbedtextextenta DWORD GetTabbedTextExtentA( HDC hdc, // LPCSTR lpString, int chCount, int nTabPositions, const INT *lpnTabStopPositions ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "3444bb8d-4a30-47d4-b211-01f7cba39975")] public static extern uint GetTabbedTextExtent(HDC hdc, string lpString, int chCount, int nTabPositions, [In] int[] lpnTabStopPositions); /// /// The GetTabbedTextExtent function computes the width and height of a character string. If the string contains one or more /// tab characters, the width of the string is based upon the specified tab stops. The GetTabbedTextExtent function uses the /// currently selected font to compute the dimensions of the string. /// /// A handle to the device context. /// A pointer to a character string. /// /// A pointer to an array containing the tab-stop positions, in device units. The tab stops must be sorted in increasing order; the /// smallest x-value should be the first item in the array. /// /// /// If the function succeeds, the return value is the dimensions of the string in logical units. /// /// If the function fails, the return value is Size.Empty. GetTabbedTextExtent will fail if hDC is invalid and if /// nTabPositions is less than 0. /// /// /// /// The current clipping region does not affect the width and height returned by the GetTabbedTextExtent function. /// /// Because some devices do not place characters in regular cell arrays (that is, they kern the characters), the sum of the extents /// of the characters in a string may not be equal to the extent of the string. /// /// /// If the nTabPositions parameter is zero and the lpnTabStopPositions parameter is NULL, tabs are expanded to eight times the /// average character width. /// /// /// If nTabPositions is 1, the tab stops are separated by the distance specified by the first value in the array to which /// lpnTabStopPositions points. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-gettabbedtextextenta DWORD GetTabbedTextExtentA( HDC hdc, // LPCSTR lpString, int chCount, int nTabPositions, const INT *lpnTabStopPositions ); [PInvokeData("winuser.h", MSDNShortId = "3444bb8d-4a30-47d4-b211-01f7cba39975")] public static SIZE GetTabbedTextExtent(HDC hdc, string lpString, int[] lpnTabStopPositions) { var ret = GetTabbedTextExtent(hdc, lpString, lpString?.Length ?? 0, lpnTabStopPositions?.Length ?? 0, lpnTabStopPositions); return new SIZE(Macros.LOWORD(ret), Macros.HIWORD(ret)); } /// The GetUserObjectSecurity function retrieves security information for the specified user object. /// A handle to the user object for which to return security information. /// A pointer to a SECURITY_INFORMATION value that specifies the security information being requested. /// /// A pointer to a SECURITY_DESCRIPTOR structure in self-relative format that contains the requested information when the function /// returns. This buffer must be aligned on a 4-byte boundary. /// /// The length, in bytes, of the buffer pointed to by the pSD parameter. /// /// A pointer to a variable to receive the number of bytes required to store the complete security descriptor. If this variable's /// value is greater than the value of the nLength parameter when the function returns, the function returns FALSE and none of /// the security descriptor is copied to the buffer. Otherwise, the entire security descriptor is copied. /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. To get extended error information, call GetLastError. /// /// /// /// To read the owner, group, or discretionary access control list (DACL) from the user object's security descriptor, the calling /// process must have been granted READ_CONTROL access when the handle was opened. /// /// /// To read the system access control list (SACL) from the security descriptor, the calling process must have been granted /// ACCESS_SYSTEM_SECURITY access when the handle was opened. The correct way to get this access is to enable the SE_SECURITY_NAME /// privilege in the caller's current token, open the handle for ACCESS_SYSTEM_SECURITY access, and then disable the privilege. /// /// Examples /// For an example that uses this function, see Starting an Interactive Client Process. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getuserobjectsecurity BOOL GetUserObjectSecurity( HANDLE // hObj, PSECURITY_INFORMATION pSIRequested, PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "998c2520-7833-4efd-a794-b13b528f0485")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetUserObjectSecurity(HANDLE hObj, in SECURITY_INFORMATION pSIRequested, PSECURITY_DESCRIPTOR pSID, uint nLength, out uint lpnLengthNeeded); /// /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra /// window memory. /// /// A handle to the window and, indirectly, the class to which the window belongs. /// /// The zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra /// window memory, minus four; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the /// third 32-bit integer. To retrieve any other value, specify one of the following values. /// /// /// If the function succeeds, the return value is the requested value. If the function fails, the return value is zero.To get /// extended error information, call GetLastError. /// [DllImport(Lib.User32, CharSet = CharSet.Auto, SetLastError = true)] [SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "return", Justification = "This declaration is not used on 64-bit Windows.")] [SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "2", Justification = "This declaration is not used on 64-bit Windows.")] [System.Security.SecurityCritical] public static extern int GetWindowLong(HWND hWnd, WindowLongFlags nIndex); /// /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra /// window memory. /// /// A handle to the window and, indirectly, the class to which the window belongs. /// /// The zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra /// window memory, minus the size of an integer. To retrieve any other value, specify one of the following values. /// /// /// If the function succeeds, the return value is the requested value. If the function fails, the return value is zero.To get /// extended error information, call GetLastError. /// public static IntPtr GetWindowLongAuto(HWND hWnd, WindowLongFlags nIndex) { IntPtr ret; if (IntPtr.Size == 4) ret = (IntPtr)GetWindowLong(hWnd, nIndex); else ret = GetWindowLongPtr(hWnd, nIndex); if (ret == IntPtr.Zero) throw new System.ComponentModel.Win32Exception(); return ret; } /// /// Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra /// window memory. /// /// A handle to the window and, indirectly, the class to which the window belongs. /// /// The zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra /// window memory, minus the size of an integer. To retrieve any other value, specify one of the following values. /// /// /// If the function succeeds, the return value is the requested value. If the function fails, the return value is zero.To get /// extended error information, call GetLastError. /// [DllImport(Lib.User32, CharSet = CharSet.Auto, SetLastError = true)] [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist", Justification = "Entry point does exist on 64-bit Windows.")] [System.Security.SecurityCritical] public static extern IntPtr GetWindowLongPtr(HWND hWnd, WindowLongFlags nIndex); /// /// /// [ LoadBitmap is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions. Instead, use LoadImage and DrawFrameControl.] /// /// The LoadBitmap function loads the specified bitmap resource from a module's executable file. /// /// A handle to the instance of the module whose executable file contains the bitmap to be loaded. /// /// A pointer to a null-terminated string that contains the name of the bitmap resource to be loaded. Alternatively, this parameter /// can consist of the resource identifier in the low-order word and zero in the high-order word. The MAKEINTRESOURCE macro can be /// used to create this value. /// /// /// If the function succeeds, the return value is the handle to the specified bitmap. /// If the function fails, the return value is NULL. /// /// /// /// If the bitmap pointed to by the lpBitmapName parameter does not exist or there is insufficient memory to load the bitmap, the /// function fails. /// /// /// LoadBitmap creates a compatible bitmap of the display, which cannot be selected to a printer. To load a bitmap that you /// can select to a printer, call LoadImage and specify LR_CREATEDIBSECTION to create a DIB section. A DIB section can be selected to /// any device. /// /// /// An application can use the LoadBitmap function to access predefined bitmaps. To do so, the application must set the /// hInstance parameter to NULL and the lpBitmapName parameter to one of the following values. /// /// /// /// Bitmap name /// Bitmap name /// /// /// OBM_BTNCORNERS /// OBM_OLD_RESTORE /// /// /// OBM_BTSIZE /// OBM_OLD_RGARROW /// /// /// OBM_CHECK /// OBM_OLD_UPARROW /// /// /// OBM_CHECKBOXES /// OBM_OLD_ZOOM /// /// /// OBM_CLOSE /// OBM_REDUCE /// /// /// OBM_COMBO /// OBM_REDUCED /// /// /// OBM_DNARROW /// OBM_RESTORE /// /// /// OBM_DNARROWD /// OBM_RESTORED /// /// /// OBM_DNARROWI /// OBM_RGARROW /// /// /// OBM_LFARROW /// OBM_RGARROWD /// /// /// OBM_LFARROWD /// OBM_RGARROWI /// /// /// OBM_LFARROWI /// OBM_SIZE /// /// /// OBM_MNARROW /// OBM_UPARROW /// /// /// OBM_OLD_CLOSE /// OBM_UPARROWD /// /// /// OBM_OLD_DNARROW /// OBM_UPARROWI /// /// /// OBM_OLD_LFARROW /// OBM_ZOOM /// /// /// OBM_OLD_REDUCE /// OBM_ZOOMD /// /// /// Bitmap names that begin with OBM_OLD represent bitmaps used by 16-bit versions of Windows earlier than 3.0. /// /// For an application to use any of the OBM_ constants, the constant OEMRESOURCE must be defined before the Windows.h header file is included. /// /// The application must call the DeleteObject function to delete each bitmap handle returned by the LoadBitmap function. /// Examples /// For an example, see Example of Menu-Item Bitmaps in Using Menus. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-loadbitmapa HBITMAP LoadBitmapA( HINSTANCE hInstance, // LPCSTR lpBitmapName ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "5eed5f78-deaf-4b23-986e-4802dc05936c")] public static extern SafeHBITMAP LoadBitmap(HINSTANCE hInstance, [In] SafeResourceId lpBitmapName); /// /// The ReleaseDC function releases a device context (DC), freeing it for use by other applications. The effect of the /// ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs. /// /// A handle to the window whose DC is to be released. /// A handle to the DC to be released. /// /// The return value indicates whether the DC was released. If the DC was released, the return value is 1. /// If the DC was not released, the return value is zero. /// /// /// /// The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC /// function that retrieves a common DC. /// /// /// An application cannot use the ReleaseDC function to release a DC that was created by calling the CreateDC function; /// instead, it must use the DeleteDC function. ReleaseDC must be called from the same thread that called GetDC. /// /// Examples /// For an example, see Scaling an Image. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-releasedc int ReleaseDC( HWND hWnd, HDC hDC ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "c4f48f1e-4a37-4330-908e-2ac5c65e1a1d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ReleaseDC(HWND hWnd, HDC hDC); /// /// /// Sets the colors for the specified display elements. Display elements are the various parts of a window and the display that /// appear on the system display screen. /// /// /// /// Type: int /// The number of display elements in the lpaElements array. /// /// /// Type: const INT* /// An array of integers that specify the display elements to be changed. For a list of display elements, see GetSysColor. /// /// /// Type: const COLORREF* /// /// An array of COLORREF values that contain the new red, green, blue (RGB) color values for the display elements in the array /// pointed to by the lpaElements parameter. /// /// To generate a COLORREF, use the RGB macro. /// /// /// Type: Type: BOOL /// If the function succeeds, the return value is a nonzero value. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The SetSysColors function sends a WM_SYSCOLORCHANGE message to all windows to inform them of the change in color. It also /// directs the system to repaint the affected portions of all currently visible windows. /// /// /// It is best to respect the color settings specified by the user. If you are writing an application to enable the user to change /// the colors, then it is appropriate to use this function. However, this function affects only the current session. The new colors /// are not saved when the system terminates. /// /// Examples /// /// The following example demonstrates the use of the GetSysColor and SetSysColors functions. First, the example uses /// GetSysColor to retrieve the colors of the window background and active caption and displays the red, green, blue (RGB) /// values in hexadecimal notation. Next, example uses SetSysColors to change the color of the window background to light gray /// and the active title bars to dark purple. After a 10-second delay, the example restores the previous colors for these elements /// using SetSysColors. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setsyscolors BOOL SetSysColors( int cElements, CONST INT // *lpaElements, CONST COLORREF *lpaRgbValues ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "41a7a96c-f9d1-44e3-a7e1-fd7d155c4ed0")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetSysColors(int cElements, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U4, SizeConst = 0)] SystemColorIndex[] lpaElements, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 0)] COLORREF[] lpaRgbValues); /// /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory. /// /// /// A handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process /// that owns the window specified by the hWnd parameter is at a higher process privilege in the UIPI hierarchy than the process the /// calling thread resides in. /// /// /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window /// memory, minus the size of an integer. Alternately, this can be a value from . /// /// The replacement value. /// /// If the function succeeds, the return value is the previous value of the specified offset. If the function fails, the return value /// is zero. To get extended error information, call GetLastError. /// /// If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error /// information. To determine success or failure, clear the last error information by calling SetLastError with 0, then call /// SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero. /// /// public static IntPtr SetWindowLong(HWND hWnd, WindowLongFlags nIndex, IntPtr dwNewLong) { IntPtr ret; if (IntPtr.Size == 4) ret = (IntPtr)SetWindowLongPtr32(hWnd, nIndex, dwNewLong); else ret = SetWindowLongPtr64(hWnd, nIndex, dwNewLong); if (ret == IntPtr.Zero) throw new System.ComponentModel.Win32Exception(); return ret; } /// /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory. /// /// /// A handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process /// that owns the window specified by the hWnd parameter is at a higher process privilege in the UIPI hierarchy than the process the /// calling thread resides in. /// /// /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window /// memory, minus the size of an integer. Alternately, this can be a value from . /// /// The replacement value. /// /// If the function succeeds, the return value is the previous value of the specified offset. If the function fails, the return value /// is zero. To get extended error information, call GetLastError. /// /// If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error /// information. To determine success or failure, clear the last error information by calling SetLastError with 0, then call /// SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero. /// /// public static int SetWindowLong(HWND hWnd, WindowLongFlags nIndex, int dwNewLong) { IntPtr ret; if (IntPtr.Size == 4) ret = (IntPtr)SetWindowLongPtr32(hWnd, nIndex, (IntPtr)dwNewLong); else ret = SetWindowLongPtr64(hWnd, nIndex, (IntPtr)dwNewLong); if (ret == IntPtr.Zero) throw new System.ComponentModel.Win32Exception(); return ret.ToInt32(); } /// /// The TabbedTextOut function writes a character string at a specified location, expanding tabs to the values specified in an /// array of tab-stop positions. Text is written in the currently selected font, background color, and text color. /// /// A handle to the device context. /// The x-coordinate of the starting point of the string, in logical units. /// The y-coordinate of the starting point of the string, in logical units. /// /// A pointer to the character string to draw. The string does not need to be zero-terminated, since nCount specifies the length of /// the string. /// /// The length of the string pointed to by lpString. /// The number of values in the array of tab-stop positions. /// /// A pointer to an array containing the tab-stop positions, in logical units. The tab stops must be sorted in increasing order; the /// smallest x-value should be the first item in the array. /// /// The x-coordinate of the starting position from which tabs are expanded, in logical units. /// /// /// If the function succeeds, the return value is the dimensions, in logical units, of the string. The height is in the high-order /// word and the width is in the low-order word. /// /// If the function fails, the return value is zero. /// /// /// /// If the nTabPositions parameter is zero and the lpnTabStopPositions parameter is NULL, tabs are expanded to eight times the /// average character width. /// /// /// If nTabPositions is 1, the tab stops are separated by the distance specified by the first value in the lpnTabStopPositions array. /// /// /// If the lpnTabStopPositions array contains more than one value, a tab stop is set for each value in the array, up to the number /// specified by nTabPositions. /// /// /// The nTabOrigin parameter allows an application to call the TabbedTextOut function several times for a single line. If the /// application calls TabbedTextOut more than once with the nTabOrigin set to the same value each time, the function expands /// all tabs relative to the position specified by nTabOrigin. /// /// /// By default, the current position is not used or updated by the TabbedTextOut function. If an application needs to update /// the current position when it calls TabbedTextOut, the application can call the SetTextAlign function with the wFlags /// parameter set to TA_UPDATECP. When this flag is set, the system ignores the X and Y parameters on subsequent calls to the /// TabbedTextOut function, using the current position instead. /// /// Note For Windows Vista and later, TabbedTextOut ignores text alignment when it draws text. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-tabbedtextouta LONG TabbedTextOutA( HDC hdc, int x, int y, // LPCSTR lpString, int chCount, int nTabPositions, const INT *lpnTabStopPositions, int nTabOrigin ); [DllImport(Lib.User32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winuser.h", MSDNShortId = "1cb78a75-752d-4e06-afdf-cd797f209114")] public static extern int TabbedTextOut(HDC hdc, int x, int y, string lpString, int chCount, [Optional] int nTabPositions, [In, Optional] int[] lpnTabStopPositions, int nTabOrigin); /// /// The WindowFromDC function returns a handle to the window associated with the specified display device context (DC). Output /// functions that use the specified device context draw into this window. /// /// Handle to the device context from which a handle to the associated window is to be retrieved. /// /// The return value is a handle to the window associated with the specified DC. If no window is associated with the specified DC, /// the return value is NULL. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-windowfromdc HWND WindowFromDC( HDC hDC ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "57ecec82-03be-4d1a-84cf-6b64131af19d")] public static extern HWND WindowFromDC(HDC hDC); private static SafeCoTaskMemHandle GetPtr(in T val) => SafeCoTaskMemHandle.CreateFromStructure(val); /// /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window /// and does not return until the window procedure has processed the message. /// /// The type of the value. /// The type of the value. /// The type of the value. /// /// A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST ((HWND)0xffff), the /// message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and /// pop-up windows; but the message is not sent to child windows. /// /// The message to be sent. /// Additional message-specific information. /// Additional message-specific information. /// The return value specifies the result of the message processing; it depends on the message sent. private static IntPtr SendMessageUnmanaged(HWND hWnd, TEnum msg, in TWP wParam, ref TLP lParam) where TEnum : struct, IConvertible where TWP : unmanaged where TLP : unmanaged { var m = (uint)Convert.ChangeType(msg, typeof(uint)); unsafe { fixed (void* wp = &wParam, lp = &lParam) { return (IntPtr)SendMessageUnsafe((void*)(IntPtr)hWnd, m, wp, lp); } } } /// /// The SetUserObjectSecurity function sets the security of a user object. This can be, for example, a window or a DDE conversation. /// /// A handle to a user object for which security information is set. /// /// /// A pointer to a value that indicates the components of the security descriptor to set. This parameter can be a combination of the /// following values. /// /// /// /// Value /// Meaning /// /// /// DACL_SECURITY_INFORMATION /// /// Sets the discretionary access control list (DACL) of the object. The handle specified by hObj must have WRITE_DAC access, or the /// calling process must be the owner of the object. /// /// /// /// GROUP_SECURITY_INFORMATION /// Sets the primary group security identifier (SID) of the object. /// /// /// OWNER_SECURITY_INFORMATION /// /// Sets the SID of the owner of the object. The handle specified by hObj must have WRITE_OWNER access, or the calling process must /// be the owner of the object or have the SE_TAKE_OWNERSHIP_NAME privilege enabled. /// /// /// /// SACL_SECURITY_INFORMATION /// /// Sets the system access control list (SACL) of the object. The handle specified by hObj must have ACCESS_SYSTEM_SECURITY access. /// To obtain ACCESS_SYSTEM_SECURITY access /// /// /// /// /// /// A pointer to a SECURITY_DESCRIPTOR structure that contains the new security information. /// This buffer must be aligned on a 4-byte boundary. /// /// /// If the function succeeds, the function returns nonzero. /// If the function fails, it returns zero. To get extended error information, call GetLastError. /// /// /// /// The SetUserObjectSecurity function applies changes specified in a security descriptor to the security descriptor assigned /// to a user object. The security descriptor of the object must be in self-relative form. If necessary, this function allocates /// additional memory to increase the size of the security descriptor. /// /// Examples /// For an example that uses this function, see Starting an Interactive Client Process. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setuserobjectsecurity BOOL SetUserObjectSecurity( HANDLE // hObj, PSECURITY_INFORMATION pSIRequested, PSECURITY_DESCRIPTOR pSID ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "219e41b8-9ac7-4747-a585-b6b9df6a1c9c")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetUserObjectSecurity(HANDLE hObj, in SECURITY_INFORMATION pSIRequested, PSECURITY_DESCRIPTOR pSID); /// /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory. /// /// /// A handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process /// that owns the window specified by the hWnd parameter is at a higher process privilege in the UIPI hierarchy than the process the /// calling thread resides in. /// /// /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window /// memory, minus the size of an integer. Alternately, this can be a value from . /// /// The replacement value. /// /// If the function succeeds, the return value is the previous value of the specified offset. If the function fails, the return value /// is zero. To get extended error information, call GetLastError. /// /// If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error /// information. To determine success or failure, clear the last error information by calling SetLastError with 0, then call /// SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero. /// /// [DllImport(Lib.User32, SetLastError = true, EntryPoint = "SetWindowLong")] [SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "return", Justification = "This declaration is not used on 64-bit Windows.")] [SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "2", Justification = "This declaration is not used on 64-bit Windows.")] private static extern int SetWindowLongPtr32(HWND hWnd, WindowLongFlags nIndex, IntPtr dwNewLong); /// /// Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory. /// /// /// A handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process /// that owns the window specified by the hWnd parameter is at a higher process privilege in the UIPI hierarchy than the process the /// calling thread resides in. /// /// /// The zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window /// memory, minus the size of an integer. Alternately, this can be a value from . /// /// The replacement value. /// /// If the function succeeds, the return value is the previous value of the specified offset. If the function fails, the return value /// is zero. To get extended error information, call GetLastError. /// /// If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error /// information. To determine success or failure, clear the last error information by calling SetLastError with 0, then call /// SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero. /// /// [DllImport(Lib.User32, SetLastError = true, EntryPoint = "SetWindowLongPtr")] [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist", Justification = "Entry point does exist on 64-bit Windows.")] private static extern IntPtr SetWindowLongPtr64(HWND hWnd, WindowLongFlags nIndex, IntPtr dwNewLong); /// /// Grants or denies access to a handle to a User object to a job that has a user-interface restriction. When access is granted, all /// processes associated with the job can subsequently recognize and use the handle. When access is denied, the processes can no /// longer use the handle. For more information see User Objects. /// /// A handle to the User object. /// /// A handle to the job to be granted access to the User handle. The CreateJobObject or OpenJobObject function returns this handle. /// /// /// If this parameter is TRUE, all processes associated with the job can recognize and use the handle. If the parameter is FALSE, the /// processes cannot use the handle. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The UserHandleGrantAccess function can be called only from a process not associated with the job specified by the hJob /// parameter. The User handle must not be owned by a process or thread associated with the job. /// /// /// To create user-interface restrictions, call the SetInformationJobObject function with the JobObjectBasicUIRestrictions job /// information class. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-userhandlegrantaccess BOOL UserHandleGrantAccess( HANDLE // hUserHandle, HANDLE hJob, BOOL bGrant ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "6e7a6cfc-f881-43cc-a5af-b97e0bf14bf4")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UserHandleGrantAccess(HANDLE hUserHandle, HANDLE hJob, [MarshalAs(UnmanagedType.Bool)] bool bGrant); /// Contains information about a window's maximized size and position and its minimum and maximum tracking size. [StructLayout(LayoutKind.Sequential)] public struct MINMAXINFO { /// Reserved; do not use. public POINT reserved; /// /// The maximized width (x member) and the maximized height (y member) of the window. For top-level windows, this value is based /// on the width of the primary monitor. /// public SIZE maxSize; /// /// The position of the left side of the maximized window (x member) and the position of the top of the maximized window (y /// member). For top-level windows, this value is based on the position of the primary monitor. /// public POINT maxPosition; /// /// The minimum tracking width (x member) and the minimum tracking height (y member) of the window. This value can be obtained /// programmatically from the system metrics SM_CXMINTRACK and SM_CYMINTRACK (see the GetSystemMetrics function). /// public SIZE minTrackSize; /// /// The maximum tracking width (x member) and the maximum tracking height (y member) of the window. This value is based on the /// size of the virtual screen and can be obtained programmatically from the system metrics SM_CXMAXTRACK and SM_CYMAXTRACK (see /// the GetSystemMetrics function). /// public SIZE maxTrackSize; } /// Contains information about the size and position of a window. [StructLayout(LayoutKind.Sequential)] public struct WINDOWPOS { /// A handle to the window. public HWND hwnd; /// /// The position of the window in Z order (front-to-back position). This member can be a handle to the window behind which this /// window is placed, or can be one of the special values listed with the SetWindowPos function. /// public HWND hwndInsertAfter; /// The position of the left edge of the window. public int x; /// The position of the top edge of the window. public int y; /// The window width, in pixels. public int cx; /// The window height, in pixels. public int cy; /// The window position. This member can be one or more of the following values. public SetWindowPosFlags flags; /// Creates a structure from an LPARAM value. /// The LPARAM value. /// A structure. public static WINDOWPOS FromLParam(IntPtr lParam) => (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); /// Updates the value pointed to by an LPARAM value from this instance. /// The LPARAM value to update. public void UpdateLParam(IntPtr lParam) => Marshal.StructureToPtr(this, lParam, false); } /// Special window handles public static class SpecialWindowHandles { /// /// Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its /// topmost status and is placed at the bottom of all other windows. /// public static HWND HWND_BOTTOM = new IntPtr(1); /// /// Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window /// is already a non-topmost window. /// public static HWND HWND_NOTOPMOST = new IntPtr(-2); /// Places the window at the top of the Z order. public static HWND HWND_TOP = new IntPtr(0); /// Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. public static HWND HWND_TOPMOST = new IntPtr(-1); } /// The DRAWTEXTPARAMS structure contains extended formatting options for the DrawTextEx function. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagdrawtextparams typedef struct tagDRAWTEXTPARAMS { UINT // cbSize; int iTabLength; int iLeftMargin; int iRightMargin; UINT uiLengthDrawn; } DRAWTEXTPARAMS, *LPDRAWTEXTPARAMS; [PInvokeData("winuser.h", MSDNShortId = "d3b89ce2-9a05-42af-b03e-24e1c4d6ef1d")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public class DRAWTEXTPARAMS { /// Initializes a new instance of the class. /// The size of each tab stop, in units equal to the average character width. /// The left margin, in units equal to the average character width. /// The right margin, in units equal to the average character width. public DRAWTEXTPARAMS(int tabLength = 0, int leftMargin = 0, int rightMargin = 0) { cbSize = (uint)Marshal.SizeOf(typeof(DRAWTEXTPARAMS)); iTabLength = tabLength; iLeftMargin = leftMargin; iRightMargin = rightMargin; } /// The structure size, in bytes. public uint cbSize; /// The size of each tab stop, in units equal to the average character width. public int iTabLength; /// The left margin, in units equal to the average character width. public int iLeftMargin; /// The right margin, in units equal to the average character width. public int iRightMargin; /// /// Receives the number of characters processed by DrawTextEx, including white-space characters. The number can be the length of /// the string or the index of the first line that falls below the drawing area. Note that DrawTextEx always processes the /// entire string if the DT_NOCLIP formatting flag is specified. /// public uint uiLengthDrawn; } } }