tags:

views:

288

answers:

2

I have an ATL control that I want to be Unicode-aware. I added a message handler for WM_UNICHAR:

MESSAGE_HANDLER( WM_UNICHAR, OnUniChar )

But, for some reason, the OnUniChar handler is never called.

According to the documentation, the handler should first be called with "UNICODE_NOCHAR", on which the handler should return TRUE if you want to receive UTF-32 characters. But, as I said, the handler is never called.

Is there anything special that needs to be done to activate this?

A: 

You message loop has to use TranslateMessage to create WM_UNICHAR notifications from WM_KEYDOWN events.

Judge Maygarden
Thanks for the info, but the TranslateMessage() seems to be called by the AfxInternalPumpMessage() function. There is probably something else wrong...
Martin Cote
+2  A: 

What are you doing that you think should generate a WM_UNICHAR message?

If your code (or the ATL code) ultimately calls CreateWindowW, then your window is already Unicode aware, and WM_CHAR messages will be UTF-16 format.

The documentation is far from clear on when, exactly, a WM_UNICHAR message gets generated, but from what I can gather in very limited poking around on Google Groups and on the Internet it looks like it gets sent by 3rd party apps and not by Windows itself, unless the Window is an ANSI window (CreateWindowA and all that). Have you tried manually sending a WM_UNICHAR message to your window to see what happens? If you get the message then there's nothing wrong with your message dispatch code and there's just nothing happening that would cause WM_UNICHAR. You can also check with Spy++ and see whether you're getting that message, though I suspect it's just not being sent.

Joel
My application is compiled with multi-byte character set. Using the Unicode character set is not an option. According to the docs, the message should be generated automatically, unless I don't understand something...
Martin Cote
Finally, you are perfectly right. The WM_UNICHAR message is not sent natively by Windows, only by 3rd party applications. Thanks for the clarification.
Martin Cote