Taskbar menu popped up on your icon?

You created an icon in system notification area, and want it to responding your mouse click.Usually, you want your application’s menu can be popped up after you clicked on it, generally, right clicked on it.

According to MSDN, you wrote down following codes,

case WM_RBUTTONDOWN:
{
...
SetForegroundWindow(hDlg);

// Display the menu
TrackPopupMenu( hSubMenu,
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
hDlg,
NULL);

PostMessage(hDlg, WM_NULL, 0, 0);
...
}

Right, it works. But why you got taskbar menu popping up again and again after your clicked on your own icon? What’s wrong with your code? Is that a bug of Windows shell itself? You can think so, but you still need a work-around.

Very fortunately, the key is very very simple. You only need change WM_RBUTTONDOWN to WM_RBUTTONUP.

(If your application stuck in WM_RBUTTONDOWN, complain it to Microsoft.)