Thread: Changing the window frame styles causes the window to disappear

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    96

    Changing the window frame styles causes the window to disappear

    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();
    Last edited by sethjackson; 08-12-2010 at 04:44 PM.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by sethjackson View Post
    I hacked up a fix, but I want to know why this happens.
    The WS_VISIBLE bit isn't set in the new mask.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    96
    Quote Originally Posted by adeyblue View Post
    The WS_VISIBLE bit isn't set in the new mask.
    LOL I'm an idiot. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  2. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  3. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM