From 662c8a18c1e5420e3e266c86eed83c0d7d52b08e Mon Sep 17 00:00:00 2001 From: dahall Date: Sat, 26 Dec 2020 16:00:25 -0700 Subject: [PATCH] Added IDI_* values for static icons and overloaded LoadIcon function to accept a ResourceId param. --- PInvoke/User32/WinUser.Icon.cs | 125 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/PInvoke/User32/WinUser.Icon.cs b/PInvoke/User32/WinUser.Icon.cs index f587c77e..b36263c0 100644 --- a/PInvoke/User32/WinUser.Icon.cs +++ b/PInvoke/User32/WinUser.Icon.cs @@ -911,6 +911,96 @@ namespace Vanara.PInvoke [PInvokeData("winuser.h", MSDNShortId = "loadicon")] public static extern SafeHICON LoadIcon(HINSTANCE hInstance, string lpIconName); + /// + /// Loads the specified icon resource from the executable (.exe) file associated with an application instance. + /// Note This function has been superseded by the LoadImage function. + /// + /// + /// Type: HINSTANCE + /// + /// A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL + /// when a standard icon is being loaded. + /// + /// + /// + /// Type: LPCTSTR + /// + /// The name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order + /// word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value. + /// + /// + /// To use one of the predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the + /// following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// IDI_APPLICATION MAKEINTRESOURCE(32512) + /// Default application icon. + /// + /// + /// IDI_ASTERISK MAKEINTRESOURCE(32516) + /// Asterisk icon. Same as IDI_INFORMATION. + /// + /// + /// IDI_ERROR MAKEINTRESOURCE(32513) + /// Hand-shaped icon. + /// + /// + /// IDI_EXCLAMATION MAKEINTRESOURCE(32515) + /// Exclamation point icon. Same as IDI_WARNING. + /// + /// + /// IDI_HAND MAKEINTRESOURCE(32513) + /// Hand-shaped icon. Same as IDI_ERROR. + /// + /// + /// IDI_INFORMATION MAKEINTRESOURCE(32516) + /// Asterisk icon. + /// + /// + /// IDI_QUESTION MAKEINTRESOURCE(32514) + /// Question mark icon. + /// + /// + /// IDI_SHIELD MAKEINTRESOURCE(32518) + /// Security Shield icon. + /// + /// + /// IDI_WARNING MAKEINTRESOURCE(32515) + /// Exclamation point icon. + /// + /// + /// IDI_WINLOGO MAKEINTRESOURCE(32517) + /// Default application icon. Windows 2000: Windows logo icon. + /// + /// + /// + /// + /// Type: HICON + /// If the function succeeds, the return value is a handle to the newly loaded icon. + /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. + /// + /// + /// + /// LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing + /// resource. The function searches the icon resource for the icon most appropriate for the current display. The icon resource can be + /// a color or monochrome bitmap. + /// + /// + /// LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use + /// the LoadImage function to load icons of other sizes. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-loadicona HICON LoadIconA( HINSTANCE hInstance, LPCSTR + // lpIconName ); + [DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("winuser.h", MSDNShortId = "loadicon")] + public static extern SafeHICON LoadIcon(HINSTANCE hInstance, ResourceId lpIconName); + /// /// Searches through icon or cursor data for the icon or cursor that best fits the current display device. /// To specify a desired height or width, use the LookupIconIdFromDirectoryEx function. @@ -1238,6 +1328,41 @@ namespace Vanara.PInvoke public string szResName; } + /// Predefined icon values. + [PInvokeData("winuser.h")] + public static class IDI + { + /// Default application icon. + public static readonly ResourceId IDI_APPLICATION = Macros.MAKEINTRESOURCE(32512); + + /// Hand-shaped icon. Same as IDI_ERROR. + public static readonly ResourceId IDI_HAND = Macros.MAKEINTRESOURCE(32513); + + /// Question mark icon. + public static readonly ResourceId IDI_QUESTION = Macros.MAKEINTRESOURCE(32514); + + /// Exclamation point icon. Same as IDI_WARNING. + public static readonly ResourceId IDI_EXCLAMATION = Macros.MAKEINTRESOURCE(32515); + + /// Asterisk icon. Same as IDI_INFORMATION. + public static readonly ResourceId IDI_ASTERISK = Macros.MAKEINTRESOURCE(32516); + + /// Default application icon. Windows 2000: Windows logo icon. + public static readonly ResourceId IDI_WINLOGO = Macros.MAKEINTRESOURCE(32517); + + /// Security Shield icon. + public static readonly ResourceId IDI_SHIELD = Macros.MAKEINTRESOURCE(32518); + + /// Exclamation point icon. + public static readonly ResourceId IDI_WARNING = IDI_EXCLAMATION; + + /// Hand-shaped icon. + public static readonly ResourceId IDI_ERROR = IDI_HAND; + + /// Asterisk icon. + public static readonly ResourceId IDI_INFORMATION = IDI_ASTERISK; + } + /// Provides a to a Windows that disposes a created HICON instance at disposal using DestroyIcon. public class SafeHICON : SafeHANDLE, IUserHandle {