Resize frame

This is a discussion on Resize frame within the Windows Programming forums, part of the Platform Specific Boards category; I try to keep the same proportion when I resize frame. I handle WM_SIZE and WM_SIZEING, but something is wrong ...

  1. #1
    Eugene
    Guest

    Question Resize frame

    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.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    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.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Eugene
    Guest

    Question Doesn't work

    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?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421

    Lightbulb

    Dont call the "setwindowpos" function, all you have to do is change the members of the pRect structure.. like this:

    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;
          }
       }
    }
    I haven't compiled this... but it should give you the right idea.

    good luck!
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    Eugene
    Guest

    Thumbs up

    Thank you very much.
    It works perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Frame buffer not working
    By Noise in forum Game Programming
    Replies: 1
    Last Post: 02-15-2009, 12:05 PM
  2. Html frame question
    By Checker1977 in forum Tech Board
    Replies: 4
    Last Post: 11-06-2008, 07:43 AM
  3. png Image Resize
    By bhupesh.kec in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 07:52 AM
  4. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 05:37 AM
  5. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 12:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21