I try to keep the same proportion when I resize frame.
I handle WM_SIZE and WM_SIZEING, but something is wrong and I can't get desired result. Please give me any idea how to solve it.
Printable View
I try to keep the same proportion when I resize frame.
I handle WM_SIZE and WM_SIZEING, but something is wrong and I can't get desired result. Please give me any idea how to solve it.
This is pretty basic GUI geometry stuff... if you are handling the messages.. just make sure that you resize the frame using the right ratio.... quite simple.
if the frame size is in the proportion 4:3
then if the top or bottom is resized make sure that the width of the frame is 4/3 * height of the window
if the left or right side is resize.. the make the frame 3/4 the size of the width.
easy as that.
I need to keep perfect square (client area). So I wrote message handler. While I dragging a border, I have a square, but frame itselve moving a bit. When I release mouse button, frame agane change possition.
void CChildFrame::OnSizing(UINT fwSide, LPRECT pRect)
{
CMDIChildWnd::OnSizing(fwSide, pRect);
int borderX = ::GetSystemMetrics(SM_CXEDGE);
int borderY = ::GetSystemMetrics(SM_CYEDGE);
int caption = ::GetSystemMetrics(SM_CYCAPTION);
if(fwSide == WMSZ_RIGHT ||
fwSide == WMSZ_LEFT ||
fwSide == WMSZ_BOTTOMRIGHT ||
fwSide == WMSZ_TOPLEFT)
{
int cy = pRect->right - pRect->left - 2 * borderX + borderY + caption;
SetWindowPos( &wndTop,
pRect->left,
pRect->top,
pRect->right - pRect->left,
cy,
SWP_NOOWNERZORDER);
}
else if(fwSide == WMSZ_TOP ||
fwSide == WMSZ_BOTTOM ||
fwSide == WMSZ_BOTTOMLEFT ||
fwSide == WMSZ_TOPRIGHT)
{
int cx = pRect->bottom - pRect->top + 2 * borderX - borderY - caption;
SetWindowPos( &wndTop,
pRect->left,
pRect->top,
cx,
pRect->bottom - pRect->right,
SWP_NOOWNERZORDER);
}
}
What am I doing wrong?
Dont call the "setwindowpos" function, all you have to do is change the members of the pRect structure.. like this:
I haven't compiled this... but it should give you the right idea.Code:void CChildFrame::OnSizing(UINT fwSide, LPRECT pRect)
{
CMDIChildWnd::OnSizing(fwSide, pRect);
int borderX = ::GetSystemMetrics(SM_CXEDGE);
int borderY = ::GetSystemMetrics(SM_CYEDGE);
int caption = ::GetSystemMetrics(SM_CYCAPTION);
int currentWidth = pRect->right - pRect->left - borderX * 2;
int currentHeight = pRect->bottom - pRect->top - borderY * 2 - caption;
switch(fwSide)
{
case WMSZ_RIGHT:
{
// make sure that the bottom of the window changes size
pRect->bottom = pRect->top + currentWidth + borderY * 2 + caption;
break;
}
case WMSZ_TOP:
case WMSZ_BOTTOM:
case WMSZ_TOPRIGHT:
case WMSZ_BOTTOMRIGHT:
{
// make sure that the right side of the window changes size
pRect->right = pRect->left + currentHeight + borderX * 2;
break;
}
case WMSZ_left:
{
// make sure that the bottom of the window changes size
pRect->bottom = pRect->top + currentWidth + borderY * 2 + caption;
break;
}
case WMSZ_TOPLEFT:
case WMSZ_BOTTOMLEFT:
{
// make sure that the right side of the window changes size
pRect->left = pRect->right - currentHeight - borderX * 2;
break;
}
}
}
good luck!
U.
Thank you very much.
It works perfect.