Code of the drag window without Borders in C ++

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.