TrackPopupMenu
-
According to the KB article Q135788 the below code is the correction action that is to be applied to have the TrackPopupMenu to behave accurately. Could somebody explain the problem better and provide a deeper understanding? What is the significance of sending WM_NULL message? SetForegroundWindow(hDlg); // Display the menu TrackPopupMenu( hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0);
-
According to the KB article Q135788 the below code is the correction action that is to be applied to have the TrackPopupMenu to behave accurately. Could somebody explain the problem better and provide a deeper understanding? What is the significance of sending WM_NULL message? SetForegroundWindow(hDlg); // Display the menu TrackPopupMenu( hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0);
Posting the null message to the popup menu's owner window forces a task switch to the application that displayed the menu.
WM_NULL
is chosen as it's a benign message that doesn't do anything more than cause the task switch. /raviThis is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
According to the KB article Q135788 the below code is the correction action that is to be applied to have the TrackPopupMenu to behave accurately. Could somebody explain the problem better and provide a deeper understanding? What is the significance of sending WM_NULL message? SetForegroundWindow(hDlg); // Display the menu TrackPopupMenu( hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0);
if i understood your question correctly, the according KB article in MSDN describes why this workaround is necessary: PRB: Menus for Notification Icons Do Not Work Correctly[^]
SYMPTOMS
...
When you display a context menu for a notification icon (see Shell_NotifyIcon),
clicking anywhere besides the menu or the window that created the menu
(if it is visible) doesn't cause the menu to disappear.
...RESOLUTION
...
The second problem is caused by a problem with TrackPopupMenu. It is necessary
to force a task switch to the application that called TrackPopupMenu at some
time in the near future. This can be accomplished by posting a benign message
to the window or thread.
...So the WM_NULL message is used to force a task switch to the calling app, so when you click outside the popup menu, the popup menu disappears correctly.
cheers, mykel
OMM: "Let us be thankful we have commerce. Buy more. Buy more now. Buy. And be happy."