Link to home
Start Free TrialLog in
Avatar of shvetsov
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_hwndMain);
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 ?
Avatar of chensu
chensu
Flag of Canada image

Try PostMessage(g_hwndMain, WM_NULL, 0, 0) right after TrackPopupMenu and before DestroyMenu. Remove SendMessage(g_hwndMain, 0, 0, 0);.
Avatar of AndreasF
AndreasF

My taskbarmenu is called exactly as yours is. The only difference: I don't have this SendMessage(...) at all. What is it for?
Avatar of shvetsov

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 :)
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey! AndreasF and chensu! It's my question! :)