Code: Select all
hIcon32 := DllCall("LoadImage", uint, 0
, str, "My Icon.ico" ; Icon filename (this file may contain multiple icons).
, uint, 1 ; Type of image: IMAGE_ICON
, int, 32, int, 32 ; Desired width and height of image (helps LoadImage decide which icon is best).
, uint, 0x10) ; Flags: LR_LOADFROMFILE
Gui +LastFound
SendMessage, 0x80, 1, hIcon32 ; 0x80 is WM_SETICON; and 1 means ICON_BIG (vs. 0 for ICON_SMALL).
Gui Show
I use shell32.dll icons in many cases, in order to avoid the need for external icon files, and the limited selection of icons in shell32.dll suits the limited number of cases where I actually need to do this.
This works just fine for setting a tray icon, for example...
Code: Select all
;-----------------------------------------------------------------------------
; Create small icon for the tray
;-----------------------------------------------------------------------------
Menu, Tray, Icon, Shell32.dll, 255
;-----------------------------------------------------------------------------
This code below doesn't work--an attempt at adapting the help topic code above.
If anyone sees any mistakes in the DLL call arguments please let me know... this code is executed before the GUI is created via Gui, Show
Code: Select all
;-----------------------------------------------------------------------------
; Create large icon for Alt+Tab switch window
; https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
;-----------------------------------------------------------------------------
hIcon32 := DllCall("LoadImage", unit, hInst:=DllCall("GetModuleHandle", str, "Shell32.dll")
, str, "#255" ; Icon resource # within DLL
, uint, IMAGE_ICON:=1
, int, IcoWidth:=32, int, IcoHeight:=32 ; Desired width and height of image (helps LoadImage decide which icon is best).
, uint, Flags:=0)
SendMessage, WM_SETICON:=0x80, ICON_BIG:=1, hIcon32