Unsolveable problem with tray icon ???

Hi,
I'm really out of my knowldedge with this problem:
I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....

Has anybody any idea ???

Any suggestion will help.

Standa.

Comments

  • before you call TrackPopupMenu or whatever, call SetForgroundWindow with your main window.

    : Hi,
    : I'm really out of my knowldedge with this problem:
    : I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....
    :
    : Has anybody any idea ???
    :
    : Any suggestion will help.
    :
    : Standa.
    :

  • I call SetForegroundWindow and even though it doesnt work. It works only when main window is minimized but when it is maximized the tray menu doesnt disappear....I really dont know what do to...

    : before you call TrackPopupMenu or whatever, call SetForgroundWindow with your main window.
    :
    : : Hi,
    : : I'm really out of my knowldedge with this problem:
    : : I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....
    : :
    : : Has anybody any idea ???
    : :
    : : Any suggestion will help.
    : :
    : : Standa.
    : :
    :
    :

  • Always worked for me. Could you show us the pop up menu code?

    : I call SetForegroundWindow and even though it doesnt work. It works only when main window is minimized but when it is maximized the tray menu doesnt disappear....I really dont know what do to...
    :
    : : before you call TrackPopupMenu or whatever, call SetForgroundWindow with your main window.
    : :
    : : : Hi,
    : : : I'm really out of my knowldedge with this problem:
    : : : I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....
    : : :
    : : : Has anybody any idea ???
    : : :
    : : : Any suggestion will help.
    : : :
    : : : Standa.
    : : :
    : :
    : :
    :
    :

  • Here's a link to an article that discusses some of the known 'features.' that Microsoft included in the system tray.

    ALSO INCLUDES A CLASS 'CSystemTray'

    I would definitely check this out:

    http://www.codeproject.com/shell/systemtray.asp


    (haven't slept in two day.... good night)
  • Hi pingpong,
    yes it worked for me as well, but just in single-thread scenario. Now, when I create separate CWinThread (with its own CFrameWnd main window receiving tray notifications), it doesn't work. Here is the code:

    CFakeWnd::OnTrayNotify()
    {
    case RBUTTONDOWN:
    {
    if (bMainWindowMinimized)
    minimizeMainWindow();
    else
    showMainWindow();

    if (bMainWindowMinimized)
    SetForegroundWindow()
    else
    foregroundMainWindow()

    TrackPopupMenu(hWnd,...,..NULL);
    SendMessage(WM_NULL, 0, 0);
    DestroyMenu(hTrayMenu);
    hTrayMenu = 0;
    }

    when main application window is minimized, it works fine. But when its maximized, tray menu doesn't disappear after losing focus.
    foregroundMainWindow() just sends a notify message (WM_COPYDATA) to main application thread telling the main window to call SetForegroundWindow(). I also tried to call SetForegroundWindow() in CFakeWnd::OnTrayNotify() regardless of whether main window is minimized or not, but it didn't work. Have you any idea ?

    Thanks Standa.




    : Always worked for me. Could you show us the pop up menu code?
    :
    : : I call SetForegroundWindow and even though it doesnt work. It works only when main window is minimized but when it is maximized the tray menu doesnt disappear....I really dont know what do to...
    : :
    : : : before you call TrackPopupMenu or whatever, call SetForgroundWindow with your main window.
    : : :
    : : : : Hi,
    : : : : I'm really out of my knowldedge with this problem:
    : : : : I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....
    : : : :
    : : : : Has anybody any idea ???
    : : : :
    : : : : Any suggestion will help.
    : : : :
    : : : : Standa.
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • No, sorry no idea. I never had more than one window when doing tray icons and always do a SetForegroundWindow to the window I used in the NOTIFYICONDATA.hWnd structure. Have you tried that? If that doesnt work, then sorry! I dont know the answer.

    Good luck my friend.

    : Hi pingpong,
    : yes it worked for me as well, but just in single-thread scenario. Now, when I create separate CWinThread (with its own CFrameWnd main window receiving tray notifications), it doesn't work. Here is the code:
    :
    : CFakeWnd::OnTrayNotify()
    : {
    : case RBUTTONDOWN:
    : {
    : if (bMainWindowMinimized)
    : minimizeMainWindow();
    : else
    : showMainWindow();
    :
    : if (bMainWindowMinimized)
    : SetForegroundWindow()
    : else
    : foregroundMainWindow()
    :
    : TrackPopupMenu(hWnd,...,..NULL);
    : SendMessage(WM_NULL, 0, 0);
    : DestroyMenu(hTrayMenu);
    : hTrayMenu = 0;
    : }
    :
    : when main application window is minimized, it works fine. But when its maximized, tray menu doesn't disappear after losing focus.
    : foregroundMainWindow() just sends a notify message (WM_COPYDATA) to main application thread telling the main window to call SetForegroundWindow(). I also tried to call SetForegroundWindow() in CFakeWnd::OnTrayNotify() regardless of whether main window is minimized or not, but it didn't work. Have you any idea ?
    :
    : Thanks Standa.
    :
    :
    :
    :
    : : Always worked for me. Could you show us the pop up menu code?
    : :
    : : : I call SetForegroundWindow and even though it doesnt work. It works only when main window is minimized but when it is maximized the tray menu doesnt disappear....I really dont know what do to...
    : : :
    : : : : before you call TrackPopupMenu or whatever, call SetForgroundWindow with your main window.
    : : : :
    : : : : : Hi,
    : : : : : I'm really out of my knowldedge with this problem:
    : : : : : I'm developing typical MFC application, using tray icon. Because of certain reasons, I'm creating and handling tray icon in separate thread (so tray icon actions are handled in other thread than the main application window is running). It works fine with one exception. When I click on tray icon, the tray menu appears, OK, I change focus to some other application and the tray menu doesn't disappear. I have tried many ways to do it but nothing has helped....
    : : : : :
    : : : : : Has anybody any idea ???
    : : : : :
    : : : : : Any suggestion will help.
    : : : : :
    : : : : : Standa.
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories