Ok, I have figured out most things I need to know about using tray icons except one thing. When someone double-clicks the icon, I want it so that it shows it in the case where the program is already iconized and also when the program isn't iconized but happens to be inactive (i.e. they open the program then switch to another window). In all other cases, I want it to iconize the program. Most tray apps I've used do this. I figured out 2 of the 3 cases, but I can't figure out how to distinguish when they click the tray icon if the program was previously active or not. The issue lies in the fact that just by clicking the tray icon, the program inactivates, so my click event can't really tell if it was "previously" active or already active before I clicked the icon. Any thoughts on how I can detect this?
Ok, I tested programs like mIRC and uTorrent which exhibit the behavior I want a little closer. I now believe they aren't doing exactly what I thought. Instead, it appears they minimize to the tray if you click the tray icon in any case where the program is on top, even if it's inactive.
So, is there a way to test if the program is on top, even if it's inactive? In other words, say you open a program and then click the task bar blank space. The program's title bar shows inactive, but it's still on top. What state is the program in in this case, besides inactive?
Last edited by miclus; March 5th, 2010 at 06:04 PM.
if (program is minimized)
restore it and bring it to the foreground.
else if (program isn't minimized and isn't on top)
bring it to the foreground
It's the else if case I can't figure out. I tried things like GetForegroundWindow() and GetActiveWindow(), but these never vary in my clicking on tray event. In other words, in my tray click event, my program is never the foreground window and never the active window, since the icon click itself made it that way.
The first time when mIRC is showing and active, if I click the tray icon, it minimizes it. The second time, I select another app (IE), then click the tray icon, it shows mIRC. The third time is the part I can't figure out. I click the blank taskbar area, mIRC is still showing but inactive. But, then I click the tray icon and it minimizes it. How did it detect that mIRC was still on top of the screen like that?