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. How to get cursor position in status bar?

How to get cursor position in status bar?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelptutorialannouncement
13 Posts 4 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.
  • V Vladislav Gospodinov

    Hello...This question may sound silly to some of you but I've been stuck on it for few days and can't find any answer... So I need to have the mouse position x and y displayed in the status bar. So far I add new string to the table, in the indicators array, afx_msg void OnUpdateCurPos(CCmdUI *pCmdUI) in the message map and ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSOR,OnUpdateCurPos) When I run it's there but can't find the right way to update the cords. I think it must work with ON_MOUSEMOVE func...I've tried several codes in ON_MOUSEMOVE and OnUpdateCurPos but it doesn't work at all... Working with SDI.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    What does your OnUpdateCurPos() and OnMouseMove() functions look like? Have you called SetCapture()?

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    V 1 Reply Last reply
    0
    • D David Crow

      What does your OnUpdateCurPos() and OnMouseMove() functions look like? Have you called SetCapture()?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      V Offline
      V Offline
      Vladislav Gospodinov
      wrote on last edited by
      #3

      Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?

      void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
      {
      // TODO: Add your message handler code here and/or call default
      SetCapture();
      CFrameWnd::OnLButtonDown(nFlags, point);
      }

      void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
      {
      // TODO: Add your message handler code here and/or call default
      if(GetCapture()==this){
      posX=point.x;
      posY=point.y;
      }
      CFrameWnd::OnMouseMove(nFlags, point);
      }

      void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
      CString pos;
      pos.Format(ID_INDICATOR_CURSOR,posX,posY);
      m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
      }

      Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...

      J D 2 Replies Last reply
      0
      • V Vladislav Gospodinov

        Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?

        void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
        {
        // TODO: Add your message handler code here and/or call default
        SetCapture();
        CFrameWnd::OnLButtonDown(nFlags, point);
        }

        void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
        {
        // TODO: Add your message handler code here and/or call default
        if(GetCapture()==this){
        posX=point.x;
        posY=point.y;
        }
        CFrameWnd::OnMouseMove(nFlags, point);
        }

        void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
        CString pos;
        pos.Format(ID_INDICATOR_CURSOR,posX,posY);
        m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
        }

        Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...

        J Offline
        J Offline
        jeron1
        wrote on last edited by
        #4

        What happens when you change your Format statement to

        pos.Format(" x: %d ,y: %d " ,posX,posY);

        V 1 Reply Last reply
        0
        • J jeron1

          What happens when you change your Format statement to

          pos.Format(" x: %d ,y: %d " ,posX,posY);

          V Offline
          V Offline
          Vladislav Gospodinov
          wrote on last edited by
          #5

          Nothing. Stays the same:

          "x: 0 , y: 0"

          J 1 Reply Last reply
          0
          • V Vladislav Gospodinov

            Nothing. Stays the same:

            "x: 0 , y: 0"

            J Offline
            J Offline
            jeron1
            wrote on last edited by
            #6

            It that the value of pos immediately after the Format() call?

            V 1 Reply Last reply
            0
            • J jeron1

              It that the value of pos immediately after the Format() call?

              V Offline
              V Offline
              Vladislav Gospodinov
              wrote on last edited by
              #7

              Yes... Seems like OnMouseMove doesn't update posX and posY. If I do :

              void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
              CString pos;
              posX=100;
              posY=200;
              pos.Format(L" x: %d ,y: %d ",posX,poxY);
              m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
              }

              It does put

              "x: 100,y: 200"

              in the status bar...

              J 1 Reply Last reply
              0
              • V Vladislav Gospodinov

                Yes... Seems like OnMouseMove doesn't update posX and posY. If I do :

                void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
                CString pos;
                posX=100;
                posY=200;
                pos.Format(L" x: %d ,y: %d ",posX,poxY);
                m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
                }

                It does put

                "x: 100,y: 200"

                in the status bar...

                J Offline
                J Offline
                jeron1
                wrote on last edited by
                #8

                So, it looks like GetCapture() != this, perhaps have a look at this[^] article.

                1 Reply Last reply
                0
                • V Vladislav Gospodinov

                  Well that is the problem :P I've added SetCapture() when you press LButton, but I'm not rly sure if I need it?

                  void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
                  {
                  // TODO: Add your message handler code here and/or call default
                  SetCapture();
                  CFrameWnd::OnLButtonDown(nFlags, point);
                  }

                  void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
                  {
                  // TODO: Add your message handler code here and/or call default
                  if(GetCapture()==this){
                  posX=point.x;
                  posY=point.y;
                  }
                  CFrameWnd::OnMouseMove(nFlags, point);
                  }

                  void CMainFrame::OnUpdateCursor(CCmdUI *pCmdUI){
                  CString pos;
                  pos.Format(ID_INDICATOR_CURSOR,posX,posY);
                  m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURSOR),pos);
                  }

                  Well atleast now the sting is updated with 0's. Its defined as " x: %d ,y: %d ". So the OnUpdateCursor() is working but not with the right values...

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  In OnMouseMove(), what is the value of point.x and point.y?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  V 1 Reply Last reply
                  0
                  • D David Crow

                    In OnMouseMove(), what is the value of point.x and point.y?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    V Offline
                    V Offline
                    Vladislav Gospodinov
                    wrote on last edited by
                    #10

                    I can't rly get the debuger to stop there ... It's kinda like skipping it all? Any other way of checking ?

                    D 1 Reply Last reply
                    0
                    • V Vladislav Gospodinov

                      Hello...This question may sound silly to some of you but I've been stuck on it for few days and can't find any answer... So I need to have the mouse position x and y displayed in the status bar. So far I add new string to the table, in the indicators array, afx_msg void OnUpdateCurPos(CCmdUI *pCmdUI) in the message map and ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSOR,OnUpdateCurPos) When I run it's there but can't find the right way to update the cords. I think it must work with ON_MOUSEMOVE func...I've tried several codes in ON_MOUSEMOVE and OnUpdateCurPos but it doesn't work at all... Working with SDI.

                      S Offline
                      S Offline
                      Software_Developer
                      wrote on last edited by
                      #11

                      Try this!

                      void CDlgStatusBarDlg::OnMouseMove(UINT nFlags, CPoint point)
                      {
                      CString s;
                      s.Format("X=%d Y=%d",point.x,point.y);
                      m_bar.SetPaneText(0,s);
                      CDialog::OnMouseMove(nFlags, point);
                      }

                      Source: [Adding a status bar to an MFC dialog[^]]

                      1 Reply Last reply
                      0
                      • V Vladislav Gospodinov

                        I can't rly get the debuger to stop there ... It's kinda like skipping it all? Any other way of checking ?

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        Vladislav Gospodinov wrote:

                        Any other way of checking ?

                        TRACE().

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        V 1 Reply Last reply
                        0
                        • D David Crow

                          Vladislav Gospodinov wrote:

                          Any other way of checking ?

                          TRACE().

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          V Offline
                          V Offline
                          Vladislav Gospodinov
                          wrote on last edited by
                          #13

                          So it doesn't TRACE() anything at all when called in

                          CMainFrame::OnMouseMove

                          so it's like it doesn't get the mouse moving at all in MainFrame class... it does trace correct values if I call it in the View class

                          CpositionView::OnMouseMove

                          however I can't find a way to send them from View to MainFrame, although I have included ***View.h and taka them like

                          CpositionView::positionX

                          I get a lot of errors :P

                          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