1 Attachment(s)
TrackPopupMenu and default taskbar menu
Hi everyone:
I'm not sure why this happens, so maybe someone can clear this up for me.
Say, I want to display a pop-up menu from my program's tray icon on the task bar. I do the following:
Code:
int nRes = TrackPopupMenu(hMenu, TPM_RIGHTALIGN | TPM_TOPALIGN |
TPM_LEFTBUTTON | TPM_VERPOSANIMATION | TPM_HORNEGANIMATION | TPM_RETURNCMD,
pnt.x, pnt.y, 0, hMainWnd, NULL);
Because of some bug in the Explorer shell the menu isn't dismissed when someone clicks outside of it, so I had to add the following code to accommodate for that (which can be found throughout Win32 forums online):
Code:
::SetForegroundWindow(hMainWnd);
int nRes = TrackPopupMenu(hMenu, TPM_RIGHTALIGN | TPM_TOPALIGN |
TPM_LEFTBUTTON | TPM_VERPOSANIMATION | TPM_HORNEGANIMATION | TPM_RETURNCMD,
pnt.x, pnt.y, 0, hMainWnd, NULL);
PostMessage(WM_NULL, 0, 0);
That takes away that bug, but what happens is that at times when my tray icon is first displayed on the task bar's tray and I try to right-click it, I get my pop-up menu and also get the default task bar menu (picture below) displayed over it, as if I right-clicked the task bar itself. This happens only the first time I right-click my tray icon.
Can someone tell me why this happens and how to remedy that?
PS. I'm running these tests on a Windows 7 with a default theme (and glass effect enabled).
Re: TrackPopupMenu and default taskbar menu
You need to show the code that creates the taskbar icon. Are you intercepting WM_RBUTTONDOWN or WM_CONTEXTMENU to display the popup menu?
Re: TrackPopupMenu and default taskbar menu
I process both like this:
Code:
case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
{
ShowTrayPopupMenu();
}
break;
Is it supposed to be done differently?
Re: TrackPopupMenu and default taskbar menu
Remove the redundant WM_RBUTTONDOWN case.
Code:
// case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
{
ShowTrayPopupMenu();
}
break;
Re: TrackPopupMenu and default taskbar menu
As a general rule, never display a popup menu with WM_RBUTTONDOWN. Instead, use WM_CONTEXTMENU.
Re: TrackPopupMenu and default taskbar menu
For some reason if I remove WM_RBUTTONDOWN it's not called at all.
Re: TrackPopupMenu and default taskbar menu
My bad. For task bar icon popups, use WM_RBUTTONDOWN and remove WM_CONTEXTMENU.
Re: TrackPopupMenu and default taskbar menu
Thanks, but I still get the same bug of two overlapping menus. I played a little with it, and to reproduce this bug you can add Sleep(500); after SetForegroundWindow call to make it come up for sure. I also believe that this only happens when some other window has keyboard focus (like any other Explorer window.)
Re: TrackPopupMenu and default taskbar menu
Quote:
Can someone tell me why this happens and how to remedy that?
It seems the effect has nothing to do with your code. I had the effect of the kind in regular Explorer window while right clicking an element without selecting it previously. So it's rather Win7 Explorer behavior.