Jump to content
  • Advertisement
Sign in to follow this  
Raxvan

managing alt+tab

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all Can someone know that there a method to stop windows from loosing focus on a application! How can i stop alt+tab working? For example in max paine 2 is impossible to alt+tab and if you somehow do it the computer is gets "Not Responding" :D tnx

Share this post


Link to post
Share on other sites
Advertisement
Alt-Tab should not be disabled, unless you are building a kiosk or something specialized. Your textures that are loaded should be stored in system memory so when a alt-tab occurs you can easily load them back into video memory when your program gains focus, among other things.

-----------------

Check out CodeBASIC.org

Share this post


Link to post
Share on other sites
Don't disable alt-tab. In an NT environment like XP, if you do it incorrectly, you can end up not being able to log into windows anymore. There are many numbers of ways you can prevent alt-tab from working, but I say it again: -Don't do it! It almost invariably leads to troubles. Besides, there other reasons why an application might loose focus. Ex: AV software, Updating softwares, or other software that may demand focus for any other of reasons. To put it plainly, you need to deal with your application loosing focus. There simply is no way around it.

Share this post


Link to post
Share on other sites
There are games that disable ALT+TAB. I dont think this is nice but I dont think this is so dangerous as you say.
I used it on XP and Win98 without problem.
Obviously YOU MUST PROVIDE AN EXIT FROM YOUR PROGRAM.
If something goes wrong you have to hardware reset your computer!

This is the code you need: it is not a black art secret but it is well documented.

The idea is simply to disable all windows except the window you are using
this disables SCREENSAVERS, ALT+TAB and CTRL+ALT+DEL


Usage: pass your window and the state requested (true or false)
NOTE: remember to pass false to disable the exclusive mode when exit!!!
unless you want to turn off your computer [smile]


bool SetExclusiveMode(HWND hwnd, bool bExclusiveMode){
bool oldState;
DLONG dlong;
bool bEnableWindows = (!bExclusiveMode);
bool bSetScreenSaveActive = ( bExclusiveMode);

dlong.wParam = (WPARAM)(hwnd); // your window
dlong.lParam = (LPARAM)(bEnableWindows); // state requested for the others

LONG enumParam = (LONG)(&dlong);

WNDENUMPROC EnumWindowsProc = (WNDENUMPROC)EnumWindowsProc_enb;

EnumWindows(EnumWindowsProc, enumParam); // callback function
SystemParametersInfo(SPI_SCREENSAVERRUNNING,
bSetScreenSaveActive, &oldState, 0);
return true;
}



this is the callback function


BOOL CALLBACK EnumWindowsProc_enb(HWND hwnd, LPARAM lParam){
DLONG dlong = *((DLONG*) lParam);
HWND MainWnd = (HWND)dlong.wParam; // the window you are using
BOOL bEnable = dlong.lParam; // state requested
if( (hwnd != MainWnd) && (IsWindowEnabled(hwnd)!=bEnable))
EnableWindow(hwnd, bEnable);
return TRUE;
}



Two suggestions: 1) rate me 2) dont send me a copy or your program [lol]

Share this post


Link to post
Share on other sites
Someting is wrong i get errors compiling like this

D:\projects\Unrevealed\Main.cpp(9) : error C2065: 'DLONG' : undeclared identifier
D:\projects\Unrevealed\Main.cpp(9) : error C2146: syntax error : missing ';' before identifier 'dlong'
D:\projects\Unrevealed\Main.cpp(9) : error C2065: 'dlong' : undeclared identifier
D:\projects\Unrevealed\Main.cpp(9) : error C2059: syntax error : ')'
D:\projects\Unrevealed\Main.cpp(10) : error C2228: left of '.wParam' must have class/struct/union type
D:\projects\Unrevealed\Main.cpp(11) : error C2228: left of '.lParam' must have class/struct/union type
D:\projects\Unrevealed\Main.cpp(20) : error C2146: syntax error : missing ';' before identifier 'dlong'
D:\projects\Unrevealed\Main.cpp(24) : error C2228: left of '.wParam' must have class/struct/union type
D:\projects\Unrevealed\Main.cpp(25) : error C2228: left of '.lParam' must have class/struct/union type
Base.cpp
c:\dxsdk\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
d:\projects\unrevealed\base.h(22) : warning C4081: expected 'newline'; found ';'
d:\projects\unrevealed\base.h(23) : warning C4081: expected 'newline'; found ';'
d:\projects\unrevealed\base.h(24) : warning C4081: expected 'newline'; found ';'
Game.cpp
c:\dxsdk\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
d:\projects\unrevealed\base.h(22) : warning C4081: expected 'newline'; found ';'
d:\projects\unrevealed\base.h(23) : warning C4081: expected 'newline'; found ';'
d:\projects\unrevealed\base.h(24) : warning C4081: expected 'newline'; found ';'
Error executing cl.exe.

*******.exe - 9 error(s), 9 warning(s)

Share this post


Link to post
Share on other sites
Always start to look at the first error to solve it:

Quote:
Original post by Raxvan
D:\projects\Unrevealed\Main.cpp(9) : error C2065: 'DLONG' : undeclared identifier


This is pretty easy, looking through the code we see DLONG is used as a type. I dont know what blizzard intended DLONG to be, but I think should do something like this:

typedef type DLONG;

// Or this:
// #define DLONG type



Of course you would have to replace type with whatever it should be.

Share this post


Link to post
Share on other sites
Sorry! I copied the code from my file and I've not noticed that DLONG is not in the 'hungarian' winsows typedef!!!

Here


typedef struct _DLONG{
LONG wParam;
LONG lParam;
} DLONG;


it's simply a long pair

For your direct input errors I dont know [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!