1
我寫了下面的WndProc。它由通知圖標使用。我刪除了不重要的部分(如默認標籤)以獲得更好的概述。這段代碼爲什麼運行?
當我用鼠標右鍵單擊Nofify圖標時,出現上下文菜單。當我點擊一個項目時,我會得到TrackPopupMenu的相應返回值並將其打印出來。但是,TrackPopupMenu是一個阻塞調用,但WndProc在打開上下文菜單時工作正常。爲什麼?
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, ID_TRAY_EXIT_CONTEXT_MENU_ITEM, displayString);
}
break;
case WM_TRAYICON:
switch (lParam)
{
case WM_RBUTTONUP:
{
POINT curPoint;
GetCursorPos(&curPoint);
UINT clicked = TrackPopupMenu(
hMenu,
TPM_RETURNCMD | TPM_NONOTIFY,
curPoint.x,
curPoint.y,
0,
hWnd,
NULL
);
std::cout << std::to_string(clicked) << std::endl;
}
break;
}
std::cout << lParam << std::endl;
break;
}
return 0;
}