How to get CMenu popup menu to disappearing?
c++, mfc, visual-studio-2010, windows-7
Solution
The solution that worked for me was invoking the `SetForegroundWindow();` function before calling `TrackPopupMenu`.
I found the solution in Remarks of the `TrackPopupMenu` function description.
Problem
I have a popup menu for my application in the system tray. The issue I'm have is I can not get the menu to disappear without selecting an item. How could I get the popup menu to disappear when I click elsewhere in windows? Here is the code for making the popup menu appear: ``` LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if( message == WM_MYMESSAGE && lParam == WM_RBUTTONDOWN) { m_menu.CreatePopupMenu(); POINT point; GetCursorPos(&point); m_menu.AppendMenu(MF_POPUP, WM_MAXIMIZE, _T("Maximize")); m_menu.AppendMenu(MF_POPUP, WM_EXIT, _T("Exit")); m_menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this); } return CDialog::WindowProc(message, wParam, lParam); } ``` I've tried using `CMenu::DestroyMenu` with no luck.