Changing the window frame styles causes the window to disappear

Discussion in 'Win32' started by sethjackson, Aug 31, 2010.

  1. sethjackson

    sethjackson New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Ok so I have this function that will let you switch whether a window can be resized or not.


    Code:
    void Window::SetResizable(bool resizable)
    {
        DWORD dwStyles;
        
        if (resizable)
            dwStyles = WS_OVERLAPPEDWINDOW;
        
        else
            dwStyles = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX;
    
        SetWindowLongPtr(GetHandle(), GWL_STYLE, dwStyles);
        
        // When changing frame styles with SetWindowLong()/SetWindowLongPtr()
        // be sure to call SetWindowPos() with SWP_FRAMECHANGED
        // otherwise the non client area of the window won't be recalculated
        // until the window is sized.
        UINT uFlags = SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED;
        
        SetWindowPos(GetHandle(), // the window handle
                     HWND_TOP,    // the window to insert after
                     0,           // x
                     0,           // y
                     0,           // width
                     0,           // height
                     uFlags);     // flags
    } 
    
    Now this works great, with one minor flaw.
    If the window was visible *before* I call this function,
    the window disappears off the screen leaving behind artifacts on the screen.

    I hacked up a fix, but I want to know why this happens.

    Here is the fix:
    Code:
    bool wasVisible = IsVisible();

    all that other code
    ....

    if (wasVisible)
    Show();
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice