1 year ago
#68622
NatsuKage
tray icon pop-up menu right-click problem in windows server 2016
I have created a tray icon,
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
hMainIcon = LoadIcon(hInstance,(LPCTSTR)MAKEINTRESOURCE(IDI_SYSTRAYDEMO));
nidApp.cbSize = sizeof(NOTIFYICONDATA); // sizeof the struct in bytes
nidApp.hWnd = (HWND) hWnd; //handle of the window which will process this app. messages
nidApp.uID = IDI_SYSTRAYDEMO; //ID of the icon that willl appear in the system tray
nidApp.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; //ORing of all the flags
nidApp.hIcon = hMainIcon; // handle of the Icon to be displayed, obtained from LoadIcon
nidApp.uCallbackMessage = WM_USER_SHELLICON;
LoadString(hInstance, IDS_APPTOOLTIP,nidApp.szTip,MAX_LOADSTRING);
Shell_NotifyIcon(NIM_ADD, &nidApp);
and pop up a menu when receive WM_RBUTTONUP,
SetForegroundWindow(hWnd);
TrackPopupMenu(hPopMenu,TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_BOTTOMALIGN,lpClickPoint.x, lpClickPoint.y,0,hWnd,NULL);
PostMessage(hWnd, WM_NULL, 0, 0);
It works well in windows 10. But in windows server 2016, when I right-click the tray, sometimes the taskbar menu pop-up instead of my menu. I notices that this bug also appears in some others applications like windows Taskmgr.exe, but never appears in other apps. It seems that sometimes the right-click message has been sent to the taskbar. How can I fix this bug?
Any help would be appreciated.
Sry, I found there are some mistakes in previous question description. There are two unexpected behaviors I found in right-click. 1、single right-click my tray icon, and the taskbar menu sometimes will be poped up, as same as the Taskmgr.exe. 2、continuous right-click my tray. Somestimes the taskbar menu will be poped up.
Case 1 appears only when I pop up my menu in the WM_RBUTTONDOWN message callback. After I change the pop-up event message to WM_RBUTTONUP, the case 1 no longer appear. The Taskmgr.exe also pop-up menu when receive WM_RBUTTONDOWN so it trigger case 1.
Case 2 still confuses me, I tried using a simple tray demo written by c# but still trigger this bug. It seems that somtimes my tray lose focus of the cursor while I keep right-clicking it, the cursor event messages are sent to the taskbar, whose menu be poped-up.
c++
winapi
windows-server-2016
popupmenu
trayicon
0 Answers
Your Answer