Full Screen to Windowed - Window loses border and style

Started by
4 comments, last by Endurion 11 years, 8 months ago
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:

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


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

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


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?
Advertisement
Try this:

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


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

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


Try this:

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


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


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?
I think you might have to muck around with DwmSetWindowAttribute but it should be possible.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

You may be better off just closing that window and creating a new window after exiting full screen mode.
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 );

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement