Sunday, January 14, 2007

Preventing a window from receiving focus on click in Windows

Ok, you may ask yourself how come I'm writing a Win32 programming howto in a blog labeled "Linux and Free Software". The answer is quite simple:
I ran upon this problem, and google could not find the answer. Since I like the "share alike" ideas, I'm documenting the solution somewhere google-visible.

Warning - highly technical post ahead:

Explanation of problem:
Sometimes you may want to create a window that does not receive focus when clicked. The most simple example is an on-screen virtual keyboard. It's an applet that displays a keyboard on screen, and pressing the keys with the mouse produces the relevant key, as if pressed on the keyboard.

If such an applet got focus when it was clicked, then the key produced would go to the window with the focus - the on screen keyboard. Such an application must receive the mouse clicks without activating the application's window.

Like I said above, I searched all over the web for a solution, without much success, despite the fact that I know, for a fact, that Microsoft's own "on screen keyboard" (Start-Programs-Accessories-Accessibility on windows 2000 and XP) does just that.

After a lot of looking around, I found out the solution. Starting with Windows 2000, CreateWindowEx can receive an extended style called "WS_EX_NOACTIVATE". Guess what it's doing. No, guess.... :-)

Let's hope that the internet just got smarter by one tiny little bit.



Post a Comment

<< Home