shvetsov
asked on
Popup menu from taskbar icon
My program does the following when the user clicks the program's icon in the taskbar's tray area:
hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, ID1, "Title1");
// ..........
AppendMenu(hMenu, MF_STRING, ID16, "Title16");
GetCursorPos(&pt);
SetForegroundWindow(g_hwnd Main);
TrackPopupMenu(hMenu,
TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
pt.x, pt.y, 0, g_hwndMain, 0);
DestroyMenu(hMenu);
SendMessage(g_hwndMain, 0, 0, 0);
The popup menu hides after I click somewhere outside the menu, but it doesn't appeat next time I click the icon. Only on second or third time.
What should I do to correct this ?
hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, ID1, "Title1");
// ..........
AppendMenu(hMenu, MF_STRING, ID16, "Title16");
GetCursorPos(&pt);
SetForegroundWindow(g_hwnd
TrackPopupMenu(hMenu,
TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
pt.x, pt.y, 0, g_hwndMain, 0);
DestroyMenu(hMenu);
SendMessage(g_hwndMain, 0, 0, 0);
The popup menu hides after I click somewhere outside the menu, but it doesn't appeat next time I click the icon. Only on second or third time.
What should I do to correct this ?
Try PostMessage(g_hwndMain, WM_NULL, 0, 0) right after TrackPopupMenu and before DestroyMenu. Remove SendMessage(g_hwndMain, 0, 0, 0);.
My taskbarmenu is called exactly as yours is. The only difference: I don't have this SendMessage(...) at all. What is it for?
ASKER
4 chensu: Yes !!! It works. Thank you.
Please mark your comment as answer so I can grade it.
4 AndreasF: It must be PostMessage();
The popup menu doesnt pop up after the first click on the taskbar icon without it. I don't know why. Ask Bill Gates :)
Please mark your comment as answer so I can grade it.
4 AndreasF: It must be PostMessage();
The popup menu doesnt pop up after the first click on the taskbar icon without it. I don't know why. Ask Bill Gates :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey! AndreasF and chensu! It's my question! :)