How to move a form by non-client area

Source: Internet
Author: User

See a description of how to move a form in a non-customer area, both overloading wm_nchittest and returning htcaption. But I think there's something wrong with the right mouse button function. Here I introduce a method, you can already move the form in the client area and the right mouse button function.

1, a new project dlg. Use the default settings.

2. Add Message handler function:

void CDlgDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
  PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,pointy));
  CDialog::OnLButtonDown(nFlags, point);
}

3, add right key function. The right mouse button function has been implemented

void CDlgDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
  CMenu menu,*sub;
  menu.LoadMenu(IDR_MENU1);
  sub=menu.GetSubMenu(0);
  ClientToScreen(&point);
  sub->TrackPopupMenu(TPM_RIGHTBUTTON,point.x,point.y,this);
  CDialog::OnRButtonDown(nFlags, point);
}

See source code for other implementation details.

This article supporting source code

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.