Tray icon's menu

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Looking for a good example of how to show a popup menu in response to the user right-clicking on the icon in the 'taskbar notification area' (tray). I'm fine with creating the icon and responding to its messages. It's the showing of the popup menu I can't do
I've tried it using TrackPopupMenu function, but it returns 0 and GetLastError when called immediately after it returns zero aswell. The menu passed to TrackPopupMenu was got from GetSubMenu(hMenuMain, 0) (where hMenuMain was got by calling LoadMenu(hInst, IDR_MENU), and IDR_MENU is the only menu resource in the application, and it has only got one 'sub' menu )

Can anyone lend any assistance

Thank
 
Here is a sample for your reference

CTest::OnIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
switch (lParam)
{
case WM_RBUTTONDOWN:
HMODULE mod = GetModuleHandle(NULL);

POINT point;
GetCursorPos(&point);

HMENU menu = LoadMenu(mod, MAKEINTRESOURCE(IDR_MENU1));
HMENU hmenuTrackPopup = GetSubMenu(menu, 0);
SetForegroundWindow(m_hWnd);
TrackPopupMenu(hmenuTrackPopup, 0, point.x, point.y, 0, m_hWnd, 0);
PostMessage(WM_NULL, 0, 0);
DestroyMenu(menu);
}

return 0;
};
Bonj said:
Looking for a good example of how to show a popup menu in response to the
user right-clicking on the icon in the 'taskbar notification area' (tray).
I'm fine with creating the icon and responding to its messages. It's the
showing of the popup menu I can't do!
I've tried it using TrackPopupMenu function, but it returns 0 and
GetLastError when called immediately after it returns zero aswell. The menu
passed to TrackPopupMenu was got from GetSubMenu(hMenuMain, 0) (where
hMenuMain was got by calling LoadMenu(hInst, IDR_MENU), and IDR_MENU is the
only menu resource in the application, and it has only got one 'sub' menu ))
 
Bonj a écrit:
It's the setforegroundwindow I was forgetting, would omitting that cause the
menu not to display at all?
Also what's the null message for?

KB135788 (FAQ)
 
Right, that's great cheers.
It's the setforegroundwindow I was forgetting, would omitting that cause the
menu not to display at all?

Also what's the null message for?
 
Back
Top