C++ – Why is the WM_UNICHAR handler never called


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


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?

Best Solution

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.