Thread: Popup menu in tray wont disapear

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    26

    Popup menu in tray wont disapear

    I have a program that diplays a popup menu when you right-click the tray icon. The menu works perfectly fine except that it if you activate the menu and dont click a menu item it will stay up.
    Code:
    case WM_SHELLNOTIFY:
                 {
                                if(lParam == WM_RBUTTONDOWN)
                                {
                                          GetCursorPos(&pt);
                                          TrackPopupMenu(hPopupMenu,TPM_RIGHTALIGN,pt.x,pt.y,0,hwnd,0);
                                }
                                if(lParam == WM_LBUTTONDBLCLK)
                                {
                                          SendMessage(hwnd,WM_COMMAND,SHOW,0);
                                }
                 }
    			 break;
    Help please
    thanks

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Hmmmmmmm,
    I do this and don't have that problem, then I use a local for the menu so may just be loosing scope.

    try..........

    Adding TPM_RETURNCMD to the TrackPopupMenu style. Catch the return (0 for fail or ID selected).

    Then kill/hide the menu if zero returned.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    You need to set your window as foreground with SetForegroundWindow() before calling TrackPopupMenu().

    Quoted from TrackPopupMenu on MSDN:

    To display a context menu for a notification icon, the current window must be the foreground window before the application calls TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the window that created the menu (if it is visible). However, when the current window is the foreground window, the second time this menu is displayed, it displays and then immediately disappears. To correct this, you must force a task switch to the application that called TrackPopupMenu at some time in the near future.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    thanx guys.
    hdood's solution worked perfectly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. popup menu in MFC?
    By Robert602 in forum Windows Programming
    Replies: 7
    Last Post: 07-25-2007, 09:34 PM
  4. TreeView + Popup menu
    By JaWiB in forum Windows Programming
    Replies: 9
    Last Post: 02-17-2006, 01:56 AM