标签:
无边框窗体如何实现用鼠标拖动窗体边缘实现窗体大小变动呢?通过以下几个步骤即可实现:具体阐述如下:
1. 实现WM_NCHITTEST消息,实现四条边框的模拟,参考代码如下:
LRESULT CNoBorderWndChangeSizeDlg::OnNcHitTest(CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CRect rect; GetWindowRect(&rect); CRect rect1 = rect; rect1.DeflateRect(10, 10, -10, -10); rect1.NormalizeRect(); if (point.x <= rect.left+3) return HTLEFT; else if (point.x >= rect.right-3) return HTRIGHT; else if (point.y <= rect.top+3) return HTTOP; else if (point.y >= rect.bottom-3) return HTBOTTOM; else if (point.x <= rect.left+10 && point.y <= rect.top+10) return HTTOPLEFT; else if (point.x >= rect.right-10 && point.y <= rect.top+10) return HTTOPRIGHT; else if (point.x <= rect.left+10 && point.y >= rect.bottom-10) return HTBOTTOMLEFT; else if (point.x >= rect.right-10 && point.y >= rect.bottom-10) return HTBOTTOMRIGHT; else if (!rect.IsRectEmpty()) { LRESULT uRet = CWnd::OnNcHitTest(point); uRet = (uRet == HTCLIENT) ? HTCAPTION : uRet; return uRet; } else { return CWnd::OnNcHitTest(point); } return 0; }
void CNoBorderWndChangeSizeDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nHitTest == HTTOP) { SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y)); } else if (nHitTest == HTBOTTOM) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTLEFT) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTRIGHT) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTTOPLEFT) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTTOPRIGHT) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTBOTTOMLEFT) SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y)); else if (nHitTest == HTBOTTOMRIGHT) SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y)); else if (nHitTest==HTCAPTION) SendMessage(WM_SYSCOMMAND, SC_MOVE | 4, MAKELPARAM(point.x, point.y)); }
if(nHitTest == HTTOP) { SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0); SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y)); SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, FALSE, NULL, 0); }
标签:
原文地址:http://blog.csdn.net/jiangqin115/article/details/42102445