Archived

This topic is now archived and is closed to further replies.

Cipher3D

ALT-TAB and its anoyances!

Recommended Posts

Cipher3D    340
I''m developing a directx game, and when I run my window, if I press alt-tab (switching between applications) or make it unactive, it terminates into the underworld! Can anyone explain how to fix this? Cheers, Cipher3D

Share this post


Link to post
Share on other sites
Gladiator    127
check if your application is inactive or active for that matter and pause any action until the game is activated again...

check out WM_ACTIVATEAPP

Share this post


Link to post
Share on other sites
merlin9x9    174
...or is it WM_ACTIVATE? If I''m not mistaken, both work, though does anyone know which one is considered correct to use? Even Microsoft''s own examples use both...

Share this post


Link to post
Share on other sites
Oluseyi    2116
quote:
Original post by merlin9x9
...or is it WM_ACTIVATE? If I''m not mistaken, both work, though does anyone know which one is considered correct to use? Even Microsoft''s own examples use both...

I believe, from looking at the documentation, that the one (WM_ACTIVATE) is sent to windows which may use the same input queue - meaning that they may belong to the same application - while the other (WM_ACTIVATEAPP) is sent to separate applications.



I wanna work for Microsoft!

Share this post


Link to post
Share on other sites
MarkyD    127
All I have done is made my own message handler. If a message is WM_ACTIVATEAPP , then the wParam or lParam (I forgot which one) will be either 1 or 0 . If it is 1, then -I think- it is activating my application, otherwise it is deactivating. Simply trap this message and the game will keep chugging along...

~ There''s no substitute for failure ~

Share this post


Link to post
Share on other sites
MarkyD    127
  

procedure TGame.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
// If this message is going to deactivate the app, trap it

if (Msg.Message = ACTIVATEAPP) and (Msg.wParam = 0) then
Handled:=true;
end;



~ There''s no substitute for failure ~

Share this post


Link to post
Share on other sites
narfidoo    122
In order to disable the ALT + TAB key combination and not lose focus to the other applications running, do the following:

1.Create the application main window with the minimize button disabled.


2.Disable all the windows in the system by calling EnumWindows(). Use EnableWindow( .., FALSE) in the callback for this function.


3.Deceive the operating system by running the application as a screen saver. This can be done by calling SystemParametersInfo(SPI_SCREENSAVERRUNNING,TRUE, ....);.


4.In the WM_DESTROY handler of the main application window again call EnumWindows() to enable all the windows in the system.


5.Deceive the operating system by no longer running the the application as a screen saver. This can be done by again calling SystemParametersInfo(SPI_SCREENSAVERRUNNING,FALSE, ....);.

From MSDN

Share this post


Link to post
Share on other sites
S1CA    1418
1. Windows is a multitasking OS - people DO want to run things in the background (e.g. someone playing a game while waiting for a big file to download, they want to Alt-Tab occasionally to check the download progress). The hacks to disable it don''t work on all versions of Windows, and aren''t guaranteed to work on future versions.

2. Assuming a reasonably modern version of DirectX, you should be checking the return codes from major calls (for example Present() in D3D8), if any of them return a D**ERR_**LOST error, then it means that some resource or control over a device was lost as a result of the Alt-Tab. You should test for restorability (TestCooperativeLevel() in the case of D3D) and restore control and re-load any resources as required (Reset() in D3D). This is documented in the DirectX SDK docs under the "lost devices" of each relevent part of the SDK.
You can make an app behave correctly in response to an Alt-Tab just by handling these return codes. No need to do any logic based on app activation messages from Windows!.
Look at the code in the SDK samples for an example of this working in practice.

3. If you''re using an older version of DirectX (say 3 or 5), then you will have to do some extra work with the app activation messages. The SDK samples have examples of this working.

4. The other reason you would want to watch for app activation messages is so that you can switch to a more friendly message pump, pause any music, pause the game, stop any game timers etc.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites