我创建了一个弹出菜单,当用户使用TrackPopupMenu单击任务栏图标时将显示该菜单。代码工作正常,直到我在菜单外单击以取消选择项。然后,每当我左/右键单击图标时,菜单就会弹出并在我看到它之前立即消失(看起来 TrackPopupMenu 立即返回 0)。MDSN 告诉了PostMessage(hDlg, WM_NULL, 0, 0);
在TrackPopupMenu 之后添加的方法来修复,但它不起作用。
这是我的代码:
case WM_LBUTTONUP :
case WM_RBUTTONUP :
POINT p;
GetCursorPos(&p);
HMENU hPopupMenu = CreatePopupMenu();
AppendMenu(hPopupMenu, MF_ENABLED, ID_ADDMUSIC, L"Add music" );
AppendMenu(hPopupMenu, MF_ENABLED, ID_REMOVEMUSIC, L"Remove music");
SetForegroundWindow(msgInfo->hwnd);
result = TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_RIGHTALIGN | TPM_NONOTIFY |
TPM_RETURNCMD | TPM_RIGHTBUTTON | TPM_VERNEGANIMATION,
p.x, p.y, 0, msgInfo->hwnd, NULL);
PostMessageW(msgInfo->hwnd, WM_NULL, 0, 0);
DestroyMenu(hPopupMenu);