ImageSearch and LoadPicture (transparency and lost hIcon)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

ImageSearch and LoadPicture (transparency and lost hIcon)

10 Jun 2017, 14:49

This code works on my Windows 7 PC, to move the cursor to the AHK exe icon.

However I had to set the transparency value to 85 for it to work on all 3 of: the systray, an AHK window title bar, the Program Files folder window.

The issues I am having are:
- Does a transparency value have to be set? Can this be avoided if you use TransBlack or TransWhite etc.
- How can the transparency colour RGB value for an icon be retrieved. (I tried MS Paint Windows XP version, NirSoft IconsExtract, IcoFX, Icon Sushi.)
- When ImageSearch is used, hIcon, appears not to work anymore. Although the variable does retain its value.
- Can this script be modified to work with Notepad's icon?
Thanks.

Code: Select all

q:: ;move cursor to 16x16 AHK exe icon e.g. systray, title bar, Explorer windows
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
vPath := A_AhkPath
hIcon := LoadPicture(vPath, "w16 h16", vType)
;SplashImage, HICON:%hIcon%, B
ImageSearch, vPosX, vPosY, 0, 0, % A_ScreenWidth, % A_ScreenHeight, % "*85 HICON:*" hIcon
;hIcon appears to be destroyed by using it with ImageSearch
;SplashImage, HICON:%hIcon%, B
MouseMove, % vPosX, % vPosY
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ImageSearch and LoadPicture (transparency and lost hIcon)

04 Sep 2017, 01:51

Code: Select all

q::
vPath := A_AhkPath
hIcon := LoadPicture(vPath, "w16 h16", vType)

w:: ;move cursor to 16x16 AHK exe icon e.g. systray, title bar, Explorer windows
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
ImageSearch, vPosX, vPosY, 0, 0, % A_ScreenWidth, % A_ScreenHeight, % "*85 HICON:*" hIcon
MouseMove, % vPosX, % vPosY
return
If I use the q hotkey it always works, but if I use the w hotkey it doesn't work.

This appears relevant:
Image Handles
https://autohotkey.com/docs/misc/ImageHandles.htm
By default, AutoHotkey treats the handle as though it loaded the image from file - for example, a bitmap used on a Picture control is deleted when the GUI is destroyed, and an image will generally be deleted immediately if it needs to be resized. To avoid this, put an asterisk between the colon and handle. For example: hbitmap:*%handle% (or "hbitmap:*" handle in an expression). With the exception of ImageSearch, this forces the command to take a copy of the image.
But I don't find this entirely clear. Can I reuse an hIcon? If I can't then it defeats the purpose of LoadPicture, which is to avoid reading an icon from a file every time you want to use ImageSearch.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Ianizer, mrdigitalis, teadrinker and 65 guests