Sign in to follow this  

Full Screen to Windowed - Window loses border and style

This topic is 1975 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

Hello all,

This is using Directx9 and C++, but since the problem is the window itself I'm posting in general. Also, I really did try searching for this, but everything I found was asking "how to get borderless windows" ><

Basically, I have the following sequence:

1. Game loads in a fixed window
2. I set the game to full screen and reset the d3d device
3. I change the resolution in full screen mode resetting the device again
4. I return to windowed mode resetting the device a final time

Resulting Problem: When returning to windowed mode with a new resolution, the border of the window is "gone". I can still select the border (i.e. clicking the top left will give me the default menu bar (restore, move, size, etc) and when I select it I briefly see it. Also, if I change the resolution a second time, the window re-appears, but it has become the windows default style (i.e. if my window bars are green, this one has reverted back to the default light blue with the default minimize, maximize and close icons).

This is my window:

[CODE]hWindow = CreateWindowEx(WS_EX_CLIENTEDGE,
className,
L"Shader Implementations",
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
SCREEN_WIDTH,
SCREEN_HEIGHT,
NULL,
NULL,
hInstance,
NULL);[/CODE]

When I exit full screen mode I only access the window with the following:

[CODE]if (d3dpp.Windowed == true)
{
RECT rect;
GetWindowRect(hWindow, &rect);
MoveWindow(hWindow, rect.left, rect.top, d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, false);
}[/CODE]

I have also tried it without this code (just to be sure).

If I return to windowed mode without changing the resolution it was set to when it went to full screen, it reverts without issue.

I am guessing there is something more I need to do with the window to make sure it retains the style and border when returning to windowed mode? Edited by Nexian

Share this post


Link to post
Share on other sites
Try this:

[code]RECT clientRect;
clientRect.left = 0;
clientRect.top = 0;
clientRect.right = d3dpp.BackBufferWidth;
clientRect.bottom = d3dpp.BackBufferHeight;
AdjustWindowRect(&clientRect, GetWindowLongPtr(hWindow, GWL_STYLE), FALSE);
MoveWindow(hWindow, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, false);[/code]

This will enlarge the window rectangle to include the border size.

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1345420410' post='4971271']
Try this:

[code]RECT clientRect;
clientRect.left = 0;
clientRect.top = 0;
clientRect.right = d3dpp.BackBufferWidth;
clientRect.bottom = d3dpp.BackBufferHeight;
AdjustWindowRect(&clientRect, GetWindowLongPtr(hWindow, GWL_STYLE), FALSE);
MoveWindow(hWindow, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom, false);[/code]

This will enlarge the window rectangle to include the border size.
[/quote]

I had to add 50 to the rectangle when returning at max resolution (border was above the top of the screen) but that seemed to do it very nicely, thank you!

Although it still loses the windows 7 border style. Is there anyway to get that back?

Share this post


Link to post
Share on other sites
I think you might have to muck around with [url=http://msdn.microsoft.com/en-us/library/windows/desktop/aa969524(v=vs.85).aspx]DwmSetWindowAttribute[/url] but it should be possible.

Share this post


Link to post
Share on other sites
You may be better off just closing that window and creating a new window after exiting full screen mode.

Share this post


Link to post
Share on other sites
D3D removes the border styles. You need to reapply them via SetWindowLong. You can store the wanted styles. Just make sure to also manually remove WS_EX_TOPMOST.

Before going fullscreen:
m_WindowedModeStyles = GetWindowLong( hwndViewport, GWL_STYLE );
m_WindowedModeExStyles = GetWindowLong( hwndViewport, GWL_EXSTYLE );
m_WindowedModeExStyles &= ~WS_EX_TOPMOST;

Returning to windowed mode:
SetWindowLong( hwndViewport, GWL_STYLE, m_WindowedModeStyles );
SetWindowLong( hwndViewport, GWL_EXSTYLE, m_WindowedModeExStyles );
SetWindowPos( hwndViewport, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED );

Share this post


Link to post
Share on other sites

This topic is 1975 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this