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. Is SetCursorPos() Calling MouseMove ?

Is SetCursorPos() Calling MouseMove ?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionannouncement
13 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.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    Hello Friends OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe. But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up. I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop. But,In actual I want to stop mouse pos at end of stripe while mouseMove. Here is the Flow : 1.)LButtonDown 2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe] And again if Mousemove,strip should draw and cursor at end of Stripe. 3.)LbuttonUp[releasing the mouse] Any Ideas?? Regards Yogesh

    T _ L 3 Replies Last reply
    0
    • 0 002comp

      Hello Friends OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe. But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up. I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop. But,In actual I want to stop mouse pos at end of stripe while mouseMove. Here is the Flow : 1.)LButtonDown 2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe] And again if Mousemove,strip should draw and cursor at end of Stripe. 3.)LbuttonUp[releasing the mouse] Any Ideas?? Regards Yogesh

      T Offline
      T Offline
      TomasRiker2
      wrote on last edited by
      #2

      Just remember in a "global" variable that you have done the movement so that you can then ignore OnMouseOver the next time.

      Visit my project: Derivative Calculator

      1 Reply Last reply
      0
      • 0 002comp

        Hello Friends OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe. But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up. I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop. But,In actual I want to stop mouse pos at end of stripe while mouseMove. Here is the Flow : 1.)LButtonDown 2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe] And again if Mousemove,strip should draw and cursor at end of Stripe. 3.)LbuttonUp[releasing the mouse] Any Ideas?? Regards Yogesh

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        If you're drawing in MouseMove, why do you need to call SetCursorPos. Please post some relevant code so that we can understand the problem better.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        0 1 Reply Last reply
        0
        • _ _Superman_

          If you're drawing in MouseMove, why do you need to call SetCursorPos. Please post some relevant code so that we can understand the problem better.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          0 Offline
          0 Offline
          002comp
          wrote on last edited by
          #4

          Hello As I told that OnMouseMove I am drawin gsome color stripes on Ruler Scale . Suppose scale is from 1 to 10 and If i am clicked on 2 and moved a little then it draws stripe of 5inch width.after that i want cursor should come at 7th Inch. So,for that i used SetCursorpos to move mouse manually after end of drawn stripe. Any IDeas ? Regards Yogesh

          _ 1 Reply Last reply
          0
          • 0 002comp

            Hello As I told that OnMouseMove I am drawin gsome color stripes on Ruler Scale . Suppose scale is from 1 to 10 and If i am clicked on 2 and moved a little then it draws stripe of 5inch width.after that i want cursor should come at 7th Inch. So,for that i used SetCursorpos to move mouse manually after end of drawn stripe. Any IDeas ? Regards Yogesh

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            The question is not clear to me, but let me answer with what I think the question is. An OnMouseMove handler is called when the mouse is moved over a window. When SetCursorPos is called, it does not normally call OnMouseMove. But if the new cursor position as a result of calling SetCursorPos is over the window for which the OnMouseMove handler is created, then it will be invoked. If that is the case, you will need to set a flag before calling SetCursorPos and then check this flag inside OnMouseMove to distinguish between manually moving the mouse and calling SetCursorPos. Remember to reset this flag inside OnMouseMove.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            0 2 Replies Last reply
            0
            • _ _Superman_

              The question is not clear to me, but let me answer with what I think the question is. An OnMouseMove handler is called when the mouse is moved over a window. When SetCursorPos is called, it does not normally call OnMouseMove. But if the new cursor position as a result of calling SetCursorPos is over the window for which the OnMouseMove handler is created, then it will be invoked. If that is the case, you will need to set a flag before calling SetCursorPos and then check this flag inside OnMouseMove to distinguish between manually moving the mouse and calling SetCursorPos. Remember to reset this flag inside OnMouseMove.

              «_Superman_»  _I love work. It gives me something to do between weekends.

              _Microsoft MVP (Visual C++)

              Polymorphism in C

              0 Offline
              0 Offline
              002comp
              wrote on last edited by
              #6

              Hello you got it right. I am facing the same scenario. Let me try your way. Thanks & Regards Yogesh

              1 Reply Last reply
              0
              • _ _Superman_

                The question is not clear to me, but let me answer with what I think the question is. An OnMouseMove handler is called when the mouse is moved over a window. When SetCursorPos is called, it does not normally call OnMouseMove. But if the new cursor position as a result of calling SetCursorPos is over the window for which the OnMouseMove handler is created, then it will be invoked. If that is the case, you will need to set a flag before calling SetCursorPos and then check this flag inside OnMouseMove to distinguish between manually moving the mouse and calling SetCursorPos. Remember to reset this flag inside OnMouseMove.

                «_Superman_»  _I love work. It gives me something to do between weekends.

                _Microsoft MVP (Visual C++)

                Polymorphism in C

                0 Offline
                0 Offline
                002comp
                wrote on last edited by
                #7

                Hello As U suggested that I need to set a flag before calling setCursorPos to check on MouseMove. Suppose If this flag satisfies the condition on MouseMove that movement is through SeCursorPos then it will return from there and then how will i reset tht flag on MouseMove. Here is sample Code for this:

                void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
                {
                if(GetCapture() != this) return;

                //----Calling my own Code to Draw Stripe---//
                // Doing Some calculation to Find the Width---
                // and then setting Mouse Cursor Position---------

                SetCursorPos(x,y)

                CWnd::OnMouseMove(nFlags, point);
                }

                Thanks Yogesh

                _ 1 Reply Last reply
                0
                • 0 002comp

                  Hello As U suggested that I need to set a flag before calling setCursorPos to check on MouseMove. Suppose If this flag satisfies the condition on MouseMove that movement is through SeCursorPos then it will return from there and then how will i reset tht flag on MouseMove. Here is sample Code for this:

                  void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
                  {
                  if(GetCapture() != this) return;

                  //----Calling my own Code to Draw Stripe---//
                  // Doing Some calculation to Find the Width---
                  // and then setting Mouse Cursor Position---------

                  SetCursorPos(x,y)

                  CWnd::OnMouseMove(nFlags, point);
                  }

                  Thanks Yogesh

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  Please check the lines in bold. That should do it.

                  void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
                  {
                  if (mouseFlag)
                  {
                  mouseFlag = false;
                  return;
                  }

                  if(GetCapture() != this) return;

                  //----Calling my own Code to Draw Stripe---//
                  // Doing Some calculation to Find the Width---
                  // and then setting Mouse Cursor Position---------

                  mouseFlag = true;
                  SetCursorPos(x,y)

                  CWnd::OnMouseMove(nFlags, point);
                  }

                  «_Superman_»  _I love work. It gives me something to do between weekends.

                  _Microsoft MVP (Visual C++)

                  Polymorphism in C

                  0 1 Reply Last reply
                  0
                  • _ _Superman_

                    Please check the lines in bold. That should do it.

                    void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
                    {
                    if (mouseFlag)
                    {
                    mouseFlag = false;
                    return;
                    }

                    if(GetCapture() != this) return;

                    //----Calling my own Code to Draw Stripe---//
                    // Doing Some calculation to Find the Width---
                    // and then setting Mouse Cursor Position---------

                    mouseFlag = true;
                    SetCursorPos(x,y)

                    CWnd::OnMouseMove(nFlags, point);
                    }

                    «_Superman_»  _I love work. It gives me something to do between weekends.

                    _Microsoft MVP (Visual C++)

                    Polymorphism in C

                    0 Offline
                    0 Offline
                    002comp
                    wrote on last edited by
                    #9

                    Hello. I tried as u suggested but still Mouse is keep on Moving on my First move. Thanks Yogesh

                    _ 1 Reply Last reply
                    0
                    • 0 002comp

                      Hello. I tried as u suggested but still Mouse is keep on Moving on my First move. Thanks Yogesh

                      _ Offline
                      _ Offline
                      _Superman_
                      wrote on last edited by
                      #10

                      Try to debug and find out what is happening.

                      «_Superman_»  _I love work. It gives me something to do between weekends.

                      _Microsoft MVP (Visual C++)

                      Polymorphism in C

                      0 1 Reply Last reply
                      0
                      • 0 002comp

                        Hello Friends OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe. But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up. I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop. But,In actual I want to stop mouse pos at end of stripe while mouseMove. Here is the Flow : 1.)LButtonDown 2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe] And again if Mousemove,strip should draw and cursor at end of Stripe. 3.)LbuttonUp[releasing the mouse] Any Ideas?? Regards Yogesh

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Hi, Rather than using SetCursorPos you could use the SendInput function[^]. This would allow you to set some 'extra info' for marking simulated user input. For example:

                        BOOL setcursorposition(long x, long y)
                        {
                        INPUT input = {0};
                        input.type = INPUT_MOUSE;
                        input.mi.dx = ((x - GetSystemMetrics(SM_XVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CXVIRTUALSCREEN)-1);
                        input.mi.dy = ((y - GetSystemMetrics(SM_YVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CYVIRTUALSCREEN)-1);
                        input.mi.dwFlags = MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                        input.mi.dwExtraInfo = 0xC0DEDBAD;
                        return SendInput(1, &input, sizeof(input));
                        }

                        void YourClass::OnMouseMove(UINT nFlags, CPoint point)
                        {
                        if(0xC0DEDBAD != GetMessageExtraInfo())
                        {
                        //You would ignore the simulated input and do your processing here
                        }
                        YourBaseClass::OnMouseMove(nFlags, point);
                        }

                        Don't forget to convert client coordinates to screen before calling setcursorposition. Best Wishes, -David Delaune

                        J 1 Reply Last reply
                        0
                        • _ _Superman_

                          Try to debug and find out what is happening.

                          «_Superman_»  _I love work. It gives me something to do between weekends.

                          _Microsoft MVP (Visual C++)

                          Polymorphism in C

                          0 Offline
                          0 Offline
                          002comp
                          wrote on last edited by
                          #12

                          I got it. Its Working now. Thanks Sir ji. Thanks David For your Info also.I will try your way too. Regards Yogesh

                          1 Reply Last reply
                          0
                          • L Lost User

                            Hi, Rather than using SetCursorPos you could use the SendInput function[^]. This would allow you to set some 'extra info' for marking simulated user input. For example:

                            BOOL setcursorposition(long x, long y)
                            {
                            INPUT input = {0};
                            input.type = INPUT_MOUSE;
                            input.mi.dx = ((x - GetSystemMetrics(SM_XVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CXVIRTUALSCREEN)-1);
                            input.mi.dy = ((y - GetSystemMetrics(SM_YVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CYVIRTUALSCREEN)-1);
                            input.mi.dwFlags = MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                            input.mi.dwExtraInfo = 0xC0DEDBAD;
                            return SendInput(1, &input, sizeof(input));
                            }

                            void YourClass::OnMouseMove(UINT nFlags, CPoint point)
                            {
                            if(0xC0DEDBAD != GetMessageExtraInfo())
                            {
                            //You would ignore the simulated input and do your processing here
                            }
                            YourBaseClass::OnMouseMove(nFlags, point);
                            }

                            Don't forget to convert client coordinates to screen before calling setcursorposition. Best Wishes, -David Delaune

                            J Offline
                            J Offline
                            JohnCz
                            wrote on last edited by
                            #13

                            This is definitely the best approach. I wish I could rate your post.

                            JohnCz

                            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