Is SetCursorPos() Calling MouseMove ?
-
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
-
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
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
-
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
If you're drawing in
MouseMove
, why do you need to callSetCursorPos
. 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.
-
If you're drawing in
MouseMove
, why do you need to callSetCursorPos
. 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.
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
-
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
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. WhenSetCursorPos
is called, it does not normally callOnMouseMove
. But if the new cursor position as a result of callingSetCursorPos
is over the window for which theOnMouseMove
handler is created, then it will be invoked. If that is the case, you will need to set a flag before callingSetCursorPos
and then check this flag insideOnMouseMove
to distinguish between manually moving the mouse and callingSetCursorPos
. Remember to reset this flag insideOnMouseMove
.«_Superman_» _I love work. It gives me something to do between weekends.
-
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. WhenSetCursorPos
is called, it does not normally callOnMouseMove
. But if the new cursor position as a result of callingSetCursorPos
is over the window for which theOnMouseMove
handler is created, then it will be invoked. If that is the case, you will need to set a flag before callingSetCursorPos
and then check this flag insideOnMouseMove
to distinguish between manually moving the mouse and callingSetCursorPos
. Remember to reset this flag insideOnMouseMove
.«_Superman_» _I love work. It gives me something to do between weekends.
-
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. WhenSetCursorPos
is called, it does not normally callOnMouseMove
. But if the new cursor position as a result of callingSetCursorPos
is over the window for which theOnMouseMove
handler is created, then it will be invoked. If that is the case, you will need to set a flag before callingSetCursorPos
and then check this flag insideOnMouseMove
to distinguish between manually moving the mouse and callingSetCursorPos
. Remember to reset this flag insideOnMouseMove
.«_Superman_» _I love work. It gives me something to do between weekends.
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
-
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
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.
-
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.
-
Hello. I tried as u suggested but still Mouse is keep on Moving on my First move. Thanks Yogesh
Try to debug and find out what is happening.
«_Superman_» _I love work. It gives me something to do between weekends.
-
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
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
-
Try to debug and find out what is happening.
«_Superman_» _I love work. It gives me something to do between weekends.
-
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