Use the mouse to change the size of the dialog box with the border attribute set to none (MFC)

Source: Internet
Author: User

Original Author copyright statement: During reprinting, please mark the original source and author information of the article as hyperlinks and this statement

Http://keegoo.blogbus.com/logs/31246850.html

 

When writing a dialog box-based program, you like to set the border attribute to none, so that the entire dialog box does not look like anything (no edges or non-customer zones ), in this way, you can use some nice pictures to draw non-customer areas and dialog box edges. But the only unpleasant thing is that the dialog box cannot move with the mouse or change the size with the mouse. The following methods implement these functions:

Add the m_nhittest variable to the dialog box class,

 

1. Add the wm_mousemove message processing function and add the following code to the processing function:

Crect rect;
Getclientrect (& rect );
If (point. x <= rect. Left + 3)
{
Setcursor (loadcursor (null, makeintresource (idc_sizewe )));
M_nhittest = htleft;
}
Else if (point. x> = rect. Right-3)
{
Setcursor (loadcursor (null, makeintresource (idc_sizewe )));
M_nhittest = htright;
}
Else if (point. Y <= rect. Top + 3)
{
Setcursor (loadcursor (null, makeintresource (idc_sizens )));
M_nhittest = httop;
}
Else if (point. Y> = rect. Bottom-3)
{
Setcursor (loadcursor (null, makeintresource (idc_sizens )));
M_nhittest = htbottom;
}
Else if (point. x <= rect. Left + 10 & point. Y <= rect. Top + 10)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenwse )));
M_nhittest = httopleft;
}
Else if (point. x> = rect. Right-10 & point. Y <= rect. Top + 10)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenesw )));
M_nhittest = httopright;
}
Else if (point. x <= rect. Left + 10 & point. Y> = rect. Bottom-10)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenesw )));
M_nhittest = htbottomleft;
}
Else if (point. x> = rect. Right-10 & point. Y> = rect. Bottom-10)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenwse )));
M_nhittest = htbottomright;
}
Else
{
Setcursor (loadcursor (null, makeintresource (idc_arrow )));
M_nhittest = 0;
}

 

2. Add the wm_lbuttondown message processing function and add the following code to the processing function:

 

If (m_nhittest = httop)
{
Setcursor (loadcursor (null, makeintresource (idc_sizens )));
Sendmessage (wm_syscommand, SC _size | wmsz_top, makelparam (point. X, point. y ));
}
Else if (m_nhittest = htbottom)
{
Setcursor (loadcursor (null, makeintresource (idc_sizens )));
Sendmessage (wm_syscommand, SC _size | wmsz_bottom, makelparam (point. X, point. y ));
}
Else if (m_nhittest = htleft)
{
Setcursor (loadcursor (null, makeintresource (idc_sizewe )));
Sendmessage (wm_syscommand, SC _size | wmsz_left, makelparam (point. X, point. y ));
}
Else if (m_nhittest = htright)
{
Setcursor (loadcursor (null, makeintresource (idc_sizewe )));
Sendmessage (wm_syscommand, SC _size | wmsz_right, makelparam (point. X, point. y ));
}
Else if (m_nhittest = httopleft)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenwse )));
Sendmessage (wm_syscommand, SC _size | wmsz_topleft, makelparam (point. X, point. y ));
}
Else if (m_nhittest = httopright)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenesw )));
Sendmessage (wm_syscommand, SC _size | wmsz_topright, makelparam (point. X, point. y ));
}
Else if (m_nhittest = htbottomleft)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenesw )));
Sendmessage (wm_syscommand, SC _size | wmsz_bottomleft, makelparam (point. X, point. y ));
}
Else if (m_nhittest = htbottomright)
{
Setcursor (loadcursor (null, makeintresource (idc_sizenwse )));
Sendmessage (wm_syscommand, SC _size | wmsz_bottomright, makelparam (point. X, point. y ));
}
Else
{

// The implementation dialog box follows the mouse

: Sendmessage (getsafehwnd (), wm_syscommand, SC _move + htcaption, 0 );
}

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.