Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Sat, 31 May 2008 22:14:00 -0700,    group: microsoft.public.win32.programmer.ui        back       


WM_CHAR Unicode and Code Page   
I have an app. that uses both unicode and code pages.
The app is not using #define _UNICODE
Currently, I get the value of an input character with WM_CHAR.  Because 
_UNICODE is not defined, WM_CHAR always returns the code page character value 
of a keystroke.

I need to get code page value for the char AND the unicode value (I need 
UTF16) in one shot, where that is possible.  How can I do that?

Thanks, Tony Duff
date: Sat, 31 May 2008 22:14:00 -0700   author:   Tony Duff

Re: WM_CHAR Unicode and Code Page   
> I need to get code page value for the char AND the unicode value (I need 
> UTF16) in one shot, where that is possible.  How can I do that?

You can't.

The windows should be Unicode in order to receive Unicode messages.

Using RegisterClassW (or RegisterClassExW) is enough for Windows to believe 
that your window is Unicode (returning TRUE for IsWindowUnicode).

But is not enough for all things to work right.
You also need to create the window as Unicode
(using CreateWindowW or CreateWindowExW) and
"clean the message pump" (using GetMessageW, DispatchMessageW and
DefWindowProcW)

Overall, maintaining a mixed application is a major pain.
Moving to Unicode all the way (compiling with UNICODE and _UNICODE)
pays back fast enough to justify the effort.

The task looks more difficult than it really is.
You can start from here:
    http://www.mihai-nita.net/article.php?artID=tounicode



-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Sun, 01 Jun 2008 00:31:43 -0700   author:   Mihai N.

Re: WM_CHAR Unicode and Code Page   
Thanks for your reply.  I am in my own process of conversion to Unicode, 
thanks anyway.

I understand now and can make WM_CHAR give me unicodes by make creating the 
window as wide, thanks.

However, what I need to do is get both a code page character value AND a 
unicode character value.  How can I do that?

Also, is there a way to get a Unicode in a window without the window being 
created as wide?

Specific answers would be greatly appreciated.
Thankyou,
Tony Duff

"Mihai N." wrote:

> > I need to get code page value for the char AND the unicode value (I need 
> > UTF16) in one shot, where that is possible.  How can I do that?
> 
> You can't.
> 
> The windows should be Unicode in order to receive Unicode messages.
> 
> Using RegisterClassW (or RegisterClassExW) is enough for Windows to believe 
> that your window is Unicode (returning TRUE for IsWindowUnicode).
> 
> But is not enough for all things to work right.
> You also need to create the window as Unicode
> (using CreateWindowW or CreateWindowExW) and
> "clean the message pump" (using GetMessageW, DispatchMessageW and
> DefWindowProcW)
> 
> Overall, maintaining a mixed application is a major pain.
> Moving to Unicode all the way (compiling with UNICODE and _UNICODE)
> pays back fast enough to justify the effort.
> 
> The task looks more difficult than it really is.
> You can start from here:
>     http://www.mihai-nita.net/article.php?artID=tounicode
> 
> 
> 
> -- 
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
date: Sun, 1 Jun 2008 02:39:00 -0700   author:   Tony Duff

Re: WM_CHAR Unicode and Code Page   
> However, what I need to do is get both a code page character value AND a 
> unicode character value.  How can I do that?

Once you get the Unicode value, you can convert it to what you want
by using WideCharToMultiByte


> Also, is there a way to get a Unicode in a window without the window being 
> created as wide?

Technically, not the CreateWindow matters, is RegisterClass that's important.
If you use RegisterClassW with CreateWindowA, Windows will still report true
for IsWindowUnicode.
But if the "message pump is not clean" you end up with all kind of surprises.
It's asking for future trouble :-)


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Sun, 01 Jun 2008 16:29:27 -0700   author:   Mihai N.

Re: WM_CHAR Unicode and Code Page   
Thanks.

I have the window unicoded and successfully get unicodes.  However, I am 
having trouble converting them to ANSI codes.

I have used WideCharToMultiByte.
I am on a US Windows XP system with both US and Russian keyboards installed.
I change to the russian keyboard, input a character and run it through 
WideCharToMultiByte.

If I explicitly give 1251 (russian ANSI codepage) for the first param of 
WideCharToMultiByte, the conversion from the unicode to the single byte char
happens perfectly well.  If I try anything else, including the default 
option for WideCharToMultiByte and also the current thread ACP option, it 
sends me back the default character for couldn't convert, a question mark.

I have read all the keyboard documentation and tried everything available to 
try to get the CP for the russian keyboard when it is active but everything 
returns the US OEM ANSI code.

