WinAPI:如何在自定义编辑控制中处理键盘输入 [英] WinAPI: How to process keyboard input in custom edit control

查看:210
本文介绍了WinAPI:如何在自定义编辑控制中处理键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用Windows API在C ++中创建自己的编辑控件(多行文本框)。这是很好,但我有点困惑的一件事。

So i'm creating my own edit control (multi-line textbox) in C++ using the windows API. It's going pretty well, but i'm a bit confused about one thing.

首先,控件被构建为能够处理unicode,所有的输入将是转换为unicode。换句话说,所有输入将被存储为wchar_t。

First off, the control is being built to be able to handle unicode and all input will be converted to unicode. In other words, all input will be stored as wchar_t.

我困惑的是键盘输入处理的消息。 MSDN有以下窗口通知:

What i'm confused about is which message to process for keyboard input. MSDN has the following window notifications:

WM_CHAR

WM_KEYDOWN

WM_UNICHAR

WM_CHAR
WM_KEYDOWN
WM_UNICHAR

和其他人,但我相信这是我需要处理的三个之一。我的猜测是WM_UNICHAR,但文档有点不清楚。此外,在查看VKcodes时,我看到了这一点:

And others, but i believe it's one of these three that i need to process. My guess would be WM_UNICHAR, but the documentation is a bit unclear about it. Also, upon looking over the VKcodes, i saw this:


VK_PACKET

0xE7

用于传递Unicode字符,就像它们是击键一样。 VK_PACKET键是用于非键盘输入方法的32位虚拟键值的低字。有关详细信息,请参阅在KEYBDINPUT,SendInput,WM_KEYDOWN和WM_KEYUP中注释。

VK_PACKET
0xE7
Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP.

对不起,如果这是一个愚蠢的问题,

Sorry if it's a silly question, but i just want to be sure about this.

推荐答案

如果您的控件创建为unicode窗口(使用CreateWindowW),那么
WM_CHAR你会得到宽的字符开箱。

If your control is created as a unicode window (using CreateWindowW) then in WM_CHAR you will get wide char out of the box.

如果你想提供非unicode版本的控件,那么你需要处理
WM_INPUTLANGCHANGE,东西像这样:

If you want to provide non-unicode version of your control then you need to handle WM_INPUTLANGCHANGE, something like this:

case WM_INPUTLANGCHANGE:
{
              HKL NewInputLocale = (HKL) lParam ;
              g_InputCodePage = LangToCodePage( LOWORD(NewInputLocale) ) ; 
}

因此,您的WM_CHAR处理程序应如下所示:

And so your WM_CHAR handler should look like:

 case WM_CHAR:
     {
        unsigned char c = (byte)wParam;
        if(!::IsWindowUnicode(hwnd))
          MultiByteToWideChar(g_InputCodePage , 0, (LPCSTR) &c, 1, (LPWSTR) &wParam, 1) ;
     }

不要忘记WM_IME_CHAR和朋友。
关于RTL输入。

And don't forget about WM_IME_CHAR and friends. And yet about RTL input.

这篇关于WinAPI:如何在自定义编辑控制中处理键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