真是棘手,紧急求教如何在窗口类的WM_CHAR消息中得到输入的中文字符???

Barks 2006-07-14 09:40:08
WM_CHAR消息的响应函数是这样的
void CWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
}
nChar参数可以得到输入的中文字符的ASCII码,但是我用任一种中文输入法输入多个中文字符和OnChar函数得到的中文字符有出入阿,一个中文字符对应两个字节,输入多个中文字符时好像总是少了一些字符,有谁知道这是怎么回事,或者有谁知道有这方面的例程啊?
...全文
707 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
javaecho 2010-06-27
  • 打赏
  • 举报
回复
说的具体一点,我一直用vs2008,采用默认的unicode 字符集,这方面的问题遇到不少,基本上都解决了
simonjp 2006-07-22
  • 打赏
  • 举报
回复
还有一个方便的方法,就是你采用UNICODE编译,这样收到的中英文都是2个byte,可以直接处理
当然要看你的工程而定
cpio 2006-07-21
  • 打赏
  • 举报
回复

是这样的,如果输入中文的话,一个汉字会收到两次这个消息

他们加一起就是一个汉字了

小李匪盗 2006-07-21
  • 打赏
  • 举报
回复
MultiByteToWideChar:单字节转化为双字节,ANSCII->UNICODE
Barks 2006-07-14
  • 打赏
  • 举报
回复
MultiByteToWideChar这个函数是什么意思,怎么用?楼上的能具体讲解以下吗?
Barks 2006-07-14
  • 打赏
  • 举报
回复
不太一样,我的意思是说切换输入法后,是否可以通过某个函数捕捉到输入法是否改变到了IME状态。
Stefine 2006-07-14
  • 打赏
  • 举报
回复
那再请教一下有没有判断当前输入状态是否是IME的WINDOWS API函数啊?

你是说想有没有API函数来判断当前输入的是中文字符还是非中文字符吧

中文编码的第一个字节最高位恒定为1,所以可以进行 &0x80 来判断

不晓得你是不是问这个
Stefine 2006-07-14
  • 打赏
  • 举报
回复
呵呵,见识了

也可以试试转换后看看

MultiByteToWideChar
Barks 2006-07-14
  • 打赏
  • 举报
回复
那再请教一下有没有判断当前输入状态是否是IME的WINDOWS API函数啊?
DentistryDoctor 2006-07-14
  • 打赏
  • 举报
回复
没听说过三或四字节的。
Barks 2006-07-14
  • 打赏
  • 举报
回复
也就是说如果输入了一个双字节的中文字符的话,就相当于是发送了一个WM_IME_CHAR消息和两个WM_CHAR消息,有没有可能有的字符是三个或四个字节的呢,因为WParam的大小是四个字节
DentistryDoctor 2006-07-14
  • 打赏
  • 举报
回复
WM_IME_CHAR
The WM_IME_CHAR message is sent to an application when the IME gets a character of the conversion result. Unlike the WM_CHAR message for a non-Unicode window, this message can include double-byte as well as single-byte character values. For a Unicode window, this message is the same as WM_CHAR.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
WM_IME_CHAR, // message
WPARAM wParam, // character code
LPARAM lParam // key indicators
);
Parameters
wParam
DBCS: Specifies a single- or double-byte character value. For a double-byte character, (BYTE)(wParam >> 8) contains the lead byte. Note that the parentheses are necessary because the cast operator has higher precedence than the shift operator.
Unicode: Specifies a Unicode character value.

lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown following. Bit Meaning
0-15 Repeat count: Since the first byte and second byte is continuous, this is always 1.
16-23 Scan code: Scan code for a complete Asian character.
24 Extended key
25-28 Not used.
29 Context code.
30 Previous key state.
31 Transition state.


Remarks
For a non-Unicode window, if the WM_IME_CHAR message includes a double-byte character and the application passes this message to DefWindowProc, the IME converts this message into two WM_CHAR messages, each containing one byte of the double-byte character.

Requirements
Windows NT/2000/XP: Included in Windows NT 4.0 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Imm.h; include Windows.h.

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