473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Detecting Alt-Tab

kh
My app filters windows messages because of some custom window functionality I
have implemented. Does my window receive a message when the user selects
Alt-Tab? If so which message?

Many thanks

kh
May 4 '06 #1
5 6473
Hi,

Dont know if it does, it's very easy to check though, just expand the
winproc and see what messages you get when you press alt+tab , for sure you
will lose focus and will be no longer the foremost window
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"kh" <kh@newsgroups.nospam> wrote in message
news:11**********************************@microsof t.com...
My app filters windows messages because of some custom window
functionality I
have implemented. Does my window receive a message when the user selects
Alt-Tab? If so which message?

Many thanks

kh

May 4 '06 #2
kh
thanks. on a related issue, if i subclass UserControl, can this control
listen to messages which were meant for it's parent form?
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Dont know if it does, it's very easy to check though, just expand the
winproc and see what messages you get when you press alt+tab , for sure you
will lose focus and will be no longer the foremost window
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"kh" <kh@newsgroups.nospam> wrote in message
news:11**********************************@microsof t.com...
My app filters windows messages because of some custom window
functionality I
have implemented. Does my window receive a message when the user selects
Alt-Tab? If so which message?

Many thanks

kh


May 4 '06 #3
>My app filters windows messages because of some custom window functionality I
have implemented. Does my window receive a message when the user selects
Alt-Tab? If so which message?


Do you mean during the Alt-Tab'ing (while cycling through the
different windows) or after the keys have been released and the active
application actually changes?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 4 '06 #4
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.

May 5 '06 #5
"kh" wrote:
My app filters windows messages because of some custom window functionality I
have implemented. Does my window receive a message when the user selects
Alt-Tab? If so which message?


When the user presses Alt+Tab while your application is focused, the
operating system intercepts that key sequence and focuses another window
before your window receives the entire key sequence. Therefore, the best way
to detect Alt+Tab reliably is to create a WH_KEYBOARD_LL global keyboard hook
that can see keyboard events across all applications.

--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com
May 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve | last post by:
Hi everyone, I'm trying to make an openGL app (in visual c++) that allows the use of two mice simultaneously. Does anyone know if this is possible, how I might go about doing it or how I could...
1
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list...
1
by: jasper | last post by:
hi, i am trying to make a very simple program that will just detect and output your currently connected IDE devices. It will look something like this: IDE PRIMARY MASTER: IDE PRIMARY SLAVE:...
12
by: Wladimir Borsov | last post by:
On one of my web pages there is an java applets which works fine on my computer. However I noticed on some other computer that the run of java applets are disabled. I got an error message...
13
by: ima | last post by:
I've been studying a great book on css and now that I've put together a few pages using it, I'm finding out that my book needed one more very important chapter. Introducing css in the real world. ...
2
by: MackS | last post by:
Hello I am writing a small app to learn how to use the curses module. I would like to know how I can get "composite" key presses, eg, Control+Q. Currently I am looking at the following code...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
9
by: aljamala | last post by:
Hi, I am looking for different ways this can be accomplished, I can think of a way, but I'm not too happy with it... The Problem: Users with multiple accounts can switch between them;...
4
imarkdesigns
by: imarkdesigns | last post by:
hello again guys... im in trouble here in my coding which i cannot open a link for the end user of the page in the site where there is a portal thru the folder... anyway, here is my code... ...
9
by: raknin | last post by:
Hi, I want to detect when the user close a window through the X button or ALT-F4 or when the user go to another page and leave my page. I try to use the onuload and on unloadbeore but it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.