Re: ClipCursor trouble after window is resized

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is fuller version of my code. I very much appreciate assistance!


// a class gets the client coordinates of a sprite rectangle
// and then passes its centerpoint to SetMoveToward
// as the destination for the cursor demo

m_pCurrentSprite = pSourceSprite;
CRect rect;
pSourceSprite->GetRect(&rect);
m_pView->SetMoveCursorToward(rect.CenterPoint() );

// set up to move cursor toward a point
void CTestView::SetMoveCursorToward(CPoint point)
{
m_ptMoveCursorToward.x = point.x;
m_ptMoveCursorToward.y = point.y;

// ::GetCursorPos(&m_ptMoveCursorFrom);
// ClientToScreen(&m_ptMoveCursorFrom);
// SetCursorPos(m_ptMoveCursorFrom.x,m_ptMoveCursorFrom.y);

m_bCursorCouldBeMovingToward = true;
m_nMoveCursorTowardCounter = 0;
SetTimer(Timer_MoveCursorToward,0,NULL);
}

// move cursor toward a point
void CTestView::MoveCursorToward()
{
CPoint point;
::GetCursorPos(&point);

m_nMoveCursorTowardCounter++;
m_nMoveCursorTowardDivisor = 40;
int nDivisor = m_nMoveCursorTowardDivisor;

CPoint ptMoveTo;
int nTotalDistanceX = abs( m_ptMoveCursorToward.x - m_ptMoveCursorFrom.x);
int nTotalDistanceY = abs( m_ptMoveCursorToward.y - m_ptMoveCursorFrom.y);
float fLegX = (float)nTotalDistanceX / nDivisor;
// get the integer portion of leg
int nLegXInteger = fLegX;
// get the decimal portion of leg
float fLegXRemainder = fLegX - nLegXInteger;
// now get the cumulative integer and decimal distance
// according to the number of moves thus far
int nCumulativeMoveDistanceX = (nLegXInteger + fLegXRemainder) *
m_nMoveCursorTowardCounter;
if(point.x < m_ptMoveCursorToward.x)
if(m_ptMoveCursorFrom.x + nCumulativeMoveDistanceX <
m_ptMoveCursorToward.x)
ptMoveTo.x = m_ptMoveCursorFrom.x + nCumulativeMoveDistanceX;
else
ptMoveTo.x = m_ptMoveCursorToward.x;

else
if(m_ptMoveCursorFrom.x - nCumulativeMoveDistanceX >
m_ptMoveCursorToward.x)
ptMoveTo.x = m_ptMoveCursorFrom.x - nCumulativeMoveDistanceX;
else
ptMoveTo.x = m_ptMoveCursorToward.x;

float fLegY = (float)nTotalDistanceY / nDivisor;
// get the integer portion of leg
int nLegYInteger = fLegY;
// get the decimal portion of leg
float fLegYRemainder = fLegY - nLegYInteger;
// now get the cumulative integer and decimal distance
// according to the number of moves thus far
int nCumulativeMoveDistanceY = (nLegYInteger + fLegYRemainder) *
m_nMoveCursorTowardCounter;

if(point.y < m_ptMoveCursorToward.y)
if(m_ptMoveCursorFrom.y + nCumulativeMoveDistanceY <
m_ptMoveCursorToward.y)
ptMoveTo.y = m_ptMoveCursorFrom.y + nCumulativeMoveDistanceY;
else
ptMoveTo.y = m_ptMoveCursorToward.y;

else
if(m_ptMoveCursorFrom.y - nCumulativeMoveDistanceY >
m_ptMoveCursorToward.y)
ptMoveTo.y = m_ptMoveCursorFrom.y - nCumulativeMoveDistanceY;
else
ptMoveTo.y = m_ptMoveCursorToward.y;

::SetCursorPos(ptMoveTo.x, ptMoveTo.y);
CRect rectCursor(ptMoveTo.x, ptMoveTo.y, ptMoveTo.x + 1, ptMoveTo.y + 1);
ClipCursorTo(&rectCursor);

////////////////////////////////////
// if cursor has arrived, kill timer
////////////////////////////////////
if(point.x == m_ptMoveCursorToward.x && point.y == m_ptMoveCursorToward.y)
{
KillTimer(Timer_MoveCursorToward);

m_bCursorHasDemoed = true;
}
}
----------------------
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:a5nvl2l09pq5tn3cbnkk26epki51l7hgjj@xxxxxxxxxx
Not enough information here. Is CPoint in screen or client coordinates?
On Sat, 18 Nov 2006 19:54:06 -0500, "Steve Russell"
<srussell@xxxxxxxxxxxxxxxxxxxxxx>
wrote:

