Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ALT TAB again........

Status
Not open for further replies.

ceodav

Programmer
Feb 21, 2003
106
IT
hi,
i need help to solve a big problem for my application...
how is possible to intercept the alt tab?
i need this because i don't want some people change the focus from the main program running to another.
i'm trying with OnSysKeydown but i don't get any result because the program never enters in that subroutine.
my computer is windows NT based.

thanks
ceodav
 
Please Read the article "HOWTO: Disable Task Switching on Win32 Platforms" from MSDN.

It has different solutions for NT and Win(x platforms. To make sure your progam will work OK on both platformas you will have to use GetVersionEx API to determine the platform you are on.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
thank you very much!!!!!

is the same if i want to intercept the key CTRL.

bye
Ceodav
 
i tryed....
but i can't find that article.........


 
HOWTO: Disable Task Switching on Win32 Platforms

Q226359


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Application Programming Interface (API), included with:
Microsoft Windows 98
Microsoft Windows 95
the operating system: Microsoft Windows 2000
Microsoft Windows NT Server versions 3.51, 4.0
Microsoft Windows NT Workstation versions 3.51, 4.0

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


SUMMARY
This article describes how to disable task switching and other system functions accessed through key combinations such as CTRL+ESC and ATL+TAB on Win32 Platforms.

Windows 95 and Windows 98
Applications can enable and disable ALT+TAB and CTRL+ESC, for example, by calling SystemParametersInfo (SPI_SETSCREENSAVERRUNNING). To disable ALT+TAB and CTRL+ESC, set the uiParam parameter to TRUE; to enable the key combinations, set the parameter to FALSE:

UINT nPreviousState;

// Disables task switching
SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);

// Enables task switching
SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
NOTE: Applications that use SystemParametersInfo (SPI_SETSCREENSAVERRUNNING) to disable task switching must enable task switching before exiting or task switching remains disabled after the process terminates.
Windows NT 4.0 Service Pack 3 and Later and Windows 2000
Applications can disable ALT+TAB or CTRL+ESC by installing a low-level keyboard hook. A low-level keyboard hook (WH_KEYBOARD_LL) is installed by calling SetWindowsHookEx. For more information on Window hooks see the "Hooks" overview in the Platform SDK documentation.

The following is a sample low-level keyboard hook procedure that disables CTRL+ESC, ALT+TAB, and ALT+ESC:


LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
BOOL bControlKeyDown = 0;

switch (nCode)
{
case HC_ACTION:
{
// Check to see if the CTRL key is pressed
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);

// Disable CTRL+ESC
if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
return 1;

// Disable ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1;

// Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1;

break;
}

default:
break;
}
return CallNextHookEx (hHook, nCode, wParam, lParam);
}
Windows NT 4.0 Service Pack 2 and Earlier, Windows NT 3.51 and Earlier
Applications can disable CTRL+ESC system-wide by replacing the Windows NT Task Manager, but this is not recommended.

Applications can disable ALT+TAB and ALT+ESC when the application is running by registering hotkeys for the ALT+TAB and ALT+ESC combinations by calling RegisterHotKey.



MORE INFORMATION
Older development tools, such as Microsoft Visual C++ Version 5.0 and earlier, might not contain the header files necessary to build an application that uses low-level keyboard hooks. To obtain the most recent header files, download the latest Platform SDK from the following Microsoft Web site:

Because low-level keyboard hooks are a feature specific to Windows NT 4.0 Service Pack 3 and later, define _WIN32_WINNT >= 0x0400 prior to including winuser.h (or windows.h).

Additional query words: SystemParametersInfo SetWindowsHookEx Hooks SPI_SCREENSAVERRUNNING SPI_SETSCREENSAVERRUNNING WH_KEYBOARD_LL

Keywords : kbHook kbInput kbOSWinNT400 kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin95 kbOSWin98
Issue type : kbhowto
Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT351xsearch kbWinNT400xsearch kbWinNTW351xsearch kbWinNTW351 kbWinNTSsearch kbWinNTS400xsearch kbWinNTS400 kbWinNTS351 kbWinNTS351xsearch kbOSWin2000 kbOSWinSearch


Last Reviewed: February 15, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources. s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
ok,

the header are windows.h e winuser.h
but i got some errors:
WH_KEYBOARD_LL not defined
LLKHF_ALTDOWN not defined
and in ULONG_PTR dwExtraInfo within KBDLLHOOKSTRUCT.

do i have to define other header files?

thank you
ceodav
 
yes,
i did...

i have also downloaded the new windows.h and winuser.h from the microsoft site because i'm using visual c++ 5.

i have no new idea yet, but i hope to work it out very soon.

ceodav


 
anyway,
thank you very much for your help....

bye
 
I have VC++ 6.0 and in my winuser.h is defined WH_KEYBOARD_LL. (I haven't looked for the others)

Check it out for yourself in your version of winuser.h. BTW, see what other .h they include, you might need some newer versions of other included files.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
yes,
i did it, now the program is working but i got a very nasty error before the launch:

Debug error

DAMAGE! after normal block (#130) at 0x00D81E00

if i click on ignore the program run perfectly.

this is strange, i think the program has written something in the registry because if i use old version of the same .exe i got always the same error.
this is only an idea.
have you got the same in your program?

thanks
ceodav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top