DirectX 9 switching window state

Started by
36 comments, last by malborojones 12 years, 10 months ago
Hellow :)
I've searched for about 2 hours around the web for a guide on how to switch a window from windowed to full screen after runtime.
I can do it fine at run time but I want to be able to switch back and forth.

I've made this method but when it's called the screen just goes white:

First it creates the new window style and updates the window




//Create new window style
DWORD style = (windowed) ?
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX :
WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE;

//set new window style
SetWindowLong(mHwnd, GWL_STYLE, style);
ShowWindow(mHwnd, SW_SHOW);
UpdateWindow(mHwnd);




then updates the present parameters for the device



mPresent.hDeviceWindow = mHwnd;
mPresent.Windowed = (windowed) ? TRUE : FALSE;
mPresent.BackBufferFormat = (windowed) ? D3DFMT_UNKNOWN : D3DFMT_X8R8G8B8;



mPresent are the present parameters used initially to create the device so I just update the values that need to be changed.

Next I call reset with the new parameters



hr = mDevice->Reset(&mPresent);

if (FAILED(hr))
{
if(hr == D3DERR_DEVICELOST)
ErrMsg("Device Lost");

if(hr == D3DERR_DEVICEREMOVED)
ErrMsg("Device Removed");

if(hr == D3DERR_DRIVERINTERNALERROR)
ErrMsg("Driver Error");

if(hr == D3DERR_OUTOFVIDEOMEMORY)
ErrMsg("Out of memory");
}



After this is done I don't get any of the errors that the MS site says it returns so none of the messages are shown but if I check if hr has failed I do get an error and hr has the value -2005530516

So what am I doing wrong? I keep seeing something about "state blocks" being released before calling Reset but I have no idea what they are and presume I haven't used any that need to be released.

So, any idea how to go about this correctly?

Thanks, Mal.
ph34r.gif
Never refuse a cup of tea, that's how wars are started.
Advertisement
try searching MSDN for Window Features (my links seam to point to my local one, but ill try to link to the online one)
This might be the online version

the local one has too much text to paste here.
ill update when i find it

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.


Try Reading This


What's this? xD
Never refuse a cup of tea, that's how wars are started.

[quote name='ryan20fun' timestamp='1306250986' post='4815150']
Try Reading This


What's this? xD
[/quote]

link pointed to my local one :P

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

I understand the whole windows style stuff (that's what the link you gave me seems to be on)
when I try switching, the style of the window changes as it should e.g. the borders disappear when it should be full screen and show again when it's set to windowed but the window just goes white. That doesn't really make much sense because my render function clears the screen black before anything else.

Also before changing I have two sprites on the screen that I can move around with the arrow keys, once I try to switch mode they disappear as well as the screen going white.

Never refuse a cup of tea, that's how wars are started.
the DirectX device could be lost, i hade that when i was experimenting with Fullscreen and then minimizeing it.
you need to resoet the device and reload your assets (refer to the DirectX documentation on what needs to be reloaded, but as far as i know you have to reser and reload everything but shaders)

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

what you can do is create a borderless window at the current screen resolution to fake full screen.
what you could do is to reset the device with nre presentation params that state that it should be fullscreen.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

So do you mean that all textures have to be reloaded, sprites remade etc.? That's a bit of an irritation D:
Never refuse a cup of tea, that's how wars are started.
May I direct you to the very well written tutorial/article of Evil Steve about this particular subject here? Hope this helps.
So do you mean that all textures have to be reloaded, sprites remade etc.?[/quote]
Not if they're created with D3DPOOL_MANAGED...

You only have to release and recreate unmanaged resources when you do a device reset. In most cases, the only reason you would ever create an unmanaged resource is if it can't be managed (e.g. D3DUSAGE_DYNAMIC).

This topic is closed to new replies.

Advertisement