zhangyunchao
asked on
how to disable alt+tab ,alt+f4
how to disable alt+tab ,alt+f4
Hi,
RAVID: I think your solution only works for ALT-F4, not for ALT-TAB.
zhangyunchao, to disable ALT-TAB you can register ALT-TAB as a hotkey of your application using RegisterHotKey() like this:
CMainFrame::Create(...)
{
...
if( !RegisterHotKey( m_hWnd, 1, MOD_ALT, VK_TAB ) )
{
TRACE( "Error occured with RegisterHotKey()\n", GetLastError() );
}
...
}
hopt that helps,
ZOPPO
RAVID: I think your solution only works for ALT-F4, not for ALT-TAB.
zhangyunchao, to disable ALT-TAB you can register ALT-TAB as a hotkey of your application using RegisterHotKey() like this:
CMainFrame::Create(...)
{
...
if( !RegisterHotKey( m_hWnd, 1, MOD_ALT, VK_TAB ) )
{
TRACE( "Error occured with RegisterHotKey()\n", GetLastError() );
}
...
}
hopt that helps,
ZOPPO
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi cclain,
your suggestion only works with Win9x, not with WinNT, so I think you should not post this as answer unless you know zhangyunchao only needs it for Win9x
ZOPPO
your suggestion only works with Win9x, not with WinNT, so I think you should not post this as answer unless you know zhangyunchao only needs it for Win9x
ZOPPO
You're right, but I'm new here and I think I don't understand exactly the comment-answer rules.
I thought comments were supposed to comment answers and to ask (zhangyunchao) questions. Moreover, I've seen a lot of answers in the comment section, so how these people get experts points ? Eventualy zhangyunchao can reject my answer, and you still can add comments, so I don't prevent someone from getting points...
Anyway my suggestion only works with Win9x. I would use a hook with WinNT by calling SetWindowsHook
Here's a sample that disable Alt+Tab
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 ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1; break; } default:
break; } return CallNextHookEx (hHook, nCode, wParam, lParam);
}
I thought comments were supposed to comment answers and to ask (zhangyunchao) questions. Moreover, I've seen a lot of answers in the comment section, so how these people get experts points ? Eventualy zhangyunchao can reject my answer, and you still can add comments, so I don't prevent someone from getting points...
Anyway my suggestion only works with Win9x. I would use a hook with WinNT by calling SetWindowsHook
Here's a sample that disable Alt+Tab
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 ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1; break; } default:
break; } return CallNextHookEx (hHook, nCode, wParam, lParam);
}
Yes, of course a global hook would be a way too, but I think it's quite a overhead ...
ZOPPO
ZOPPO
I think we really need more explanations. Only zhangyunchao knows...
ASKER
but ZOPPO is right too.
In the resource select the Acceslerator option and add a new accelerator with the alt option ticked and the key as VK_F4 and give some ID say ID_MY_ALY_F4 now through class wizard map the command for this ID and add the code u want.
Try similar way for alt+tab.
Hope this helps