Thanks, Joe. Here is where I think the trouble first shows up. I have
spent all day trying to understand and solve it, including various uses of
ScreenToClient etc that I have read in various literature, particularly
after your comments.

void CTestView::SetMoveCursorToward(CPoint point)
{
m_ptMoveCursorToward.x = point.x;
m_ptMoveCursorToward.y = point.y;
****
What's wrong with writing
m_ptMoveCursorToward = point;
?
I don't see the role this plays. A spec of expected behavior would help.
How is 'point'
computed, and what relationship does it have to the current cursor
position? And since I
don't actually see a SetClipCursor call anywhere here, it is hard to guess
what is
intended.
****

::GetCursorPos(&m_ptMoveCursorFrom);
m_bCursorCouldBeMovingToward = true;
m_nMoveCursorTowardCounter = 0;
SetTimer(Timer_MoveCursorToward,0,NULL);
*****
Since the role of these variables is not defined, and the role of the
timer is not
specified, and the timer handler code is not shownt is hard to guess what
any of this code
is attempting to do.
****
}
--------
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:id3vl2pjg1eeed3o670fvk20il8ma03u05@xxxxxxxxxx
Show the code. Note that you must use screen coordinates, which means
you
must recompute
the cursor position any time the window is moved or resized.
joe
On Sat, 18 Nov 2006 17:03:47 -0500, "Steve Russell"
<srussell@xxxxxxxxxxxxxxxxxxxxxx>
wrote:

I should add that in the resized window, when I run a test with
GetCursorPos
and then create a small color filled rectangle centered on those
coordinates, the rectangle is accurate, but my cursor is in a different
position. The smaller the window, the greater the divergence.
-------------
"Steve Russell" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23%231Ujo1CHHA.4928@xxxxxxxxxxxxxxxxxxxxxxx
I am unable to use ClipCursor accurately when I resize my window.
Maximized is the only state in which I get perfect results. Is there
something I should know about the relationship between ClipCursor and
resizing a window?


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


.



Relevant Pages

  • Re: ClipCursor trouble after window is resized
    ... it appears that the cursor is now moving perfectly in the resized window. ... // get the decimal portion of leg ... if(m_ptMoveCursorFrom.x + nCumulativeMoveDistanceX < ...
    (microsoft.public.vc.mfc)
  • Re: ClipCursor trouble
    ... The point is based on client coordinates of a sprite's rectangle. ... abbreviated because the related chunks are quite intricate with ... The cursor is clipped at every point ... but when I resize the window, the cursor parallels the path at a distance. ...
    (microsoft.public.vc.mfc)
  • Re: Edit Text in Buttons
    ... that to a script, FM does not let me change the text anymore. ... I-beam cursor over the button, not a hand cursor, and it will be difficult ... FileMaker's "buttons" are really only a rectangle object with a text ...
    (comp.databases.filemaker)
  • Re: Constraining mousepointer movement
    ... so that the cursor is ... Andy Ellis ... > Static bToggle As Boolean ... >> height of the rectangle, ...
    (microsoft.public.vb.general.discussion)
  • Re: Cursors - Resize columns
    ... Copy the rectangle under which I will draw the ... I also want to draw a vertical line from the cursor ... >> know I can draw a vertical line on the graphics object for the control but ...
    (microsoft.public.dotnet.languages.vb)