Tray Icon Woes
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Tray Icon Woes

  1. #1
    Join Date
    Dec 2003
    Posts
    72

    Tray Icon Woes

    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?

  2. #2
    Join Date
    Dec 2003
    Posts
    72

    Re: Tray Icon Woes

    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.

  3. #3
    Join Date
    Dec 2003
    Posts
    72

    Re: Tray Icon Woes

    Ok, maybe some pseudocode will help.

    Code:
    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
    
    else
       minimize it.
    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.

  4. #4
    Join Date
    Dec 2003
    Posts
    72

    Re: Tray Icon Woes

    Ok, here is an example video: http://duke3d.org/example.avi

    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?

  5. #5
    Join Date
    Apr 2008
    Posts
    726

    Re: Tray Icon Woes

    there's probably a windows message that tells whenever a window gets the focus. use that to determine if you were the last window or not to have the focus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center