Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Popup menu pops up in wrong place

Popup menu pops up in wrong place

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel1324
    wrote on last edited by
    #1

    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!

    M PJ ArendsP R D N 5 Replies Last reply
    0
    • D Daniel1324

      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!

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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 call ClientToScreen(&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.

      1 Reply Last reply
      0
      • D Daniel1324

        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!

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        The point is given to you in client coords, and TrackPopupMenu() expects screen coords, so use ClientToScreen() 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!

        Within you lies the power for good; Use it!

        1 Reply Last reply
        0
        • D Daniel1324

          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!

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          0
          • D Daniel1324

            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!

            D Offline
            D Offline
            Daniel1324
            wrote on last edited by
            #5

            Thanks to all of you. That worked.

            1 Reply Last reply
            0
            • D Daniel1324

              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!

              N Offline
              N Offline
              n 0
              wrote on last edited by
              #6

              some times MFC drives me so nuts that i use SDK procs. CPoint cpPoint; GetCursorPos(&cpPoint);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups