Advertisement

Easy way to restrict Alt-Tab?

Started by September 13, 2000 11:39 AM
8 comments, last by Peddler 24 years, 3 months ago
Is there a simple means to restrict alt-tab in a fullscreen directx application...the surfaces are lost everytime a user hits alt-tab to go back to windows, eventually I will attack fixing this problem..but for now I would just like to simply restrict the access to windows when in the application. Any ideas on how I can handle this? Thanks -Tim Yarosh Lucid Games
Isn''t there a flag for that in the initialization of the object?
I''m fairly sure I''m using it somewhere, but it''s on my home computer and I''m at work. Try looking in the docs. You might also be able to filter out the keypress by catching the message before it is translated.

____________________________________________________

"Two wrongs do not make a right; it usually takes 3 or more."

____________________________________________________
"Two wrongs do not make a right; it usually takes 3 or more."
Some mistakes are too much fun to only make once.
Never anger a dragon, for you are crunchy and you go well with brie.

Advertisement
I don''t know if this is possible in VB (if you are using that) but you can prevent Windows from detecting ALT+TAB is pressed by creating a DirectInput object with the exclusive and foreground bit flag set.
-------homepage - email
Just catch the WM_SYSKEYDOWN message and don''t pass it off to DefWindowProc.
Just make sure you put code in to make Alt-F4 quit the app. I hate when games don''t do this

Morbo
Thanks for all the ideas..

But it seems that this is a lot harder then I thought. I am using VC++ w/ Directx 7...I checked into the DX sdk about setting the DXinput to exclusive, though it says it will filter out all input..except the alt-tab and a few other system commands, and I wasn''t able to get any positive results when testing it.

I tried filtering it out by catching WM_SYSKEYDOWN, but that also doesn''t seem to restrict alt-tab from being processed.

It seems like fixing the surface loss problem may turn out to be easier then finding a bandaid fix for it.

You could setup a system wide hook, and catch all key messages.

Advertisement
quote: Original post by baskuenen

You could setup a system wide hook, and catch all key messages.


Speaking of those...

How might you set up a hook?



-Agent1




Operator: You have a telegram.
Encrypted Transmission from Agent1, sent Wed Sep 6, 2000 7:38 PM:
Agent1: *Speeds through section on Message Loops*
Agent1: Soon I'll be using Property Sheets! :)
Byte Me: *been using them since he was a wee lad*


[art]: Take it out, then shove it in a day or two.
[art]: *Operates on his brains.
I found something on MSDN, but..(at least for me)...it only restricts alt-tab and the other system keys AFTER the application ends, forcing a shutdown.

    UINT nPreviousState;// Disables task switchingSystemParametersInfo (SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);// Enables task switchingSystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);     


Its supposed to make windows think a screensaver is running, so it doesn''t accept alt+tab, or ctrl+alt+delete.
quote: Original post by Agent1

Original post by baskuenen

You could setup a system wide hook, and catch all key messages.

Speaking of those...

How might you set up a hook?



Some snippets:

    //---------------------------------------------------------------------------//	HOOK//---------------------------------------------------------------------------HHOOK hHook;//---------------------------------------------------------------------------LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) { 	if (!(nCode < 0))// && hWnd != NULL)	{		static HWND hWndPrev = 0;		MSG *lpMsg = (MSG *) lParam;		if (lpMsg->hwnd != hWndPrev && (lpMsg->message == WM_MOUSEMOVE || lpMsg->message == WM_NCMOUSEMOVE))		{			char sz[256];			LoadString((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), GetDlgCtrlID(lpMsg->hwnd), sz, sizeof(sz));			SendMessage(hWndStatus, SB_SETTEXT, 0|SBT_NOBORDERS, (LPARAM)sz);			hWndPrev = lpMsg->hwnd;		}	}	return CallNextHookEx(hHook, nCode, wParam, lParam);}//---------------------------------------------------------------------------		if ((hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, 			(HINSTANCE)NULL, GetCurrentThreadId())) == NULL)		{	return FALSE;		}		...message loop...		UnhookWindowsHookEx(hHook);//---------------------------------------------------------------------------    


I use this hook to catch mouse messages (for my application only), so I can display a nice help string in my statusbar.

If you want to setup a system wide hook, you''ll need a DLL...is it worth your trouble...?

Hope this is what you were searching for?...

I must come back on this. Hooks might be nice for other things, but Peddler has a better solution (I now see). The SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,...) should do the trick easily

Sorry for making things more complicated than they already are

This topic is closed to new replies.

Advertisement