Solved

Disabling ALT-TAB task switching

Posted on 1998-07-25
11
540 Views
Last Modified: 2013-11-20
Hi,

I was wondering if anyone had any information on how to disable alt-tab task switching?  Here is my current approach:

BOOL CLockoutDlg::PreTranslateMessage (MSG* pMsg)
{ if ((::GetAsyncKeyState (VK_MENU) < 0) &&
      (::GetAsyncKeyState (VK_TAB) < 0))
  { return FALSE; }

  return CDialog::PreTranslateMessage (pMsg);
}

When the user presses alt-tab, the function does return FALSE like it's supposed to. However, Windows still displays the task-switching box (the one with all the icons in it which you can select by pressing the tab key).

Do you know how to disable the task switching box? Or is the alt-tab key combination checked at a system level? It seems like it is probably a child window of explorer.exe, but I have no idea what to do about it.

Can anyone provide information on how to disable it?  Any information on how to prevent it from functioning, prevent the user from using it...anything along those lines would be appreciated.

Thank you.
HelpMeAlot!
0
Comment
Question by:helpmealot
  • 7
  • 4
11 Comments
 
LVL 8

Accepted Solution

by:
trestan earned 100 total points
ID: 1319726
In 95 and NT, you can not disable it.
SPI_GETFASTTASKSWITCH
 This flag is obsolete. Previous versions of Windows use this flag to determine whether ALT+TAB fast task switching is enabled. Beginning with Windows 95 and Windows NT version 4.0, fast task switching is always enabled.
Please refer to this function for more information: SystemParametersInfo
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319727
It may be done by writing your own GINA.(That's a little dangeous to your system.)There is an example in online help:
Visual C++ -> Visual C++ Samples -> SDK Samples -> Windows NT Samples -> Security Samples -> Gina: Graphical Identification and Authentication DLL.
Look at them. May you find a trick way to do it.
0
 

Author Comment

by:helpmealot
ID: 1319728
Hmm.... This is not good.  First of all, I'm using Windows 95 (yes, yes, terrible platform, not just for programming but for everything) so the GINA approach will not work.

I was wondering if there would be a more unusual way to disable it.  If you can think of any way at all to prevent the user from using it, I would love to hear it.  Here are some of my ideas:

Perhaps some way to take the focus off the task switching box so the tab keys would be useless)?

Prevent the tab key presses from reaching Windows?

Is there a way to prevent the focus from switching from my app to another?

Or perhaps it would be possible to continually check if the
focus was on my program and if it wasn't to reset it to it?

I tried the last approach.  I set a timer to 50ms and used the following:

void CLockoutDlg::OnTimer(UINT nIDEvent)
{ RECT rect, rect2;
  CWnd *act = GetActiveWindow ();
  act->GetWindowRect (&rect);
  GetWindowRect (&rect2);

  if (rect.top != rect2.top)
  { if (rect.left != rect2.left)
    { if (rect.right != rect2.right)
      { if (rect.bottom != rect2.bottom)
        { SetActiveWindow (); }
      }
    }
  }

  CDialog::OnTimer(nIDEvent);
}

but that kept crashing whenever the focus changed.  Is there a problem with that code?

You see, all I'm trying to do is prevent the user from switching to another application, no matter how they do it.

If you can help me with that, I'll give you the points.

Thank you very much!
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319729
If you can not find a way to do it, you should already give me the points, because it is supposed not to be disabled. hah...hah...
Add this line in a proper place of your codes:
To disable:
UINT oldval;
SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,&oldval,0);
To able:
SystemParametersInfo(SPI_SCREENSAVERRUNNING,0,&oldval,0);
This will disable all the serial key. Work on 95 not NT. But you are so lucky that you are running applications in 95.
0
 

Author Comment

by:helpmealot
ID: 1319730
What do you mean when you say "serial key"?  I don't know what they are and I have no idea how they could affect anything.

Why should I put in SPI_SCREENSAVERRUNNING?  In the documentation, it said that this was used internally by Windows and that applications should not use it.

Can you help me with the code below?
void CLockoutDlg::OnTimer(UINT nIDEvent)
{ RECT rect, rect2;
  CWnd *act = GetActiveWindow ();
  act->GetWindowRect (&rect);
  GetWindowRect (&rect2);

  if (rect.top != rect2.top)
  { if (rect.left != rect2.left)
    { if (rect.right != rect2.right)
      { if (rect.bottom != rect2.bottom)
        { SetActiveWindow ();
          // SetActiveWindow or SetFocus, both crash.
        }
      }
    }
  }

  CDialog::OnTimer(nIDEvent);
}

Why does it crash whenever the focus changes from my application to another?

Thanks.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:trestan
ID: 1319731
Why not try it? I am so happy when I make it work in my program. Why don't you just copy and paste the code in your program? There is no side effect to use it in an application. You want me to spend double time to debug your code? If you send me the whole code, it will be easier to find the problem because I can use the debug tool. However, I have provided you a solution right to the point of your question after trying a lot of time.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319732
The algorithm is that the screensaver will run full screen. Setting the system that it is running will prevent the task switching from the current application to others. That is just what you want.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319733
Hi, I searched codeguru and MSKB. Actually I found that this ia the way recommended by both. At least, you should trust MS otherwise you have discard Windows at all. So don't hesitate any more. Go head.
0
 

Author Comment

by:helpmealot
ID: 1319734
Okay, now I see, you weren't making it very clear what was happening before.  But I still have a little problem.  I can disable the task switching using:

SystemParametersInfo (SPI_SCREENSAVERRUNNING, 1, &m_ScreenSaverOn, 0);

but I can't seem to re-enable it.
The line:
SystemParametersInfo (SPI_SCREENSAVERRUNNING, 0, &m_ScreenSaverOn, 0);

doesn't fix it.

In fact, even if I let the screen saver come on, and then move the mouse so it quits, task switching is STILL disabled.

Now what?
0
 

Author Comment

by:helpmealot
ID: 1319735
Oh sorry, turns out it was a bug in my program.  Never mind.  Your idea worked great.  Thank you very very much.  I've awarded you the points.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319736
>>anything along those lines would be appreciated.
>>.  Your idea worked great.  Thank you very very much.  
Then what are you thinking when you give me a "C"? Do you know how much time I have spent to provide you this answer?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now