Two simple problems ...!

TheLionKing 101 Oct 04, 2003 at 06:38


I am facing two problems and I have came up with a few ideas with them. These are :

  • After executing my application in FullScreen Mode, if I press ALT+TAB or Windows key or by anyother means I just go to desktop and when I return back to my application, it is in Windowed mode and is empty …? I think I need to tell the Application that it has focus or is it active or not? I know how to tell the application that wether it is active or not by WM_ACTIVE Message, but what do I do next :eek: ?
  • If I want to change the resolution of my application while executing it … How do I do that? Do I have to release the D3DDevice & window and create them again in the new resolution size or do I have to just play with the D3DDevice?

All I need is some hints :confused: !

2 Replies

Please log in or register to post a reply.

MHaggag 101 Dec 12, 2003 at 06:10

Alt-TABing scenarios and changing resolution have quite in common. In both cases you want to Reset() your device with the previous, or new (respectively) presentation parameters.

However, to do a device Reset() you need to release all the D3DPOOL_DEFAULT resources (also known as: Application-managed resources), Reset(), and then reload/restore them back again.

When the user Alt-Tabs, your device is put in a “lost” state (D3DERR_DEVICELOST returned from TestCooperativeLevel() and Present()). You r game loop should check TestCooperativeLevel() every frame. When the device becomes LOST, your app should not do any processing at all (or do some background processing, if needed).

When TestCooperativeLevel() returns D3DERR_DEVICENOTRESET, it means that your app has regained focus and is now ready to be restored. You should then:
1 - Release all app-managed (D3DPOOL_DEFAULT) resources
2 - Reset() device with the previous presentation parameters
3 - Restore app-managed resources

When changing the resolution, you don’t have to destroy the device. That’s a common misconception. You just have to fill a new presentation parameters structure (changing only the backbuffer width and height, if you’re changing the resolution only), and then doing the 3 “reset” steps (copied from above):
1 - Release all app-managed (D3DPOOL_DEFAULT) resources
2 - Reset() device with the new presentation parameters
3 - Restore app-managed resources

Muhammad Haggag

bladder 101 Dec 12, 2003 at 14:15

and adding to the above. It’s also quite common to forget to actually resize your window when switching between windowed and fullscreen mode. This can be done with a function like SetWindowPos (This is using C++, with C# and MDX, there’s probably something similar, but Im not sure).

What I usually do is check for WM_ACTIVATEAPP mesages and set a bool that says whether the window is in focus or out (active or not) depending on whether WPARAM is TRUE or FALSE. Then in my “game loop” I first check if the app is active. Then if is, I check if TestCooperativeLevel succeeds, if it does then you’re good to go, just continue with your rendering. If however it returns D3DERR_DEVICELOST you can just “continue” with the next game loop iteration and check again. Some people would sleep for a few milliseconds in this situation as well. If it returns D3DERR_DEVICENOTRESET, then as mentioned above, you release all default pool resources, reset the device and then reload all the default pool resources…

The tutorials on this page takes care of resetting the device and switching between windowed and fullscreen mode. Alternatively, you can check out the DirectX framework that comes with the SDK, they handle everything in there how you probably would want to handle it.