discrete cursor

Hi !!!
I need to write a cursor (default ?), which moves only on specified grid
(i.e discrete mouse move I guess).
How should I implement it ?
Is there are any examples around ?

Thanks.
mab11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DeckmeisterCommented:
Hi,

I don't really understand what you
want to do.

The cursor's position on the screen
is discrete.
For instance, if you overload the
function OnMouseMove(), you will
see that there is a parameter of type
CPoint that is discrete.
0
migelCommented:
Hi!
you can handle OnMouseMove
catch cursor pos, align point to the desired position and call SetCursorPos
for example:
void CMyWnd::OnMouseMove(UINT uFlags, CPoint ptMouse)
{
POINT pt
::GetCursorPos(&pt);
ScreenToClient(&pt);
// snap to grid:
pt.x = (int)(xGridStep*floor((float)pt.x/xGridStep+0.5));
pt.y = (int)(yGridStep*floor((float)pt.y/yGridStep+0.5));
SetCursorPos(pt.x, pt.y);
}
0
migelCommented:
oops add
ClientToScreen(&pt);
before SetCursorPos...
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

mab11Author Commented:
I tried writing OnMouseMove, but I am getting very strange behaivior on the cursor part, it is dragging around a position and it's very hard to change it's postion.

Is there a way that I can leave default cursor alone and add one more which jumps on grid ?


0
DeckmeisterCommented:
Two cursors ???

Well, you can overload OnMouseMove()
for a specific control and leave it
as it is for the other controls
(including the main window).
0
mab11Author Commented:
I wrote overloading of mousemove with setcursorpos() , but somehow it's very difficult to move between neighbouring points, if I try to change position a little bit
it keepes dragging around current one, even though I made significant change with my hand.
Anybody knows why this is hapenning ?

Thanks
0
mab11Author Commented:
Precisly after I do SetCursorPos and check next mouse coordinates in WM_MOUSEMOVE - it stops being continious.
I think SetCursorPos influences it.
Anyway around this problem, i.e.
mouse coordinates in lParam being continiuos but Cursor positions not ?










0
migelCommented:
hm
may by storing previous cursor position and calculating offset SUM will be help
for example:
OnMouseMove()
{
POINT pt
// POINT m_ptCurrPos = member of the class
// SIZE m_szOffset = current offset;

::GetCursorPos(&pt);
ScreenToClient(&pt);

m_szOffset.cx += pt.x - m_ptCurrPos.x;
m_szOffset.cy += pt.y - m_ptCurrPos.y;
m_ptCurrPos.y +=m_szOffset.cy;
m_ptCurrPos.x +=m_szOffset.cx;

if (abs(m_szOffset.cx) > xGridStep)
m_szOffset.cx = 0
if (abs(m_szOffset.cy) > yGridStep)
m_szOffset.cy = 0

// snap to grid:
m_ptCurrPos.x = (int)(xGridStep*floor((float)m_ptCurrPos.x/xGridStep+0.5));
m_ptCurrPos.y = (int)(yGridStep*floor((float)m_ptCurrPos.y/yGridStep+0.5));
SetCursorPos(m_ptCurrPos.x, m_ptCurrPos.y);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mab11Author Commented:
Unfoirtunately it doesn't resolve mouse coordinates problem.
As soon as I introduce SetCursorPos,
what happenes is that mouse coordinates I am priniting are all at that cursor pos even though I am moving mouse.
In the description of SetCursorPos it doesn't say anything about mouse.
Any ideas ?

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.