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