[gui-talk] Fwd: PostMessage Example

Steve Pattison srp at internode.on.net
Thu May 14 02:15:43 UTC 2009


 From:    Aaron Smith aaron at gwmicro.com
 To:      gw-scripting at gwmicro.com

Greetings,

I recently discovered a spiffy way to switch between installed keyboard 
languages using the Window object's PostMessage method, and though I'd 
share it with you.

PostMessage takes three parameters: the message to send, wParam data for 
the message, and lParam data for the message.

The message that we want to post, in this case of keyboard languages, is 
WM_INPUTLANGCHANGEREQUEST. MSDN defines this message as the message that 
"is posted to the window with the focus when the user chooses a new 
input language." So we're going to send the message to signal that the 
user has requested a keyboard language change (only we're not doing it 
through a keyboard hotkey, or through the language toolbar).

WM_INPUTLANGCHANGEREQUEST has a constant value (represented in hex) of 
&H50 in VBScript.

The wParam for WM_INPUTLANGCHANGEREQUEST is 0.

The lParam for WM_INPUTLANGCHANGEREQUEST is the locale id (in hex) for 
the keyboard language you want to switch to.

Armed with that knowledge, let's try an example. Say you have the 
English keyboard layout installed, and the Polish keyboard layout 
installed. Using PostMessage, you can switch to the Polish layout from 
the English layout by doing:

Window.PostMessage &H50, 0, &H415

You can then switch back to English with:

Window.PostMessage &H50, 0, &H409

Window, in this case, needs to be the focus window that you want to 
switch the keyboard language for. Windows will remember keyboard layouts 
for specific windows. So if you set the Wordpad keyboard layout to 
Polish, and set focus to Notepad, the keyboard layout will switch back 
to English automatically. And when focus goes back to Wordpad, the 
Polish keyboard layout will be selected.

Enjoy!

Aaron

-- 
To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.

Aaron Smith
GW Micro
Phone: 260/489-3671
Fax: 260/489-2608
WWW: http://www.gwmicro.com
FTP: ftp://ftp.gwmicro.com
Technical Support & Web Development

Regards Steve
Email:  srp at internode.on.net
MSN Messenger:  internetuser383 at hotmail.com
Skype:  steve1963




More information about the GUI-Talk mailing list