public unsafe bool Extract(string iconFile, int iconIndex, ushort iconSize, out HICON hicon) { fixed(HICON *picon = &hicon) return(iconSize > 16 ? Extract(iconFile, iconIndex, iconSize, 0, picon, null) : Extract(iconFile, iconIndex, 0, iconSize, null, picon)); }
public unsafe bool Extract(string iconFile, int iconIndex, ushort iconSizeLarge, ushort iconSizeSmall, out HICON hiconLarge, out HICON hiconSmall) { fixed(HICON *piconLarge = &hiconLarge) fixed(HICON * piconSmall = &hiconSmall) return(Extract(iconFile, iconIndex, iconSizeLarge, iconSizeSmall, piconLarge, piconSmall)); }
private void Refresh() { var flags = GetFlags(); if (curFlags == flags && curId == Identifier) { return; } if (hIcon != IntPtr.Zero) { DestroyIcon(hIcon); hIcon = default; } var info = SHSTOCKICONINFO.Default; var hr = SHGetStockIconInfo(curId = Identifier, curFlags = flags, ref info); // If we get an error, return null as the icon requested might not be supported on the current system if (hr == HRESULT.E_INVALIDARG) { throw new InvalidOperationException("Invalid identifier."); } else if (hr.Succeeded) { hIcon = info.hIcon; location = new IconLocation(info.szPath, info.iIcon); systemImageIndex = info.iSysImageIndex; } else { location = null; systemImageIndex = 0; } }
public static void DestroyIcon(HICON hIcon) { if (!DestroyIconInternal(hIcon)) { throw new Win32Exception(); } }
public static BitmapSource CreateBitmapSourceFromHIcon(HICON hicon, bool destroyIcon = true) { BitmapSource imageSource = Imaging.CreateBitmapSourceFromHIcon(hicon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); imageSource.Freeze(); if (destroyIcon) { DestroyIcon(hicon); } return(imageSource); }
/// <summary>Extracts an icon image from the specified location.</summary> /// <param name="exIcon">The <see cref="IExtractIconA"/> instance.</param> /// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param> /// <param name="nIconIndex">The index of the icon in the file pointed to by pszFile.</param> /// <param name="nIconSizeLarge"> /// The desired size of the large icon, in pixels. The size specified can be the width or height. The width of an icon always equals /// its height. /// </param> /// <param name="phiconLarge">A pointer to an HICON value that receives the handle to the large icon. This parameter may be NULL.</param> /// <param name="nIconSizeSmall"> /// The desired size of the small icon, in pixels. The size specified can be the width or height. The width of an icon always equals /// its height. /// </param> /// <param name="phiconSmall">A pointer to an HICON value that receives the handle to the small icon. This parameter may be NULL.</param> /// <returns>Returns S_OK if the function extracted the icon, or S_FALSE if the calling application should extract the icon.</returns> public static HRESULT Extract(this IExtractIconA exIcon, string pszFile, uint nIconIndex, ushort nIconSizeLarge, out SafeHICON phiconLarge, ushort nIconSizeSmall, out SafeHICON phiconSmall) { if (exIcon is null) { throw new ArgumentNullException(nameof(exIcon)); } var sz = Macros.MAKELONG(nIconSizeLarge, nIconSizeSmall); unsafe { HICON h1 = default, h2 = default;
/// <summary>Extracts an icon image from the specified location.</summary> /// <param name="exIcon">The <see cref="IExtractIconA"/> instance.</param> /// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param> /// <param name="nIconIndex">The index of the icon in the file pointed to by pszFile.</param> /// <param name="nIconSize"> /// The desired size of the icon, in pixels. The size specified can be the width or height. The width of an icon always equals /// its height. /// </param> /// <param name="phicon">A pointer to an HICON value that receives the handle to the icon. This parameter may be NULL.</param> /// <returns>Returns S_OK if the function extracted the icon, or S_FALSE if the calling application should extract the icon.</returns> public static HRESULT Extract(this IExtractIconA exIcon, string pszFile, uint nIconIndex, ushort nIconSize, out SafeHICON phicon) { if (exIcon is null) { throw new ArgumentNullException(nameof(exIcon)); } var sz = nIconSize > 16 ? Macros.MAKELONG(nIconSize, 0) : Macros.MAKELONG(0, nIconSize); unsafe { HICON h1 = default; var hr = nIconSize > 16 ? exIcon.Extract(pszFile, nIconIndex, &h1, null, sz) : exIcon.Extract(pszFile, nIconIndex, null, &h1, sz); phicon = h1 == default ? null : new SafeHICON((IntPtr)h1); return(hr); } }
public HRESULT Dummy(HICON h1, HDC h2) { return(((delegate * unmanaged <IDummyHICONIncluder *, HICON, HDC, int>)(lpVtbl[3]))((IDummyHICONIncluder *)Unsafe.AsPointer(ref this), h1, h2)); }
public static extern int ShellAboutW(HWND hWnd, [NativeTypeName("LPCWSTR")] ushort *szApp, [NativeTypeName("LPCWSTR")] ushort *szOtherStuff, HICON hIcon);
public static extern int ShellAboutA(HWND hWnd, [NativeTypeName("LPCSTR")] sbyte *szApp, [NativeTypeName("LPCSTR")] sbyte *szOtherStuff, HICON hIcon);
public HRESULT ReplaceIcon(int i, HICON hicon, int *pi) { return(((delegate * unmanaged <IImageList *, int, HICON, int *, int>)(lpVtbl[4]))((IImageList *)Unsafe.AsPointer(ref this), i, hicon, pi)); }
public static extern uint ExtractIconEx(string stExeFileName, int nIconIndex, ref HICON phiconLarge, ref HICON phiconSmall, uint nIcons);
/// <summary>Initializes a new instance of the <see cref="WindowClass"/> class and registers the class name.</summary> /// <param name="className"> /// <para> /// A string that specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, /// or any of the predefined control-class names. /// </para> /// <para> /// The maximum length for <c>lpszClassName</c> is 256. If <c>lpszClassName</c> is greater than the maximum length, the /// RegisterClassEx function will fail. /// </para> /// </param> /// <param name="hInst">A handle to the instance that contains the window procedure for the class.</param> /// <param name="wndProc"> /// A pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, /// see WindowProc. /// </param> /// <param name="styles">The class style(s). This member can be any combination of the Class Styles.</param> /// <param name="hIcon"> /// A handle to the class icon. This member must be a handle to an icon resource. If this member is <c>NULL</c>, the system provides /// a default icon. /// </param> /// <param name="hSmIcon"> /// A handle to a small icon that is associated with the window class. If this member is <c>NULL</c>, the system searches the icon /// resource specified by the <c>hIcon</c> member for an icon of the appropriate size to use as the small icon. /// </param> /// <param name="hCursor"> /// A handle to the class cursor. This member must be a handle to a cursor resource. If this member is <c>NULL</c>, an application /// must explicitly set the cursor shape whenever the mouse moves into the application's window. /// </param> /// <param name="hbrBkgd"> /// A handle to the class background brush. This member can be a handle to the brush to be used for painting the background, or it /// can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). /// <para> /// The system automatically deletes class background brushes when the class is unregistered by using <see cref="UnregisterClass"/>. /// An application should not delete these brushes. /// </para> /// <para> /// When this member is <c>NULL</c>, an application must paint its own background whenever it is requested to paint in its client /// area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or test /// the <c>fErase</c> member of the PAINTSTRUCT structure filled by the BeginPaint function. /// </para> /// </param> /// <param name="menuName"> /// A string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to /// identify the menu, use the MAKEINTRESOURCE macro. If this member is <c>NULL</c>, windows belonging to this class have no default menu. /// </param> /// <param name="extraBytes"> /// The number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero. /// </param> /// <param name="extraWinBytes"> /// The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application /// uses <c>WNDCLASSEX</c> to register a dialog box created by using the <c>CLASS</c> directive in the resource file, it must set /// this member to <c>DLGWINDOWEXTRA</c>. /// </param> public WindowClass(string className, HINSTANCE hInst, WindowProc wndProc, WindowClassStyles styles = 0, HICON hIcon = default, HICON hSmIcon = default, HCURSOR hCursor = default, HBRUSH hbrBkgd = default, string menuName = null, int extraBytes = 0, int extraWinBytes = 0) { // TODO: Find way to hold on to wndProc ref wc = new WNDCLASSEX { cbSize = (uint)Marshal.SizeOf(typeof(WNDCLASSEX)), lpfnWndProc = wndProc, hInstance = hInst, lpszClassName = className, style = styles, hIcon = hIcon, hIconSm = hSmIcon, hCursor = hCursor, hbrBackground = hbrBkgd, lpszMenuName = menuName, cbClsExtra = extraBytes, cbWndExtra = extraWinBytes, }; Atom = Win32Error.ThrowLastErrorIfNull(Macros.MAKEINTATOM(RegisterClassEx(wc))); }
private static extern bool DestroyIconInternal(HICON hIcon);
public static extern bool DrawIcon(HDC hdc, int x, int y, HICON hicon);
public static extern BOOL DestroyIcon(HICON hIcon);
public static extern BOOL GetIconInfo(HICON hIcon, out IconInfo pIconInfo);
public static extern HICON DuplicateIcon(HINSTANCE hInst, HICON hIcon);
public HRESULT SetOverlayIcon(HWND hwnd, HICON hIcon, [NativeTypeName("LPCWSTR")] ushort *pszDescription) { return(((delegate * unmanaged <ITaskbarList4 *, HWND, HICON, ushort *, int>)(lpVtbl[18]))((ITaskbarList4 *)Unsafe.AsPointer(ref this), hwnd, hIcon, pszDescription)); }
public HRESULT SetIconInfo(HICON hIcon, [NativeTypeName("LPCWSTR")] ushort *pszToolTip) { return(((delegate * unmanaged <IUserNotification *, HICON, ushort *, int>)(lpVtbl[5]))((IUserNotification *)Unsafe.AsPointer(ref this), hIcon, pszToolTip)); }
public static extern bool DestroyIcon(HICON hIcon);
public HRESULT SetIcon(HICON hIcon) { return(((delegate * unmanaged <ITfSystemLangBarItem *, HICON, int>)(lpVtbl[3]))((ITfSystemLangBarItem *)Unsafe.AsPointer(ref this), hIcon)); }
public static extern bool DrawIconEx(HDC hdc, int x, int y, HICON hicon, int cx, int cy, uint istep, HGDIOBJ hbr, uint flags);
private static extern int PrivateExtractIcons(string lpszFile, int nIconIndex, int cxIcon, int cyIcon, out HICON phicon, IntPtr piconid, uint nIcons, LR flags);
public static extern bool GetIconInfo(HICON hIcon, out ICONINFO iconinfo);
public static void PrivateExtractIcons(string lpszFile, int nIconIndex, int cxIcon, out HICON phicon, LR flags) { int res = PrivateExtractIcons(lpszFile, nIconIndex, cxIcon, cxIcon, out phicon, IntPtr.Zero, 1, flags); if (res == -1) { throw new FileNotFoundException("Could not load icon from '{0}'.".Fmt(lpszFile), lpszFile); } if (res != 1) { phicon = IntPtr.Zero; } }
public HRESULT CreateBitmapFromHICON(HICON hIcon, IWICBitmap **ppIBitmap) { return(((delegate * unmanaged <IWICComponentFactory *, HICON, IWICBitmap **, int>)(lpVtbl[22]))((IWICComponentFactory *)Unsafe.AsPointer(ref this), hIcon, ppIBitmap)); }
public IconHandle(HICON handle, bool ownsHandle = true) { HICON = handle; _ownsHandle = ownsHandle; }