Why is my WM_UNICHAR handler never called?

依然范特西╮ 提交于 2020-01-15 03:43:08

问题


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?


回答1:


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.




回答2:


My experience today is that Spy++ does not give correct results for WM_CHAR in a Unicode proc. I am getting ASCII translations or '?' showing in the Messages list, even if I view Raw (not Decoded) arguments. The debugger shows wParam to be the Unicode code point though.




回答3:


void CMFCProView::OnUniChar (UINT xChar, UINT nRepCnt, UINT nFlags)
void CMFCProView::OnChar    (UINT xChar, UINT nRepCnt, UINT nFlags)

The range of UINT (unsigned int) is 0 to 4294967295 decimal (16-bit).

OnChar can do whatever you want OnUniChar to do. Click an English character A on the softkeyboard, then OnChar will receive 0x0041. Click a CJKV 一 (one), then OnChar will receive 0x4E00. So we don't need OnUniChar in App.



来源:https://stackoverflow.com/questions/378296/why-is-my-wm-unichar-handler-never-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!