Popup menu pops up in wrong place
-
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks! -
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks!You have two problems. First, the
point
parameter is in window coords, not screen coords. Second,TrackPopupMenu()
takes screen coords for the menu location. So you should callClientToScreen(&point)
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0.1! | RightClick-Encrypt You cannot truly appreciate Dilbert unless you've read it in the original Klingon. -
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks!The point is given to you in client coords, and
TrackPopupMenu()
expects screen coords, so useClientToScreen()
to convert the point.
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
-
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks!Or you could just call ::GetCursorPos(&point); Which will give you the current mouse position in screen coordinates Roger Allen - Sonork 100.10016 Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
-
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks!Thanks to all of you. That worked.
-
I derived a class from CListBox. In that class I added a handler for the right mouse button. When I click the right button, the menu pops up on my desktop. I know why its doing this, because the CPoint passed to the function is relative to the whole screen, not my listbox. I cant figure out how to tell the menu to popup where my mouse is. I tried ScreenToClient() but it didnt work.
void CMyListBox::OnRButtonUp(UINT nFlags, CPoint point) { CMenu Menu; Menu.LoadMenu(IDR_POPUP_MENU); CMenu *Popup = Menu.GetSubMenu(0); ScreenToClient(&point); Popup->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN, point.x, point.y, this, NULL); Menu.DestroyMenu(); }
Anybody help? Thanks!