If I launch my DirectX program, full-screen initializes. If I alt tab out of it, it alt-tabs as normal. However, if I then maximize it so it has the focus of my computer again and then alt-tab for the second time, the window doesn't minimize. The taskbar shows up but the program doesn't minimize. It's like, the first time I alt tab it works perfectly normal but then second time I do it, it doesn't work. Anyone know why? I would really like to fix this. Thankssss..

Dani AI

Generated

Symptom recap: a full‑screen Direct3D app alt+tabs out correctly once, but after restoring and alt+tabbing again the window does not minimize (the taskbar appears but the app stays visible). Given ’ note that no explicit minimize/maximize handlers are present, the behavior strongly suggests the program is failing to let Windows finish its focus/restore cycle — most often because the message loop or device‑lost handling is blocking further window messages.

Both prior replies point to useful lines of investigation. ’s flag/check idea is on target: full‑screen exclusive mode needs correct state tracking. was right to point at TestCooperativeLevel — in native D3D the call returns HRESULTs (managed wrappers may throw) and the app must treat a lost device as a pause state, not a permanent failure. Common mistakes that lead to the exact symptom are: calling Reset/Present while the GUI thread is not pumping messages, swallowing WM_SYSCOMMAND/WM_ACTIVATE/WM_ACTIVATEAPP, or holding an exclusive DirectInput keyboard so Windows never gets the Alt+Tab.

Quick troubleshooting checklist:

  • Verify the message pump keeps running while the app is "lost" (log WM_ACTIVATE/WM_ACTIVATEAPP/WM_SIZE/WM_SYSCOMMAND events).
  • Run the program windowed; if alt+tab works there, the cause is full‑screen device handling.
  • Ensure TestCooperativeLevel (or equivalent) is polled on the same thread that created the device; on D3DERR_DEVICELOST stop presenting and keep pumping messages until Reset is allowed.
  • Release D3DPOOL_DEFAULT resources before Reset and recreate them after a successful Reset.
  • Don’t swallow SC_MINIMIZE/SC_RESTORE in WndProc; avoid long blocking calls on the UI thread while waiting for device restore.
  • If using DirectInput in exclusive mode, unacquire on focus loss and re‑acquire on focus gain.

Enabling the DirectX debug runtime and adding lightweight logging around the focus/device states will usually reveal which step is being missed and explain why the second Alt+Tab never completes.

Recommended Answers

All 5 Replies

Your description sounds like a flag may not be getting set correctly. does your program contain code that is executed when it is minimizes and maximized ? Does the same problem occur with other DirectX programs written by either yourself of someone else (attempting to isolate the problem to either your code of Microsoft's).

It works fine with games written by professional game companies so it isn't my computer and I don't handle any code when my game is minmized/maximized

Bump

It might help if I give you my code so here: My entire source:

I am not sure if you are using TestCooperativeLevel() correctly ....

http://msdn2.microsoft.com/en-us/library/microsoft.windowsmobile.directx.direct3d.device.testcooperativelevel.aspx

If the device is lost and cannot be restored at the current time, TestCooperativeLevel throws a DeviceLostException. This is the case, for example, when a full-screen device loses focus. If an application detects a lost device, it should pause and periodically call TestCooperativeLevel until no exceptions are thrown. The application can then attempt to reset the device by calling Reset and, if this succeeds, restore the necessary resources and resume normal operation. Note that Present throws a DeviceLostException if the device is either "lost" or "not reset."
A call to TestCooperativeLevel fails if made on a thread other than the one used to create the device being reset.

It throws exceptions.... does not return anything ....

Here's a good game example using DirectX ... used directdraw but it should show you all the basic you need to know how to setup and handle a DX game app:
http://www.codeproject.com/directx/SuperBrickBreaker.asp


And for DirectX 9 tutorials:

Those are quite compleate in dealing with win32 basics and basic DX init

P.S Once you have a nice little windows and directx init/looping code wrap it all up into a nice set of classes/functions that you can reuse. It's really worth the time and effort ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.