SendInput-ing Unicode characters to Unicode windows that have an ANSI parent

SendInput-ing Unicode characters to Unicode windows that have an ANSI parent

Post by Timo Kunz » Sat, 07 Apr 2007 00:34:01


Hi,

I've an Unicode Edit control that sits on an ANSI dialog. Now I'm using
the following code to simulate input of an Unicode character:

INPUT ipt[2];
ipt[0].ki.wVk = 0;
ipt[0].ki.wScan = 931;
ipt[0].ki.dwFlags = KEYEVENTF_UNICODE;
ipt[0].ki.time = 0;
ipt[0].ki.dwExtraInfo = 0;
ipt[0].type = INPUT_KEYBOARD;

ipt[1].ki.wVk = 0;
ipt[1].ki.wScan = 931;
ipt[1].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_UNICODE;
ipt[1].ki.time = 0;
ipt[1].ki.dwExtraInfo = 0;
ipt[1].type = INPUT_KEYBOARD;

SendInput(2, ipt, sizeof(INPUT));

This should insert the Greek letter Sigma into the edit control, but
instead an ANSI "S" is inserted. If the edit control sits on an Unicode
dialog, I get the Greek Sigma. The edit control itself is Unicode in
both cases.

So how do I send Unicode input to Unicode windows that sit on ANSI dialogs?

Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
 
 
 

SendInput-ing Unicode characters to Unicode windows that have an ANSI parent

Post by Mihai N » Sat, 07 Apr 2007 16:46:31

> I've an Unicode Edit control that sits on an ANSI dialog. Now I'm using
How do you create that edit control?
How do you check that it is indeed Unicode?

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.yqcomputer.com/
------------------------------------------
Replace _year_ with _ to get the real email

 
 
 

SendInput-ing Unicode characters to Unicode windows that have an ANSI parent

Post by Mihai N » Sat, 07 Apr 2007 16:51:35

> This should insert the Greek letter Sigma into the edit control, but

Sorry, I did not pay atention.
Even if the control is Unicode, is not enough.
SendInput sends the messages to the active window. That is the dialog.
The control is a child, has focus, but is not the active window.
So all your messages go thru the dialog's message pump, which is ANSI
(because the dialog is ANSI).

Depending on what you really need, you might have several solutions:
- send the WM_CHAR messages directly to the control
(so no SendInput)
- just call SetWindowText (or WM_SETTEXT) with the control handle

In general it is not possible to completely simulate keyboard input.
You will have a lot of problems for languages that use IME, for instance.


--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.yqcomputer.com/
------------------------------------------
Replace _year_ with _ to get the real email