Howdy, Stranger!

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

Categories

Unsolveable problem with tray icon ???

s_ks_k Member Posts: 57
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

  • pingpongpingpong Member Posts: 937
    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.
    :

  • s_ks_k Member Posts: 57
    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.
    : :
    :
    :

  • pingpongpingpong Member Posts: 937
    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.
    : : :
    : :
    : :
    :
    :

  • zenboyzenboy Member Posts: 26
    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)
  • s_ks_k Member Posts: 57
    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.
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • pingpongpingpong Member Posts: 937
    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.
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ___ [ http://forcoder.org ] free video tutorials and ebooks about // C++, Perl, JavaScript, Visual Basic .NET, C#, MATLAB, Go, Assembly, Ruby, Visual Basic, Scratch, Java, Swift, R, Python, PHP, C, PL/SQL, Objective-C, Delphi Scala, Rust, Crystal, Hack, COBOL, Lua, Bash, Awk, VBScript, SAS, Scheme, FoxPro, Prolog, Logo, Dart, Ada, Julia, ML, Kotlin, Lisp, Erlang, Fortran, Clojure, D, LabVIEW, Transact-SQL, F#, Alice, Apex, ABAP // ____

Sign In or Register to comment.