MSDN library mentions this problem in the description of ::TrackPopupMenu function. In order to solve it, there is a recomendation to make the window foreground before TrackPopupMenu, and then to post a benign message immediately after TrackPopupMenu:
::SetForegroundWindow(hwnd);
::TrackPopupMenu(...);
::PostMessage(hwnd, WM_NULL, 0, 0);
Or, in case of MFC, inside a member:
SetForegroundWindow();
TrackPopupMenu(...);
PostMessage(WM_NULL);
Hope this will help. -- modified at 10:11 Friday 2nd June, 2006