Saturday, February 21, 2009

How do I constrain window resizing to always be square?

You need to handle the WM_SIZING message. Here's some sample code in MFC style :

void CMyDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
CDialog::OnSizing(fwSide, pRect);

int iWidth = (pRect->right)-(pRect->left);
int iHeight = (pRect->bottom)-(pRect->top);

if (iWidth > iHeight)
{
pRect->bottom = pRect->top + iWidth;
}
else
{
if (iHeight > iWidth)
{
pRect->right = pRect->left + iHeight;
}
}
}

Author : Bob Moore

0 nhận xét:

Post a Comment