15,979
社区成员
发帖
与我相关
我的任务
分享
void CMyFrameDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
switch(mMouseStates)
{
case HTLEFT:
case HTRIGHT:
::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
break;
case HTTOP:
case HTBOTTOM:
::SetCursor(LoadCursor(NULL, IDC_SIZENS));
break;
case HTTOPLEFT:
case HTBOTTOMRIGHT:
::SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
break;
case HTTOPRIGHT:
case HTBOTTOMLEFT:
::SetCursor(LoadCursor(NULL, IDC_SIZENESW));
break;
default:
::SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
}
if (mMouseStates == HTTOP)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTBOTTOM)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTLEFT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTRIGHT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTTOPLEFT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTBOTTOMRIGHT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTTOPRIGHT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
else if (mMouseStates == HTBOTTOMLEFT)
PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
else
{
CRect rect;
GetClientRect(&rect);
rect.bottom = FRAME_TOP_SIZE;
if(rect.PtInRect(point))
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
CDialog::OnLButtonDown(nFlags, point);
}
void CMyFrameDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(mEnableWindowSize && !IsZoomed())
{
CRect rect;
GetClientRect(&rect);
if (point.x <= rect.left + 5 && point.y <= rect.top + 5)
mMouseStates = HTTOPLEFT;
else if (point.x >= rect.right - 5 && point.y >= rect.bottom - 5)
mMouseStates = HTBOTTOMRIGHT;
else if (point.x >= rect.right - 5 && point.y <= rect.top + 5)
mMouseStates = HTTOPRIGHT;
else if (point.x <= rect.left + 5 && point.y >= rect.bottom - 5)
mMouseStates = HTBOTTOMLEFT;
else if (point.x <= rect.left + 5)
mMouseStates = HTLEFT;
else if (point.x >= rect.right - 5)
mMouseStates = HTRIGHT;
else if (point.y <= rect.top + 5)
mMouseStates = HTTOP;
else if (point.y >= rect.bottom - 5)
mMouseStates = HTBOTTOM;
else
mMouseStates = 0;
switch (mMouseStates)
{
case HTLEFT:
case HTRIGHT:
::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
break;
case HTTOP:
case HTBOTTOM:
::SetCursor(LoadCursor(NULL, IDC_SIZENS));
break;
case HTTOPLEFT:
case HTBOTTOMRIGHT:
::SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
break;
case HTTOPRIGHT:
case HTBOTTOMLEFT:
::SetCursor(LoadCursor(NULL, IDC_SIZENESW));
break;
default:
::SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CMyFrameDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
CDialog::OnSizing(fwSide, pRect);
if(mEnableWindowSize)
{
switch(fwSide)
{
case WMSZ_LEFT:
pRect->left = min(pRect->left, pRect->right - mSizeX);
break;
case WMSZ_RIGHT:
pRect->right = max(pRect->right, pRect->left + mSizeX);
break;
case WMSZ_TOP:
pRect->top = min(pRect->top, pRect->bottom - mSizeY);
break;
case WMSZ_BOTTOM:
pRect->bottom = max(pRect->bottom, pRect->top + mSizeY);
break;
case WMSZ_TOPLEFT:
pRect->left = min(pRect->left, pRect->right - mSizeX);
pRect->top = min(pRect->top, pRect->bottom - mSizeY);
break;
case WMSZ_BOTTOMRIGHT:
pRect->right = max(pRect->right, pRect->left + mSizeX);
pRect->bottom = max(pRect->bottom, pRect->top + mSizeY);
break;
case WMSZ_TOPRIGHT:
pRect->right = max(pRect->right, pRect->left + mSizeX);
pRect->top = min(pRect->top, pRect->bottom - mSizeY);
break;
case WMSZ_BOTTOMLEFT:
pRect->bottom = max(pRect->bottom, pRect->top + mSizeY);
pRect->left = min(pRect->left, pRect->right - mSizeX);
break;
default:
break;
}
}
// TODO: Add your message handler code here
}
mSizeX,mSizeY是窗口最大宽高
UINT CDemoDlg::OnNcHitTest(CPoint point)
{
CRect rect;
GetWindowRect(&rect);
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;
return CDialog::OnNcHitTest(point);
}