我使用创建我的系统托盘图标Shell_NotifyIcon
然后陷阱及其WM_LBUTTONDBLCLK
为当用户双击该图标的通知(我用它显示一个对话框窗口。)我也陷阱WM_RBUTTONDOWN
通知显示上下文菜单。
现在,我认为这将是很好的一个单一的左键点击后,显示上下文菜单。 但我怎么做呢?
如果我的陷阱WM_LBUTTONDOWN
和展示我的上下文菜单,它工作正常。 但后来,当有人双击该图标,它首先表明我的上下文菜单,然后显示的对话框窗口。 所以,我不知道如何克服呢?
编辑:这是我的代码:
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = this->GetSafeHwnd();
nid.uID = TRAY_ICON_ID1;
nid.uFlags = NIF_ICON;
nid.uCallbackMessage = TRAY_NOTIFICATION_ID1;
nid.hIcon = ghIcon;
Shell_NotifyIcon(NIM_ADD, &nid);
接着:
ON_MESSAGE(TRAY_NOTIFICATION_ID1, OnTrayIconNotifications)
LRESULT OnTrayIconNotifications(WPARAM wParam, LPARAM lParam)
{
UINT uID = (UINT)wParam;
UINT uMouseMsg = (UINT)lParam;
if(uID == TRAY_ICON_ID1)
{
switch(uMouseMsg)
{
case WM_RBUTTONDOWN:
{
//Show context menu
//...
int nChosenCmd = TrackPopupMenu(hMenu,
TPM_RIGHTALIGN | TPM_TOPALIGN |
TPM_LEFTBUTTON | TPM_VERPOSANIMATION |
TPM_HORNEGANIMATION | TPM_RETURNCMD,
x, y, 0,
this->GetSafeHwnd(), NULL);
}
break;
case WM_LBUTTONDBLCLK:
{
//Show dialog window
CDialogBasedClass dlg(this);
dlg.DoModal();
}
break;
}
}
return 0;
}