• Advertisement
Sign in to follow this  

Problem when switching from fullscreen to windowed

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

When I reset my device from fullscreen to windowed mode, it seems as though the clipping region is not set properly. The backbuffer fills the entire window, including the title bar. However, when I minimize and then maximize the window, the backbuffer seems to become clipped properly and resizes itself so that it no longer draws over the title bar. Anyone know how I can force the backbuffer to fit properly in the window without doing the minimize/maximize?

Share this post


Link to post
Share on other sites
Advertisement
Try calling MoveWindow() after you switch to windowed mode. I had a lot of trouble with the same problem. There's a trick to getting it to work properly, but I can't remember what it was.

Share this post


Link to post
Share on other sites
Thanks, the MoveWindow() trick works :) But, I'd really like to know why it works (ie, what exactly is going on behind the scenes).

I've tried to invalidate the window by calling RedrawWindow() with various parameters to force a WM_NCPAINT call, but it doesnt seem to help.

Anyone know why MoveWindow() and minimize/maximize work, and what the problem is here?

[Edited by - kosmon_x on May 31, 2005 3:09:54 AM]

Share this post


Link to post
Share on other sites
I beleive it's a problem with Direct3D, or the communication between Direct3D and windows components. Direct3D seems to be calculating the size of your window before it realizes the window has a title bar and borders.

Since you are switching to window mode from full-screen, there's no harm in setting the position of the window after the fact. But I would also be interested in knowing why it needs done.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
Are you re-applying the border and caption styles before you reset the device for windowed mode?

I'm not sure I follow you. Why would you need to mess with the window styles? You can enter fullscreen mode with captioned windows.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
Yes, but your mouse will change if the cursor is on the border or the caption, allowing you to even move the window.

Is this true? When I switch to fullscreen in my application, the captions and borders are gone. I don't use a hardware cursor within fullscreen, but I've never had any problem like this.

Well, in any case, I guess that's not the problem. I don't even remove the title bar in my engine. I doubt MoveWindow() would put it back on if I did.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
Yes, but your mouse will change if the cursor is on the border or the caption, allowing you to even move the window.


Ah I just noticed that. That is a problem...
How do I get rid of the caption style before I switch into fullscreen and reapply it when I get out? Anyone know what the win32 call is?

Share this post


Link to post
Share on other sites
I don't think you can modify it:
Quote:

The following styles can be specified wherever a window style is required.
After the control has been created, these styles cannot be modified, except as noted.

...
WS_CAPTION - Creates a window that has a title bar (includes the WS_BORDER style).
...


I don't see any note, do you? But it's hard to be sure with MS.

Share this post


Link to post
Share on other sites
Quote:
styles can be changed using SetWindowLong.


The documentation mentions that one must call SetWindowPos() before certain styles are updated and displayed properly. Sound familur?

Share this post


Link to post
Share on other sites
The problem is that when you changle your display mode you probabaly change the screen resolutions. If you place your window and set your clipping variables then changle the resolution your stuff is no longer good. you need all your window placing, finding etc... after you have switched display modes.

Share this post


Link to post
Share on other sites
Quote:
Original post by robert_p
The problem is that when you changle your display mode you probabaly change the screen resolutions. If you place your window and set your clipping variables then changle the resolution your stuff is no longer good. you need all your window placing, finding etc... after you have switched display modes.

It doesn't have anything to do with changing the resolution. Just switching from full-screen to window mode.
The back buffers need resized, though.

Share this post


Link to post
Share on other sites
Ok, so just to make sure I understand everything:

- First I fill out my new present parameters for fullscreen mode.
- Then I reset the device with the new paramters.
- Then I call SetWindowLong() to change the window flags to what exactly?
- And then I call SetWindowPos() so that it shows up correctly?

And do the reverse for going from fullscreen to windowed mode? Is this right? :)

Share this post


Link to post
Share on other sites
You want your window set before you re init direct3d or else you will continue to get the same problem you have.

I have worked out a multi-threaded approach at easily allowing the switch between fullscreen to windowed with heavy containers to restore any lost objects.


Here are some functions which I have wrapped up in a window class but allow a quick switch between the modes. Although be advised, I tested this at a minimum and did little research as to the effects of disabling to many styles, maybe someone on these forums will provide a little insight.

/*
Sets up a window to immediatly handle fullscreen
Modified: April 3, 2005 -- 11:13 -- Steve Damm
*/
void cGameWindowFrame::Set_styleFullScreen()
{
DWORD dwstyle = Get_Windowstyle();
DWORD dwRemove = WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_OVERLAPPED |
WS_CHILD | WS_VSCROLL |
WS_HSCROLL | WS_GROUP | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN;
//DWORD dwAdd = WS_VISIBLE | WS_POPUP | WS_MINIMIZE | WS_MAXIMIZE;
DWORD dwAdd = WS_VISIBLE;
DWORD dwNew = (dwstyle & (~dwRemove)) | dwAdd;

Set_Windowstyle(dwNew);
}


/*
Sets up a window to immediatly handle windowed
Modified: April 3, 2005 -- 11:13 -- Steve Damm
*/
void cGameWindowFrame::Set_styleWindowed()
{
DWORD dwstyle = Get_Windowstyle();
DWORD dwRemove = WS_CHILD | WS_DISABLED | WS_VSCROLL |
WS_HSCROLL | WS_GROUP;
DWORD dwAdd = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
DWORD dwNew = (dwstyle & (~dwRemove)) | dwAdd;

Set_Windowstyle(dwNew);
}


/*
Returns the window style for easy modification
Modified: April 1, 2005 -- 00:13 -- Steve Damm
*/
DWORD cGameWindowFrame::Get_Windowstyle()
{
return static_cast<DWORD>(GetWindowLongPtr(m_hwnd, GWL_style));
}


/*
Sets the window long, must start as the long returned from Get_Windowstyle()
Modified: April 1, 2005 -- 00:13 -- Steve Damm
*/
void cGameWindowFrame::Set_Windowstyle(DWORD dwstyle)
{
SetWindowLongPtr(m_hwnd, GWL_style, dwstyle);
SetWindowPos(m_hwnd, NULL, m_rWindow.left, m_rWindow.top, m_rWindow.right, m_rWindow.bottom,
SWP_NOZORDER | SWP_FRAMECHANGED); //Update our window
UpdateWindow(m_hwnd);
}




Edit: btw, after the switch from windowed-full-windowed, the window will remain topmost for some reason...

Share this post


Link to post
Share on other sites
Hey thanks for the detailed response. I tried that out and it worked great. I fiddled around with some of the parameters and got it so that the window would no longer be topmost, but now my window is inactive by default when the program starts >:( Oh well, I guess it just takes alot of tweaking...

Is this how everyone else sets up their windows, or are there other solutions?

Share this post


Link to post
Share on other sites
That's pretty much the way i do it. Additionally, when switching from windowed to fullscreen i call GetWindowPlacement.
This gives you a struct detailing the windows position, state (minimized, maximized, restored).
On switching back to windowed mode i reset the window with SetWindowPlacement. This restores all windows size states, so you can maximize/restore the window as it was before.

Share this post


Link to post
Share on other sites
Quote:
Original post by kosmon_x
.. but now my window is inactive by default when the program starts >:(

You might want to look at SetFocus().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement