locked
Tray Icon Help RRS feed

  • Question

  • Hi.  I have my program able to be shown in the tray, and I added a double click ability.  If the program is hidden to the tray, it will of course show it when clicking the tray icon.  If the program is already active and shown, it will put it back to the tray when clicking it.  But, I can't for the life of me decide how to show the program when it's inactive but still in the taskbar when I click the tray icon.  For example, open my program, then switch to another program.  It will leave my program in both the taskbar and tray.  I don't know how to decide when I click my tray icon to show the program instead of minimize.  I tried everything from keeping an activation record in my activate event, but it doesn't work.
    Wednesday, March 3, 2010 11:57 PM

Answers

  • PJ's class may help you out.  It's got a lot of good stuff in it and I know it works with 2005:

    http://www.naughter.com/ntray.html

    Tom
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Thursday, March 4, 2010 2:06 AM
    • Proposed as answer by Mike_999 Friday, March 5, 2010 5:20 PM
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Friday, March 5, 2010 4:11 PM
  • There are two very likely functons, since it knows it's own main window handle.

    GetForegroundWindow to check if it is the topmost window. It could also quite easily use GetNextWindow to see if there is a window before it in z-order.

    I would suggest reading through the Windows section under Windowing, especially the function reference. You can find functions to get a lot of information on windows there.
    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Sunday, March 7, 2010 5:12 AM

All replies

  • Are you using MFC?  Here is a link to the Tray Menu sample that I hope helps you.
    http://msdn.microsoft.com/en-us/library/bb983878.aspx
    Thursday, March 4, 2010 12:08 AM
  • Hi, yes, but I'm using 2005.  I can't seem to find the tray menu sample in the large file of samples they give.
    Thursday, March 4, 2010 12:25 AM
  • PJ's class may help you out.  It's got a lot of good stuff in it and I know it works with 2005:

    http://www.naughter.com/ntray.html

    Tom
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Thursday, March 4, 2010 2:06 AM
    • Proposed as answer by Mike_999 Friday, March 5, 2010 5:20 PM
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Friday, March 5, 2010 4:11 PM
  • Hi.  I know how to bring the window to the front or hide it, but I mean a real specific case.  Do this, open a program which opens to the tray.  When, click on the tray icon, it automatically loses my program's focus.  But, I want it so that when I click on the tray icon, if my program was in the inactivated or in the tray, show it.  However, if my program was active, put it in the tray.  The problem is, just clicking the icon makes the program inactive, so I can never tell it was active before that or not.
    Friday, March 5, 2010 10:13 PM
  • 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?

    Saturday, March 6, 2010 7:32 PM
  • There are two very likely functons, since it knows it's own main window handle.

    GetForegroundWindow to check if it is the topmost window. It could also quite easily use GetNextWindow to see if there is a window before it in z-order.

    I would suggest reading through the Windows section under Windowing, especially the function reference. You can find functions to get a lot of information on windows there.
    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    • Marked as answer by Wesley Yao Wednesday, March 10, 2010 2:39 AM
    Sunday, March 7, 2010 5:12 AM