Tray Icon Loading Issues

Get help with using AutoHotkey and its commands and hotkeys
Posts: 86
Joined: 27 Oct 2016, 15:06

Tray Icon Loading Issues

30 Dec 2018, 08:19

Hi, it would be great if you've any ideas what's wrong with my script over here ... 94#p255194

As you'll see from the second post, godofOOF had an error that I used to have intermittently - it didn't load the icon from disc. It may have been fixed when I updated GDI+ for me, because it never went wrong for a long time.

However, I switched to loading the icon with the HBITMAP:*%handle% method, hoping it would fix it, and now it occasionally fails to load again for me. I've not heard whether it fixed it for godofOOF. Helgef has tried it and not reported any problem yet.

On the loading of the icon, I don't really know exactly what I'm doing with the GDI, and just tried a few things, but gathered that I needed to create the handle with the relevant GDI+ function, to reference in the loading (I thought it would be okay to do it once where the graphics handle and pBitmap are allocated, but apparently not).

If anyone could spot the mistake, that would be much appreciated, or give any feedback at all on whether it fails to load the icon for you, always or intermittently. If it's now always just a very occasional failure, the other question is whether I could trap that and just have it go round again, i.e. with the timer loop updating the icon next time round. At the moment, the thread is closed, and the script stops working.

Incidentally, gwarble had a similar problem with HICON here ... 76&t=26716

User avatar
Delta Pythagorean
Posts: 567
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Tray Icon Loading Issues

31 Dec 2018, 00:09

This seems less of an issue with GDIP and more with AHK's Working directory.
SetWorkingDir, % A_ScriptDir is a good way to start with this problem.

If anything, you should try for a If (FileExist("clockfile.bmp")) for a precaution.

- [AHK].......: Unicode 64-bit
- [OS].........: Windows 10.0.18362
- [GITHUB]...:
- [PAYPAL]....:
- [DISCORD]..: Delta#3324

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
Posts: 86
Joined: 27 Oct 2016, 15:06

Re: Tray Icon Loading Issues

31 Dec 2018, 07:45

Cheers Delta Pythagorean, I'll try setting the working directory and see if that fixes it. I'm not using clockfile.bmp at all now, but noted for future. I should probably do a lot more error checking generally.
Posts: 86
Joined: 27 Oct 2016, 15:06

Re: Tray Icon Loading Issues

01 Jan 2019, 20:25

No fix yet. I added a try for the icon loading with a catch writing the ErrorLevel to a log file (mainly in the hope that it would just ignore the error and continue). It gave a blank error, but then kept throwing the error at every pass. My best workaround now is pretty awful, just to write to the log file and then Reload. It seems particularly prone to this when the system is under high load, like lots of windows open and then I decide to watch a video.

Code: Select all

; Update icon
	Menu, Tray, Icon, HBITMAP:*%hBitmap%
catch, e
	FileAppend, Error %e% at %tipstring%`n, errlog.txt
; tipstring is just the time stamp
Hoping someone can spot a way forward. :ugeek:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, DanRim, doubledave22, electrone77, f333t, fatphil, Google [Bot], mikeyww, scriptor2016, sipureysafta, solidsnake_fear, teadrinker, techmon, zxyzgt and 68 guests