What am I doing wrong?  Or, more explicitly, I not only need the 
WideCharToMultiByte function but I also need the current keyboards ANSI code 
page.  How do I get both?

Tony Duff



"Mihai N." wrote:

> 
> > However, what I need to do is get both a code page character value AND a 
> > unicode character value.  How can I do that?
> 
> Once you get the Unicode value, you can convert it to what you want
> by using WideCharToMultiByte
> 
> 
> > Also, is there a way to get a Unicode in a window without the window being 
> > created as wide?
> 
> Technically, not the CreateWindow matters, is RegisterClass that's important.
> If you use RegisterClassW with CreateWindowA, Windows will still report true
> for IsWindowUnicode.
> But if the "message pump is not clean" you end up with all kind of surprises.
> It's asking for future trouble :-)
> 
> 
> -- 
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
date: Mon, 2 Jun 2008 01:36:00 -0700   author:   Tony Duff

Re: WM_CHAR Unicode and Code Page   
> What am I doing wrong?  Or, more explicitly, I not only need the 
> WideCharToMultiByte function but I also need the current keyboards
> ANSI code page.  How do I get both?

Working with the code page matching the keyboard is problematic.
It is not unicode, and it is not ANSI (the current system code page).
So most of the APIs will handle that wrong.

But if you are sure this is what you need:
 1. GetKeyboardLayout
    "The low word contains a Language Identifier for the input language
    and the high word contains a device handle to the physical layout
    of the keyboard"
 2. Make a LCID using MAKELCID( theKbdLangIdentifier, SORT_DEFAULT )
    (the sort part does not affect the ansi code page)
 3. Use GetLocaleInfo( lcid, LOCALE_IDEFAULTANSICODEPAGE, ... )
    to get the ANSI code page matching the keyboard locale


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Mon, 02 Jun 2008 19:52:31 -0700   author:   Mihai N.

Re: WM_CHAR Unicode and Code Page   
OK, thanks, I have that working now.

Next comes logical font creation.

1) As I see it, logfont API's belong to the code page era.  Is there 
something new for unicode that I have missed?

2) Specifically, logfonts demand a code page be provided.  Is there a 
generic code page number that will produce a logfont from a specified font 
that will have all unicode glyphs that are in the font in the logfont?

Thanks,
Tony Duff

"Mihai N." wrote:

> > What am I doing wrong?  Or, more explicitly, I not only need the 
> > WideCharToMultiByte function but I also need the current keyboards
> > ANSI code page.  How do I get both?
> 
> Working with the code page matching the keyboard is problematic.
> It is not unicode, and it is not ANSI (the current system code page).
> So most of the APIs will handle that wrong.
> 
> But if you are sure this is what you need:
>  1. GetKeyboardLayout
>     "The low word contains a Language Identifier for the input language
>     and the high word contains a device handle to the physical layout
>     of the keyboard"
>  2. Make a LCID using MAKELCID( theKbdLangIdentifier, SORT_DEFAULT )
>     (the sort part does not affect the ansi code page)
>  3. Use GetLocaleInfo( lcid, LOCALE_IDEFAULTANSICODEPAGE, ... )
>     to get the ANSI code page matching the keyboard locale
> 
> 
> -- 
> Mihai Nita [Microsoft MVP, Visual C++]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email
>
date: Wed, 4 Jun 2008 19:45:00 -0700   author:   Tony Duff

Re: WM_CHAR Unicode and Code Page   
> 1) As I see it, logfont API's belong to the code page era.  Is there 
> something new for unicode that I have missed?

No, logfont is not only about code pages.
You should be carefull that LOGFONT is just a macro, and if you don't
define _UNICODE and UNICODE that is LOGFONTA.
So you have to use explicitely use LOGFONTW. So lfFaceName will be Unicode.



> > 2) Specifically, logfonts demand a code page be provided.  Is there a 
> generic code page number that will produce a logfont from a specified font 
> that will have all unicode glyphs that are in the font in the logfont?

What you need for a logfont is not a code page, but a charset.
Different beast :-) See here for the lingo:
http://www.mihai-nita.net/article.php?artID=20060806a

For Unicode text you should specify DEFAULT_CHARSET

"DEFAULT_CHARSET should be used when displaying a string of
characters encoded with Unicode."
See the "DEFAULT_CHARSET in LOGFONT" section in here
http://www.microsoft.com/globaldev/getwr/steps/wrg_font.mspx
In fact, the whole article is a good read.

In general, for UI I just go with "MS Shell Dlg" or "MS Shell Dlg2"
Or (for CJK) select directly a font for the targeted language.
For documents and othere things like this is probably better to allow the 
user to select what they want.


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Thu, 05 Jun 2008 00:23:02 -0700   author:   Mihai N.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us