resizing x and y evenly

This is a discussion on resizing x and y evenly within the Windows Programming forums, part of the Platform Specific Boards category; I'm using MFC and I have a multi view document with wizard generated child frames and docs and views. When ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    Smile resizing x and y evenly

    I'm using MFC and I have a multi view document with wizard generated child frames and docs and views. When a child frame appears, I would, when the user clicks on any of the sides of the window to try to resize the window, increase or decrease the x and y positions evenly. I would like the child frame to remain a square, and if the user tries to resize one side, have it remain a square and not turn into a rectangle. Does solving this have something to do with handling the ON_WM_SIZE message that is sent?

    Thank you.

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    when you get a WM_SIZE message try putting this in there....
    Code:
    x = LOWORD(lParam);
    y = HIWORD(lParam);
    if(x>y)
        y=x;
    else
        x=y;
    MoveWindow(hwnd,0,0,x,y,true);
    that should work...only problem is your window will jump to the point (0,0) before it resizes...

  3. #3
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    you can do the following (inspired by the previous poster's post)
    place the code in the WM_MOVE message

    RECT rc;

    GetScreenRect(hwnd,&rc)

    x = rc.right - rc.left;
    y = rc.bottom - rc.top
    if(x>y)
    y=x;
    else
    x=y;
    MoveWindow(hwnd,rc.top,rc.left,x,y,true);


    Good Luck

    Oskilian

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    still not working

    I appreciate both of your suggestions, but neither of them work for me when I try to implement them. Some weird stuff happens when I try to resize the window, and it doesn't work. This is the code I tried to implement:

    void CChildFrame::OnSize(UINT nType, int cx, int cy)
    {
    //CMDIChildWnd::OnSize(nType, cx, cy);

    CClientDC dc(this);
    CRect rc;
    GetClientRect(rc);
    rc.top+=20;

    int x = rc.right - rc.left;
    int y = rc.bottom - rc.top;
    if(x>y)
    y=x;
    else
    x=y;
    MoveWindow(rc.top,rc.left,x,y,true);
    }

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    you're not supplying the HWND of the window..

Popular pages Recent additions subscribe to a feed

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