views:

297

answers:

3

I think this problem should be easy to solve, and I'm bringing it here because I really feel like I've looked everywhere for a solution.

My code is written in C# and should simply over write the Alt-Tab hotkey. This line works in XP but return false in 7:

RegisterHotKey(handle, ID__ALT_TAB, MOD_ALT, VK_TAB)); 

I know that Windows 7 now requires that I unregister the hotkey before I can register my new one, and this is where the problem lies. When I check on the last error code I get code 1409, meaning the hotkey already exists. However if I call this line before the one above:

UnregisterHotKey(handle, ID__ALT_TAB)); 

That line fails and the last error code is set to 1419, meaning no such hotkey exists. These lines do work in XP, and I am able to register a hotkey and then unregister it. I beleive it is because I am attempting to unregister a hotkey with the wrong ID, as ID_ALT_TAB is self defined. I havent been able to find the correct ID of the Windows level Alt-Tab HotKey. Any help or general pointers would be greatly appreciated.

A: 

Did you also run the program as administrator (rather than just being logged in as Admin)? After XP programs don't necessarily get admin rights just because the user is admin, you could try right-click Run As Administrator (or similar).

Jonathan
Run as adminn came back with the same results. What I am looking for here is how to unregister a windows level hotkey that I have not created and therefore dont have the ID.The existing code should run and fail in Windows7 to register. This is mentioned in the documention for registerHotKey; http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx
Ward
+1  A: 

I don't think there is a way to do this. Not to mention, even if you manage to somehow register your hotkey overtop of the existing one, what happens when your application exits? Suddenly, there's no Alt-Tab at all.

Rather, I'd go with another shortcut to trigger your replacement. Maybe Ctrl-Alt-Tab?

Mike Caron
+1  A: 

Not sure if you've already seen this? Might have to a little work with C here. I would think you'd be able to intercept the Alt+Tab stroke using this code and then do whatever you wish in it's place, but I'm not sure.

EDIT: Also see this for some older VB work that you might have to translate into C#.

Randster
A friend of mine has used the vb code linked above and it worked.You'll need to have a way of handling unexpected termination of your program though. The last thing you'd want to happen is to leave your computer with no Alt-Tab.
Alex Essilfie