Jump to content
  • Advertisement
Sign in to follow this  
nekobasu33

AppendMenu() results in RANDOM positioning

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using AppendMenu function to create a pop-up menu, however, sometimes if I click on the icon, the menu appears at random position on the screen. However, if I click on the icon twice or more, the pop-up menu will appear at the right/desired place. Does anybody know what's going on? Here's my code snippet:
HMENU myMenu = NULL;
myMenu = CreatePopupMenu();
	
AppendMenu(myMenu, MF_STRING, IDM_CONFIG, _T("Configuration"));
AppendMenu(myMenu, MF_STRING, IDM_TRAYABOUT, _T("About"));
AppendMenu(myMenu, MF_SEPARATOR, 0, _T("")); 
AppendMenu(myMenu, MF_STRING, IDM_TRAYEXIT, _T("Exit"));

//Get the position of the mouse at the time the icon was clicked 
DWORD mp = GetMessagePos();

SetForegroundWindow(hWnd);

UINT clicked = TrackPopupMenu(	myMenu,
                                TPM_RETURNCMD | TPM_NONOTIFY, 
				GET_X_LPARAM(mp), GET_Y_LPARAM(mp), 
				0, 
				hWnd, 
				NULL);


I am assuming the problem lies before the "TrackPopupMenu(...);", but I have no idea on how to fix it.

Share this post


Link to post
Share on other sites
Advertisement
The problem, I believe, is GetMessagePos(). That gets the cursor position for the last message received. In contrast, GetCursorPos() gets the current cursor position.

Share this post


Link to post
Share on other sites
Do you mean that if I place my cursor and a click on a place, then GetCursorPos() will return that position?
Do you have any suggestion on how I can fix this? so when I click on an icon on the system tray, then the menu will actually come out from that position.

Share this post


Link to post
Share on other sites
ahh..too much programming, for some reason I kept reading GetCursorPos() and GetMessagePos() as a same word. :D

Thank you so much for the help. It's working like a charm now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!