The dreaded ALT-TAB

Started by
12 comments, last by serratemplar 23 years, 2 months ago
Hey everyone. I''ve taken the past THREE months off from programming !!!!! I know, I know, but I had finals and ALL sorts of shit to do (I''m a psych major, understand, I''m in this for making fun games, not androids)...anyway, I''ve got a bitty problem with my game and I''m hoping someone can help me. Alright, so I made my game run fullscreen hardcore as a "pop-up window" (This is in windows, Visual C++ for the record), so as to avoid moving window-over-window silliness and, quite frankly, to make my game huge and cool. However, my game kind of throws a hissy fit when you tab out of it. I''ve got an event handler running like a good boy (I am a hardcore devotee to LaMothe''s methodology!), so I''m wondering...when the user hits alt-tab, I must get *some* message about it. What is it? And what do I do with it? I figured I could have the game freeze ops until the focus is restored. Furthermore, how do I know when the focus is restored, and what do I do to get things going again? Any ideas, thoughts, or experience at all would help, I am certain. Thank you very much for your time. /*********************************************** "We are men of action. Lies do not become us." ***********************************************/
Advertisement
I do this in my game:
    case WM_SIZE:	{	// Check to see if we are losing our window...	if( SIZE_MAXHIDE==wparam || SIZE_MINIMIZED==wparam )		{		bActive = false;		}	else		{// right here, you need to call Restore on all of your// DirectDraw surfaces, otherwise you loose their contents and// I think you'll get a GPF if you try to write to them before// restoring, but I'm not sure about that.  For example://ddprimarysurface->Restore();		bActive = true;		}	} break;    

Then make sure you make bActive a global boolean variable and stop drawing to the surface (if you're using DirectDraw). Then, when you come back, bActive will be true and you can continue drawing to the surfaces.


My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X
R- tv+ b++ DI+(+++) D- G e* h!"
Decode my geekcode!
Geekcode.com


Visit our web site:
Asylum Entertainment

Edited by - ziplux on January 15, 2001 11:07:34 PM
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Awesome =) I understand it!!!!!! (This excites me.) Thank you very much; trust that I''ll post anew if I try this and I blow it up in my face. =) lol

Cheers all,
Steve

/***********************************************

"We are men of action. Lies do not become us."

***********************************************/
And now, stupid questions of clarification... =)

When you say *all* direct draw surfaces, do these include surfaces that are in mem only and not primary/secondary surfaces? I presume so, but thought I''d make certain...

I don''t do anything to the surfaces other than stop drawin to them until the restore once I get the window back; is this correct?

Thank you again for your time.

~Steve

/***********************************************

"We are men of action. Lies do not become us."

***********************************************/
Yes, but you should put your app in a sleep-loop or something when not active (so it steals less CPU). Then when you restore the surfaces I think it''s quite possible that you must restore their contents as well, so you must reload any bitmaps and stuff. This may have changed for the newer releases of DX, but it used to be that way at least (it''s been a while since I wrote any DDraw programs).

/Andreas
If you''re using Direct Draw you can just use the RestoreAllSurfaces() method of the DirectDraw object and it will restore all your surfaces, in the order they were created. I think this was introduced in DirectX 7, so check your documentation if you''re using an earlier version.

You will need to recreate the contents of your surfaces by reloading bitmaps or whatever.

I came across problems when I tried restoring/reloading surfaces in response to Windows messages. Search through old posts for full details. I resorted to checking the Primary surface at the start of my game loop, using IsLost(), and restoring/reloading if needed. Again, check the old post for details.
If you''re using Direct Draw you can just use the RestoreAllSurfaces() method of the DirectDraw object and it will restore all your surfaces, in the order they were created. I think this was introduced in DirectX 7, so check your documentation if you''re using an earlier version.

You will need to recreate the contents of your surfaces by reloading bitmaps or whatever.

I came across problems when I tried restoring/reloading surfaces in response to Windows messages. I resorted to checking the Primary surface at the start of my game loop, using IsLost(), and restoring/reloading if needed. Search through old posts for full details.
Yeah, Windows doesn''t like it at ALL when I try to have my program restore stuff on a windows message... so I''ll try it your way, see if that can help any. Thanks so much for your help.

/***********************************************

"We are men of action. Lies do not become us."

***********************************************/
hello,
when you do alt+tab and move to some other application or whatever, you can lose surfaces on your video card(simply other application override it), i think you got that already
so now you alt+tab back into your program, without any(theoretically) surfaces. The best way to restore them is when you are blitting...

so u put like this

HRESULT hRet;
while{TRUE}{

hRet = BLITFUNCTION-THAT-U-ARE-FAMILIAR-WITH-IT-IN-DX

if(hRet == DD_OK)
breakl; //lets go out of while if everythink is goodie

if(hRet == DDERR_SURFACELOST){
RestoreAll(); // restore sucker and return to blitter
}
....
}

in RestoreAll function you put the necessery work, that is,
finding if surface is lost, if it is, restore it AND reload any bitmap if you have it(backbuffer just restore it will be updated with your program)...
like this...
void RestoreAll(){
if(some_surface->IsLost()){ //i think it is IsLost()..check it
some_surface->Restore();
DDReLoadBitmap(some_surface, "where_it_is.bmp"); //using DDReLoadBitmap from dx..add ddutil.h and ddutil.cpp
}
}
dealing with backbuffer you just restore it
Is checking the IsLost() member of the primary surface sufficient? Does anyone know whether it''s possible for an offscreen surface to be lost while your primary surface is not?

This topic is closed to new replies.

Advertisement