Home > Software engineering >  How to drag the image window
How to drag the image window

Time:11-20

MFC opened an image, how to use the mouse to drag the image?

CodePudding user response:

Response to a WM_MOUSEMOVE message, if the left key press, according to the drawing as the cursor position weight

CodePudding user response:

Graphics into the CStatic is:
 
Void CMyStatic: : onm ouseMove (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
The static CPoint ptLast;
//
If (MK_LBUTTON==nFlags)
{
CRect rc;
GetWindowRect (& amp; Rc);
The ScreenToClient (& amp; Rc);
MapWindowPoints (GetParent (), & amp; Rc);
MoveWindow (rc) left + point. X-ray ptLast. (x), rc. The top + point. Y - ptLast. (y), rc. The Width (), rc, Height ());
}
The else
{
PtLast=point;
CStatic: onm ouseMove (nFlags, point);
}
Invalidate ().
}

CodePudding user response:

refer to the second floor schlafenhamster response:
graphics into the CStatic is:
 
Void CMyStatic: : onm ouseMove (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
The static CPoint ptLast;
//
If (MK_LBUTTON==nFlags)
{
CRect rc;
GetWindowRect (& amp; Rc);
The ScreenToClient (& amp; Rc);
MapWindowPoints (GetParent (), & amp; Rc);
MoveWindow (rc) left + point. X-ray ptLast. (x), rc. The top + point. Y - ptLast. (y), rc. The Width (), rc, Height ());
}
The else
{
PtLast=point;
CStatic: onm ouseMove (nFlags, point);
}
Invalidate ().
}

Can I add some comments

CodePudding user response:

If (MK_LBUTTON==nFlags)
If the left key press
The else
{
PtLast=point; Save the current position
  • Related