Hi kh,
Thanks for your post!
I have seen that you posted a question in
microsoft.public.win32.programmer.ui newsgroup. Let's continue our
discussion here, since you are using C#.
To detect Alt+Tab key, we can use SPY++ tool to monitor the window to see
what messages are posted/sent for Alt+Tab key combination. I know you must
have seen WM_CANCELMODE message and you thought WM_CANCELMODE is the
correct message for the indication. The answer is no.
In Win32 world, every UI thread will have an message queue, and all the
windows messages to this thread will be queued in it. Then, every message
structure will have an hwnd field(please refer to "MSG Structure" in MSDN)
to indicate which window in that thread will receive the message.
Let's take notepad for example, notepad main thread has 3 windows: notepad
main window, Edit window, status bar hidden window. The latter 2 windows
are child windows of the first one. When we are pressing Alt+Tab key,
because they are system key, there will be WM_SYSKEY*(up or down) messages
be sent to the currently focused window.(In notepad, it will almost always
be Edit window, because the other 2 windows can not have focus). So, if we
use spy++ to monitor main window messages, we will not see any keyboard
messages. The keyboard messages have been sent to edit window. If you use
spy++ to monitor edit window, you will see the keyboard messages we want.
Then, what is the reliable way to monitor the keyboard messages in the main
GUI thread without knowing which is the focused control? The answer is
local windows hook. Below is a sample VB article regarding how to use
low-level Keyboard hook WH_KEYBOARD_LL to do this:
"Managing Low-Level Keyboard Hooks with the Windows API"
http://www.codeguru.com/vb/gen/vb_sy...cle.php/c4829/
Note: although this article did not use WH_GETMESSAGE hook to monitor the
messages, I think we can use WH_GETMESSAGE hook to monitor all the messages
in the hooked GUI thread, and check for the Alt+key messages, but I did not
find a sample regarding using message hook.
To use windows hook in .Net, please refer to the KB below:
"How to set a Windows hook in Visual C# .NET"
http://support.microsoft.com/kb/318804/EN-US/
Regarding your last question, the correct way to hook parent form message
in usercontrol is also using local windows message hook.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.