When you press the mouse, record the coordinates of the mouse on the form, and use a BOOL variable to record the status of the left mouse button.
If the left button pops up, the Boolean variable in the record state is FALSE.
Process the mouse movement event. If the left button is pressed at the same time, drag the form and set the coordinates of the new upper left corner of the form.
View plaincopy to clipboardprint?
··· · 50 ······· · 90 ····· · 140 · 15001. void CNoBorderFormDlg: OnMouseMove (UINT nFlags, CPoint point)
{
// TODO: add the message processing program code and/or call the default value here
CDialog: OnMouseMove (nFlags, point );
If (this-> _ leftButtonDown)
{
/// When you press the left mouse button, you can drag the form
CPoint pointChanged = point-(this-> _ mousePoint );
RECT rect;
This-> GetWindowRect (& rect );
This-> SetWindowPos (NULL, rect. left pointChanged. x, rect. top pointChanged. y, 0, 0, SWP_NOSIZE );
}
}
Void CNoBorderFormDlg: OnLButtonDown (UINT nFlags, CPoint point)
{
// TODO: add the message processing program code and/or call the default value here
CDialog: OnLButtonDown (nFlags, point );
This-> _ leftButtonDown = TRUE;
This-> _ mousePoint = CPoint (point );
}
Void CNoBorderFormDlg: OnLButtonUp (UINT nFlags, CPoint point)
{
// TODO: add the message processing program code and/or call the default value here
CDialog: OnLButtonUp (nFlags, point );
This-> _ leftButtonDown = FALSE;
}
Void CNoBorderFormDlg: OnMouseLeave ()
{
// TODO: add the message processing program code and/or call the default value here
CDialog: OnMouseLeave ();
This-> _ leftButtonDown = FALSE;
}