Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup Menu just showing up at the top left corner of the screen

Status
Not open for further replies.

jasonzhangx

Programmer
Mar 12, 2002
8
US
I am building an explorer like GUI using contextmenu. The section of triggering the menu is as follow:

CMenu menu;
menu.LoadMenu(IDR_MENU_Phi);
CMenu *pContextMenu=menu.GetSubMenu(0);
ASSERT(pContextMenu);
pContextMenu->TrackPopupMenu(TPM_CENTERALIGN
|TPM_RIGHTBUTTON |TPM_LEFTBUTTON, point.x, point.y, this);

The contextmenu is showing up at the corner of the screen, but mouse click position is far from that position. point.x and point.y should be the mouse click position. Any suggestions?
 
Try this:
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN |
TPM_RIGHTBUTTON,
point.x
point.y,
this);

HTH
bunny
 
Thanks for the suggestions. I tried them, but the menu is stilling keeping showing up at the top left corner of the computer screen. I draged the windows to far away from the top left corner, but the menu is still keeping showing at the top left corner of the screen.

 
I have a popup menu that works. It looks like bunny's example. But my popup menu was created with m_fractMenu.CreatePopupMenu(); Maybe your menu is not a popup menu and that is the problem?! [dazed]
 
I found the solution. Before calling TrackPopupMenu(...), the point should be converted with ClientToScreen(&point) as follow:

.
.
.
ClientToScreen(&point);
pContextMenu->TrackPopupMenu(TPM_CENTERALIGN
|TPM_RIGHTBUTTON |TPM_LEFTBUTTON,
point.x, point.y, this);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top