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();