Archived

This topic is now archived and is closed to further replies.

Changing the styles of windows at runtime.

This topic is 5770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m just wondering if there is any way of changing the style of a window (ie: toggling the border on and off) without destroying the window and creating a new one...

Share this post


Link to post
Share on other sites
Ok, I figured out I have to use the "SetWindowLong()" function, but now it''s not redrawing the window properly afterward (only half redrawing the frame and doing nothing with the client area)...

Here''s what I''m doing:
  
if (fullscreen)
{
SetWindowLong(Window, GWL_STYLE, WS_POPUP);
SetWindowLong(Window, GWL_EXSTYLE, WS_EX_APPWINDOW);
SetWindowPos(Window, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
MoveWindow(Window, 0, 0, width, height, FALSE);
}
else
{
SetWindowLong(Window, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowLong(Window, GWL_EXSTYLE, WS_EX_WINDOWEDGE | WS_EX_APPWINDOW);
SetWindowPos(Window, 0, r.left, r.top, width, height, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
MoveWindow(Window, r.left, r.top, width + (GetSystemMetrics(SM_CXSIZEFRAME) * 2), height + (GetSystemMetrics(SM_CYSIZEFRAME) * 2) + GetSystemMetrics(SM_CYCAPTION), FALSE);
}

m_hDC = GetDC(Window);


I can''t figure out what''s up with it =/

Share this post


Link to post
Share on other sites
Probably something wrong with the dimensions. Start off by creating the window with a border, store those dims (GetWindowRect), and use them for reseting the window. That way you won't have to fuss with GetSystemMetrics. Toggling the border shouldn't effect the client area - just the non-client area. You'll have to compensate for the difference. Expand the size of the window so that the client takes up the area that once was taken up by the non-client as well.

Edited by - lessbread on February 22, 2002 8:04:37 AM

Share this post


Link to post
Share on other sites
The Windows Forms classes in the .NET Framework, which is built on top of Win32, actually recreates the windows if you try to set certain styles after creation.
So destroy/create might be the only solution in raw Win32.

The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)

Share this post


Link to post
Share on other sites
If you look in MSDN, it tells you that style changes at runtime aren''t updated right away. You have to follow the style change with:

  
SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);


to update the window and make the changes take effect.

Share this post


Link to post
Share on other sites