What is going on there?
Have a look to the function
void CPictureBox::OnLButtonDown
{
//flag to indicate that the mouse is down
m_Tracking = TRUE;
//tells Windows to send mouse messages to this window even if the mouse is leaving the window
SetCapture();
//defines the starting point of the rectangle
m_Rect.right = m_Rect.left = point.x;
m_Rect.bottom = m_Rect.top = point.y;
//tells windows that this window has to be redrawn
Invalidate();
//informs the base class that the button was pressed
CStatic::OnLButtonDown(nFl
}
The next function is when the mouse is moved now:
void CPictureBox::OnMouseMove(U
{
//checkes if mouse is currently down
if (m_Tracking)
{
// in mouse down the rectangle was set with left/top and right/bottom corner to the same point.
//now the right/bottom corner is moved to an other location depending on the mouse position
m_Rect.right = point.x;
m_Rect.bottom = point.y;
//tells windows that this window has to be redrawn
Invalidate();
}
//informs the base class that the mouse was moved
CStatic::OnMouseMove(nFlag
}
now what shall happen if the user releases the button?
well the traking flag should be set to false to indicate that.
And because the User might be done with the window he may want to click into an other window and expect that this window will react on this click. So it would be a great idea to disable that all mouse events are sent to the current window even if the mous is outside of the window
and that is what should be done in Mouse Up event
...:OnLButtonUp(...)
{
m_Tracking=FALSE;
ReleaseCapture();
BaseClass::OnLButtonUp(...
}
is the default behaviour for such cases
Main Topics
Browse All Topics





by: AlexFMPosted on 2007-06-12 at 00:15:36ID: 19264137
Check out MFC sample DRAWCLI - it contains full solution for drawing various objects.
If you need only rectangle, see CRectTracker class and TRACKER MFC sample.