views:

631

answers:

2

A friend is trying to write something not entirely unlike the old wintutor.exe from the olden days of Windows 3.1. It's meant to show some complete newbs the ropes of using WinXP, and the tutorial needs to respond to Alt-Tab and such for their own protection. How do you do this in C# Winforms?

+2  A: 

I have no first-hand experience doing this and I don't know if there's an easier way now, but this CodeProject article discusses using C# to tap low-level Windows APIs that will trap keyboard strokes like Alt-Tab.

Hope this helps.

thinkzig
This looks convincing...
Kawa
+2  A: 

Serious question: do you really need to change what Alt-Tab does if you're teaching someone to use Windows?

It's kind of a basic tool of the OS, and it would be quite misleading for their introduction to the OS to behave differently to normal in such a fundamental way.

It would be much simpler to just show them a video explaining what that key combination does.

Some background reading.

If you want to lock down the GUI (as is sometimes done by the demo apps that run in computer stores), you could have a timer running that constantly forces your app to be the foreground. Some info here.

Daniel Earwicker
The -apparent- behavior would match.
Kawa
So what would you actually do in response to the Alt+Tab?
Daniel Earwicker
Switch between fake tutorial windows ofcourse!
Kawa
Constantly forcing your application to the foreground is even more annoying. Focus stealing is very,very annoying (I hate it when I am typing in Word and another application steals the focus). Capturing Alt-Tab is not a very bad in principle (for example if alt-tab breaks your application or alt-tab should not be possible like cash register software). I wish that some games disable alt-tab, because switching back might take some while and sometimes breaks. Crucial behaviour like ctr-alt-delete is always captured by the system (cannot be "blocked") and is enough to quit out of your program.
Gertjan
@Gertjan - of course. Note the part that says "If you want to lock down the GUI (as is sometimes done by the demo apps that run in computer stores)"...
Daniel Earwicker