A solution that works to disable TASK SWITCHING on all windows platform (sourcecode dll)--------------------------------------------------------------------------------The isuue here is that there is no single way that works for all the Windows Platform. Following is the code of a DLL which takes care of this issue. This DLL exposes two functions,1. DisableAppSwitching(HWND hWnd), call this when u want to disable the task switching 2. EnableAppSwitching(void), call this to enable the task switching again.SwitchHook.h#define WIN95 0 #define WINNTSP3BELOW 1 #define WINNTSP3ABOVE 2LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); int GetWinVersion();HINSTANCE g_hDll;#pragma data_seg("Shared") HWND s_hWnd = NULL; HHOOK s_hHook = NULL; #pragma data_seg() // Exported function. BOOL WINAPI DisableAppSwitching(HWND hWnd); BOOL WINAPI EnableAppSwitching(void);SwitchHook.c#define _WIN32_WINNT 0x0400 #include <windows.h> #include <tchar.h> #include <assert.h> #include "AppSwitchHook.h" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, PVOID lpvReserved) { if(fdwReason == DLL_PROCESS_ATTACH) g_hDll = hinstDLL; return TRUE; }BOOL WINAPI DisableAppSwitching(HWND hWnd) { ATOM atom; UINT nPrevState; assert(s_hWnd != NULL || hWnd == NULL); if(s_hWnd != NULL || hWnd == NULL) return FALSE; s_hWnd = hWnd;
switch(GetWinVersion()) { case WIN95 : SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPrevState, 0); break;
case WINNTSP3BELOW: // Disabling ALT Key atom = GlobalAddAtom(_T("ALT")); RegisterHotKey(hWnd, atom, MOD_ALT, VK_MENU);
// Disabling ALT + ESCAPE Key atom = GlobalAddAtom(_T("ALTESC")); RegisterHotKey(hWnd, atom, MOD_ALT, VK_ESCAPE);
//Disabling ALT + F Key atom = GlobalAddAtom(_T("ALTF")); RegisterHotKey(hWnd, atom, MOD_ALT, 70);
// Disabling ALT + TAB atom = GlobalAddAtom(_T("ALTTAB")); RegisterHotKey(hWnd, atom, MOD_ALT, VK_TAB); break;
case WINNTSP3ABOVE: s_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, g_hDll, 0); break; } return TRUE; }BOOL WINAPI EnableAppSwitching(void) { UINT nPrevState; if(s_hWnd == NULL) return FALSE; switch(GetWinVersion()) { case WIN95 : SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPrevState, 0); break; case WINNTSP3BELOW: break; case WINNTSP3ABOVE: if(s_hHook != NULL) UnhookWindowsHookEx(s_hHook); break; } s_hWnd = NULL; s_hHook = NULL; return TRUE; }LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam; BOOL bCtrlKeyDown = FALSE; switch (nCode) { case HC_ACTION: // Check to see if the CTRL key is pressed bCtrlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
if( (pkbhs->vkCode == VK_ESCAPE && bCtrlKeyDown) || // Disable CTRL+ESC (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN) || // Disable ALT+TAB (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN) ) // Disable CTRL+ESC// Disable ALT+ESC return 1; //If WindowKey Pressed Set Focus on the window if(pkbhs->vkCode == 91 && pkbhs->scanCode == 91) { SetFocus(s_hWnd); return 1; } break; } return CallNextHookEx (s_hHook, nCode, wParam, lParam); } int GetWinVersion() { OSVERSIONINFO OSInfo; OSInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&OSInfo); if(OSInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { if(OSInfo.dwMajorVersion == 3) return WINNTSP3BELOW; if(_tcsicmp(OSInfo.szCSDVersion, _T("Service Pack 2")) == 0 || _tcsicmp(OSInfo.szCSDVersion, _T("Service Pack 1")) == 0 ) return WINNTSP3BELOW; else return WINNTSP3ABOVE; } return WIN95; } Complie this to make the dll and from your code just call the aforementioned functionsShamshu Hirani Submitted By: Shamshu Hirani (2000/09/07) Go up a level A solution that works to disable TASK SWITCHING on all windows platform (sourcecode dll) - Shamshu Hirani (2000/09/07) Modify | Add Comment | Delete
EarthWeb is a service of INT Media Group, Incorporated. Copyright 2001 INT Media Group, Incorporated. All Rights Reserved. Feedback, Advertising Info, Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,&bOld,SPIF_UPDATEINIFILE);SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,&bOld,SPIF_UPDATEINIFILE);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,&bOld,SPIF_UPDATEINIFILE);SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,&bOld,SPIF_UPDATEINIFILE);怎么没效果???????
Following is the code of a DLL which takes care of this issue. This DLL exposes two functions,1. DisableAppSwitching(HWND hWnd), call this when u want to
disable the task switching
2. EnableAppSwitching(void), call this to enable the task switching again.SwitchHook.h#define WIN95 0
#define WINNTSP3BELOW 1
#define WINNTSP3ABOVE 2LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
int GetWinVersion();HINSTANCE g_hDll;#pragma data_seg("Shared")
HWND s_hWnd = NULL;
HHOOK s_hHook = NULL;
#pragma data_seg()
// Exported function.
BOOL WINAPI DisableAppSwitching(HWND hWnd);
BOOL WINAPI EnableAppSwitching(void);SwitchHook.c#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <tchar.h>
#include <assert.h>
#include "AppSwitchHook.h"
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, PVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
g_hDll = hinstDLL; return TRUE;
}BOOL WINAPI DisableAppSwitching(HWND hWnd)
{
ATOM atom;
UINT nPrevState; assert(s_hWnd != NULL || hWnd == NULL); if(s_hWnd != NULL || hWnd == NULL)
return FALSE; s_hWnd = hWnd;
switch(GetWinVersion())
{
case WIN95 :
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPrevState, 0);
break;
case WINNTSP3BELOW:
// Disabling ALT Key
atom = GlobalAddAtom(_T("ALT"));
RegisterHotKey(hWnd, atom, MOD_ALT, VK_MENU);
// Disabling ALT + ESCAPE Key
atom = GlobalAddAtom(_T("ALTESC"));
RegisterHotKey(hWnd, atom, MOD_ALT, VK_ESCAPE);
//Disabling ALT + F Key
atom = GlobalAddAtom(_T("ALTF"));
RegisterHotKey(hWnd, atom, MOD_ALT, 70);
// Disabling ALT + TAB
atom = GlobalAddAtom(_T("ALTTAB"));
RegisterHotKey(hWnd, atom, MOD_ALT, VK_TAB);
break;
case WINNTSP3ABOVE:
s_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, g_hDll, 0);
break;
} return TRUE;
}BOOL WINAPI EnableAppSwitching(void)
{
UINT nPrevState; if(s_hWnd == NULL)
return FALSE; switch(GetWinVersion())
{
case WIN95 :
SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPrevState, 0);
break;
case WINNTSP3BELOW:
break;
case WINNTSP3ABOVE:
if(s_hHook != NULL)
UnhookWindowsHookEx(s_hHook);
break;
} s_hWnd = NULL;
s_hHook = NULL; return TRUE;
}LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
BOOL bCtrlKeyDown = FALSE; switch (nCode)
{
case HC_ACTION:
// Check to see if the CTRL key is pressed
bCtrlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
if( (pkbhs->vkCode == VK_ESCAPE && bCtrlKeyDown) || // Disable CTRL+ESC
(pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN) || // Disable ALT+TAB
(pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN) ) // Disable CTRL+ESC// Disable ALT+ESC
return 1; //If WindowKey Pressed Set Focus on the window
if(pkbhs->vkCode == 91 && pkbhs->scanCode == 91)
{
SetFocus(s_hWnd);
return 1;
}
break;
} return CallNextHookEx (s_hHook, nCode, wParam, lParam);
} int GetWinVersion()
{
OSVERSIONINFO OSInfo;
OSInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OSInfo); if(OSInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if(OSInfo.dwMajorVersion == 3)
return WINNTSP3BELOW; if(_tcsicmp(OSInfo.szCSDVersion, _T("Service Pack 2")) == 0 || _tcsicmp(OSInfo.szCSDVersion, _T("Service Pack 1")) == 0 )
return WINNTSP3BELOW;
else
return WINNTSP3ABOVE;
} return WIN95;
}
Complie this to make the dll and from your code just call the aforementioned functionsShamshu Hirani
Submitted By: Shamshu Hirani (2000/09/07)
Go up a level A solution that works to disable TASK SWITCHING on all windows platform (sourcecode dll) - Shamshu Hirani (2000/09/07)
Modify | Add Comment | Delete
EarthWeb is a service of INT Media Group, Incorporated.
Copyright 2001 INT Media Group, Incorporated. All Rights Reserved.
Feedback, Advertising Info, Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.