Fullscreen-to-windowed mode problems

Started by
4 comments, last by Syranide 18 years, 9 months ago
I am able to switch from windowed to fullscreen mode just fine, but im having some problems switching from fullscreen back to windowed mode. The problem is that it looks like it does the switch successfully, but the window somehow turns to POPUP like window with no borders and titlebar. The size is also left of the fullscreen resolution size and not of HWND size. I also use the same HWND.

// Here is how im making the switch to fullscreen:

D3DPresentParameters.Windowed = FALSE; // Fullscreen mode
D3DPresentParameters.BackBufferWidth = 800;
D3DPresentParameters.BackBufferHeight = 600;
D3DPresentParameters.BackBufferFormat = D3DFMT_A8R8G8B8;
D3DPresentParameters.FullScreen_RefreshRateInHz = 100;
D3DPresentParameters.hDeviceWindow = hWnd;
// Reset() call

// And back to windowed mode:

D3DPresentParameters.Windowed = TRUE;
D3DPresentParameters.FullScreen_RefreshRateInHz = 0;
D3DPresentParameters.BackBufferWidth = 0;
D3DPresentParameters.BackBufferHeight = 0;
D3DPresentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
D3DPresentParameters.hDeviceWindow = hWnd;
// Reset() call

Im also sure that Reset() calls succeed, because the Present() keeps rendering everything to the screen. Anyone ever must have had the same problem? Any suggestions? Im also having hard time with debugging this stuff because i have to do that in fullscreen which as i found is a pain in the ass.
Advertisement
This problem seems to be very common right now. Count you, me, and one other person 3 of os have posted on it in a week. I'm pretty sure none of us have a solution.

If anyone can help, we would be most grateful!
Turring Machines are better than C++ any day ^_~
I have only done this for OpenGL so, don't take my word for anything I say. It looks like the problem here is that the window is effectivly modified by that fullscreen switch. It is turned into a WS_POPUP style window of full screen size. Now if you turn windowed mode on, the taskbar might reclaim some of it's space, but that's it. The windowing system can't restore the old size, since that was lost when you changed your window into fullscreen. Now what I did was store the old size and window decoration settings, and manually restored them after the switch. Seems to work just nice.
Ok, this is what I got around to, requires no additional modification, just add it right after you Reset the device and it should all be fine.

For the curios people, the magic here is the SWP_DRAWFRAME flag, all the other is just to make the client rectangle the same as the buffer and not smaller.

However, there should be some better solution to it, gonna look around and see if I can find anything on it.

RECT rect;GetClientRect(dev->m_hWnd, &rect);AdjustWindowRectEx(&rect,    GetWindowLongPtr(dev->m_hWnd, GWL_STYLE),    GetMenu(dev->m_hWnd) != NULL,    GetWindowLongPtr(dev->m_hWnd, GWL_EXSTYLE));SetWindowPos(dev->m_hWnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top,    SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |    SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_NOZORDER);


EDIT: for the curious one, http://www.gamedev.net/reference/articles/article1034.asp, however if you ask me his solution isn't as good as it deals with the solution by explicitly setting the window style and hiding/showing it. hmm, but it depends on how you do it, I guess, if you hide the titlebar then it will be just as good.


Thanks Syranide,

Works fine now. I also used GetWindowInfo() when switching to fullscreen to save old window info so when i get back to windowed mode i restore the original position/size.

Also, im not sure what all the flags in SetWindowPos() do... I use NULL and it gives me the same effect... weird... too lazy to read msdn right now :-)
Quote:Original post by nkshs
Also, im not sure what all the flags in SetWindowPos() do... I use NULL and it gives me the same effect... weird... too lazy to read msdn right now :-)


Yeah, the other flags really doesn't matter that much, but, they will ensure nothing else is done except resizing and adding the frame again. Otherwise it will be activated, put to front in the zorder and so on... normally the window really has all these "states" before, but if the application were to be deactivated it would be activated and so on... but really, doesn't matter, I just like it that way.


This topic is closed to new replies.

Advertisement