Code: Select all
#Persistent
#SingleInstance, Force
handle := LoadPicture("icon.png")
Gui, Add, Pic, w100 h-1, % "HBITMAP:*" handle ; works
Gui, Show
Menu, Tray, Icon, % "HBITMAP:*" handle ; doesn't work
GuiClose:
GuiEscape:
ExitApp
Code: Select all
#Persistent
#SingleInstance, Force
handle := LoadPicture("icon.png")
Gui, Add, Pic, w100 h-1, % "HBITMAP:*" handle ; works
Gui, Show
Menu, Tray, Icon, % "HBITMAP:*" handle ; doesn't work
GuiClose:
GuiEscape:
ExitApp
So, png is not supported.Icon [, FileName, IconNumber, 1]: Changes the script's icon to one of the ones from FileName. The following types of files are supported: ICO, CUR, ANI, EXE, DLL, CPL, SCR, and other types that contain icon resources.
Hi, teadrinker! Well, probably you are correct, thank you. I was confused by this:teadrinker wrote:So, png is not supported.
However, now I understand, that this probably works only for _inner_ menu items. (Which are shown when you click on tray icon with right mouse button).[v1.1.23+]: A bitmap or icon handle can be used instead of a filename. For example, HBITMAP:%handle%.
Code: Select all
hIcon := LoadPicture("icon.bmp", "Icon1", io)
but I didn't manage to get non-zero handle returned in any other way, when I want an icon. Maybe someone can clarify. In my experience, the resulting icon using the above method is usually subpar.Iconn: Indicates which icon to load from a file with multiple icons (generally an EXE or DLL file). If n is non-zero, the file must contain an icon. For example, "Icon2" loads the file's second icon
Code: Select all
#Persistent
#SingleInstance, Force
IMAGE_ICON := 1
bkColor:=0xffffff ; This color will be transparent, you might need to change this.
ico := new LoadPictureType("icon.png",, IMAGE_ICON, bkColor)
Gui, Add, Pic, w100 h-1, % "hIcon:*" ico.getHandle() ; works
Gui, Show
Menu, Tray, Icon, % "hIcon:*" ico.getHandle() ; works
return
GuiClose:
GuiEscape:
ExitApp
#include LoadPictureType.ahk
Hi Helgef! Thank you very much. Icons in AHK is a bit weird thing. "If you want to use bmp (bitmap image), you need to use hIcon, not hBitmap"... Hm! )))Helgef wrote:You can load a bmp as hIcon with LoadPicture, but not png it seems.Note that the documentation saysCode: Select all
hIcon := LoadPicture("icon.bmp", "Icon1", io)
but I didn't manage to get non-zero handle returned in any other way, when I want an icon. Maybe someone can clarify. In my experience, the resulting icon using the above method is usually subpar.Iconn: Indicates which icon to load from a file with multiple icons (generally an EXE or DLL file). If n is non-zero, the file must contain an icon. For example, "Icon2" loads the file's second icon
Therefor, I have written a script for loading images to hBitmap, hIcon or hCursor, it works well with png to hIcon as long as the png doesn't contain any transparency, you can tryyou need LoadPictureType.ahk. If the png contains transparency, you can open it in paint and save it as iconb.png to get rid of the transparency, then set bkColor to which ever color the tranparency became, in one test it became white .Code: Select all
#Persistent #SingleInstance, Force IMAGE_ICON := 1 bkColor:=0xffffff ; This color will be transparent, you might need to change this. ico := new LoadPictureType("icon.png",, IMAGE_ICON, bkColor) Gui, Add, Pic, w100 h-1, % "hIcon:*" ico.getHandle() ; works Gui, Show Menu, Tray, Icon, % "hIcon:*" ico.getHandle() ; works return GuiClose: GuiEscape: ExitApp #include LoadPictureType.ahk
cheers.