this question cannot be answered: alt-tab

Started by
18 comments, last by serratemplar 19 years, 11 months ago
This question has been asked a million times on this site, and I feel that I''ve read thru all of those posts, I''ve even posted this question, and nobody every answers it. I am beginning to believe that the answer to this question is protected by some super secret all powerful illuminati-style cult, and I am very, very sad about this. People have found ways to disable alt-tab, and people allude to "lpDirectDrawObj->RestoreAllSurfaces" and, well...here is my deal. When someone alt-tabs out of my application, my app closes. Poof. Gone. As if it had not been running. What *really* irks me is that before I upgraded my processor and reformatted, my code worked fine. I''ve got this in my message handler: case WM_ACTIVATE: { if (LOWORD(wparam)==WA_INACTIVE) g_App.SetWindowStatus(false); if (LOWORD(wparam)!=WA_INACTIVE) { g_App.SetWindowStatus(true); g_App.RestoreSurfaces(); } } break; SetWindowStatus tells my application to hold its horses. This is only a skeleton initializing directdraw7, so it''s not doing anything fancy at all. I have a primary surface and a backbuffer. That''s it. It''s a fullscreen, exclusive app, which I draw on a fullscreen popup window (the norm). When the user tabs out, my window loses focus and should minimize. Instead it closes. It disappears from the taskbar and from the taskmanager. You cannot alt-tab back in: it is gone. People must hate this question, because the only people who answer it nowadays seem to be people who are content to disable it, and if professional game companies can do it (even the really BAD ones) then it''s gotta be doable. Even if you swore you''d never answer it again, if anybody can help me to get alt-tab working in my game(s) I promise I will answer this question for everyone for the rest of my programming life. Open me an Alt-Tab board on this site and I will moderate it, I will answer the question again and again as pennance for all time that remains for this Earth. Please, please, please someone help me. It makes me tear my hair out not knowing how. Thank you for reading, even if you didn''t answer, Steve By the way, please don''t post how to disable ALT-TAB here. Thanks to the hundred other forum posts, I could do that.
Advertisement
That''s very odd, are you sure your window status flag isn''t causing your message loop to exit? In response to the inactive message you should probably call ShowWindow(hWnd, SW_MINIMIZE). Hmm, also, you aren''t returning true in that code snippet; you should return true from your window procedure if you handle the message. Unless you''re doing that elsewhere in your message procedure.

I wouldn''t be content to disable alt-tab; in fact most people say that you should not disable it. I usually don''t bother handling it (although that was when I was using OpenGL; everything seemed to work there. Now that I''ve moved over to D3D I guess I''ll have to think about this issue soon too).

cheers
sam
I can''t believe it. =)

I don''t know whether to feel relieved or colossally stupid. I had my main program loop based on the WindowStatus, which set to false on a tab out, so of course my program exitted.

After making the main loop dependent on only a WM_QUIT or WM_DESTROY msg, I have found that I can in fact tab in and out.

Simple insights.

Well, thanks to anyone who pondered this, and - as I promised - I will answer ALT-TAB questions from now on. =)

Please don''t give me a forum.
I take it back

It doesn''t work reliably. Worked the very first time, now I can''t tab back in, but it still seems to be running (it''s in the taskbar)

Any further ideas?
Okay, this is not an answer but the problem is this:

while(m_lpddsPrimarySurface->Flip(NULL, DDFLIP_WAIT)!=DD_OK);

Once this operation has taken place (a page flip), alt-tab will not restore the application. You can tab out but not back in...it won't remaximize. I have to use the task manager to kill it. *Maybe* it's stuck in that loop?? But that loop has always worked for me before...

My attempt to recover is this:

ShowWindow(m_hWindow, SW_RESTORE);

if (m_DirectDrawObject)
if (m_lpddsPrimarySurface->IsLost())
m_DirectDrawObject->RestoreAllSurfaces();

You can still tab between the game and everything else that's running...it just won't restore itself, won't redraw itself, etc. Button on taskbar depresses as if it should though.

[edited by - serratemplar on May 26, 2004 1:12:56 AM]
What exactly do RestoreSurfaces() and RestoreAllSurfaces() do? From what I understand, you need to re-create everything: vertex buffers, textures, devices. Check out this MSDN link (it actually says it''s archived content so there''s probably a newer up-to-date version somewhere). Also here is a sample that I found from a cursory google search that might help.

cheers
sam
RestoreAllSurfaces is a member of IDirectDraw7, RestoreSurfaces is a member of my own application object that kicks in when the user alt-tabs back into my program.
Not sure if this''ll help you, but here''s what I''m doing in my WndProc function. I had a hell of a time getting this working at first, too - but when I finally figured it out it was all worth it. I can minimize, maximize, alt-tab in and out, from both windowed and full-screen, in any of the available resolutions. So it is possible.

If you need to see any of the functions, just let me know.

		case WM_ACTIVATE:			{			static bool reCreateAll = false;			if (LOWORD(wParam)==WA_INACTIVE) {				// the user is now working with another app				gameRunning = false;				gameTimer.OnLoseFocus();				if (!graphics.Windowed()) { // we were in full-screen, when we get re-activated											// we''re going to have to reset device					reCreateAll = true;				}			} else {				// the user has now switched back to our app				if (reCreateAll) { // we had switched to Windows from full-screen, need to recreate device and resources					ReleaseResources();					// release all resources first --> sprites, textures, fonts					graphics.Reset();					// now restore all resources					RestoreResources();				}				gameRunning = true;				gameTimer.OnRegainFocus();			}

Life's Short. Make Games.
Maybe in the loop, you're rendering while the application is not active. You have to if-else the gameloop too (if not active, WaitMessage() ).

--
You're Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net's DirectX FAQ. (not as cool as the Graphics and Theory FAQ)

[edited by - Pipo DeClown on May 26, 2004 1:13:14 PM]
THanks for the recommendations, guys...once I can get my hands back on my own system (working overtime right now) I''ll try them out =)

This topic is closed to new replies.

Advertisement