本文介绍了把输入法的自定义文本框,从Control派生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了自己的单行文本框控件在C#.NET 3.5

I have created my own single-line textbox control in C# .net 3.5

我已经完全从头开始写这一点,包括我自己的选择code,滚动,复制/粘贴等,甚至可以选择左到右的文本,而不是我所使用的...

I've written this completely from scratch, including my own selection code, scrolling, copy/paste etc. It can even select left-to-right text, not that I'd ever use that...

我遇到的问题是与IME(输入法编辑器)的集成。该输入法不工作,在一定程度上,但我有几个问题。我只列出其中的一个位置。

The problem I'm having is with IME (input method editor) integration. The IME does work to an extent, but I have a few problems. I'll just list one of them here.

通常情况下,使用一个文本框,输入法施工的文本框内呈现。然而,在我的控制,显示在屏幕右下角的输入法。我试图寻找其他的自定义控制,包括在使用SharpDevelop的一个。然而,这有同样的问题。打字在中国,日本,韩国或导致IME东西在屏幕的右下角来完成。

Normally, using a TextBox, the IME construction is rendered inside the TextBox. However, in my Control, the IME is displayed at the bottom right of the screen. I tried looking at other custom controls, included the one used in SharpDevelop. However, this had the same problem. Typing in Chinese, Japanese, or Korean caused the IME stuff to be done at the bottom-right of the screen.

我需要关于如何得到这个在我自己的文本框来完成,我看着的输入法在Windows API,但有这么多的功能,一些指点,我不知道从哪里开始。

I need some pointers on how to get this to be done in my own textbox, and I looked at the Windows API for IME, but there are so many functions, and I have no idea where to start.

所以,任何想法?

这很好,如果任何code样品是用C ++(管理/非托管)或VB.net。我可以将它轻松地跨越不够。

It's fine if any code samples are in C++ (managed/unmanaged) or VB.net. I can move it across easily enough.

推荐答案

确定,它看起来像有没有计算器许多IME专家......还是无人问津。

OK, it looks like there aren't many IME experts on StackOverflow... or no one is interested.

不管怎样,我想它了。

基本上,我有陷阱下面的Windows消息:

Basically, I have to trap the following Windows messages:

WM_INPUTLANGCHANGE = 0x51
WM_KEYUP = 0x101
WM_CHAR = 0x102
WM_CONVERTREQUESTEX = 0x108
WM_IME_STARTCOMPOSITION = 0x10D
WM_IME_ENDCOMPOSITION = 0x10E
WM_IME_COMPOSITION = 0x10F
WM_IME_SETCONTEXT = 0x281
WM_IME_NOTIFY = 0x282
WM_IME_CONTROL = 0x283
WM_IME_COMPOSITIONFULL = 0x284
WM_IME_SELECT = 0x285
WM_IME_CHAR = 0x286
WM_IME_REQUEST = 0x0288
WM_IME_KEYDOWN = 0x290
WM_IME_KEYUP = 0x291

我诱捕 WM_KEYUP WM_CHAR ,因为如果我点击合成一个韩国字符的中间某处,我没有得到的组合信息,但我需要的字符添加到我的文本框仍然。这是一个奇怪的现象,我不知道这是一个错误。

I'm trapping WM_KEYUP and WM_CHAR, because if I click somewhere in the middle of compositing a Korean character, I do not get a composition message, but I need to add that character to my text box nonetheless. This is a weird behaviour, I wonder if it's a bug.

一旦这种情况发生,之间有韩国,中国和日本不同的行为。

Once that happens, there are different behaviours between Korean, Chinese and Japanese.

韩国是一个非常容易的(我不知道汉字转换,但因为我不知道怎么用的呢)。

Korean is a really easy one (I'm not sure about Hanja convert though, because I don't know how to use that anyway).

基本上,所有的语言,每当我收到了 WM_IME_COMPOSITION ,我必须调用 ImmGetCompositionString 在Imm32.dll正如我在答复中描述的。然后,我显示这是一个进展中的成分,但不要把它添加到我的存储文本。

Basically, for all languages, whenever I get a WM_IME_COMPOSITION, I have to call ImmGetCompositionString in Imm32.dll as I have described in answer to this question. I then display this as a composition in progress, but don't add it to my stored text.

当一个字符串被合成从Windows的消息是针对每个不同的输入法。每一次,我可以从 WM_IME_COMPOSITION 消息得到它。

When a string has been composited the message from Windows is different for each IME. Each time, I can get it from the WM_IME_COMPOSITION message.

在韩国, Lparam型将只是 GCS_RESULTSTR wParam参数将输入的字符,这我可以转换为字符

In Korean, LParam will simply be GCS_RESULTSTR, and WParam will be the entered character, which I can just cast to char

在日本Lparam型将是 GCS_RESULTREADSTR | GCS_RESULTREADCLAUSE | GCS_RESULTSTR0 | GCS_RESULTCLAUSE 。我必须用 ImmGetCompositionString 的结果,我从previous WM_IME_COMPOSITION信息存储,因为此时它会是一个空字符串。

In Japanese 'LParam' will be GCS_RESULTREADSTR | GCS_RESULTREADCLAUSE | GCS_RESULTSTR0 | GCS_RESULTCLAUSE. I have to use the result of ImmGetCompositionString that I stored from the previous WM_IME_COMPOSITION message, because at this time it will be an empty string.

在中国, Lparam型 GCS_RESULTREADCLAUSE | GCS_RESULTSTR0 | GCS_RESULTCLAUSE 。这是一样的日本,除了当previously存储 ImmGetCompositionString 为空,在这种情况下,我需要投 wParam参数为char。

In Chinese, LParam will be GCS_RESULTREADCLAUSE | GCS_RESULTSTR0 | GCS_RESULTCLAUSE. It's the same as Japanese, except when the previously stored ImmGetCompositionString is empty, in which case I need to cast WParam to a char.

在这三种情况下,我必须确保我正在显示的补偿被清除。

In all three cases, I have to make sure that my displayed comp in progress is cleared.

如果我收到 WM_IME_STARTCOMPOSITION ,我设置一个合成标记(并显示正在进行的合成字符串)

If I receive WM_IME_STARTCOMPOSITION, I set a compositing flag (and display the compositing string in progress)

如果我收到 WM_IME_ENDCOMPOSITION 我清除标志(并清除正在进行的合成字符串)。

If I receive WM_IME_ENDCOMPOSITION I clear that flag (and clear the compositing string in progress).

有时候,我没有收到 WM_IME_ENDCOMPOSITION ,所以我清除收到我的标志 WM_CHAR

Sometimes I don't receive WM_IME_ENDCOMPOSITION, so I clear my flag on receiving WM_CHAR.

总之,这是一个非常有趣的学习体验,另一个是仍在进行 - 但输入法现在可以使用在我的控制,最后一次!我住在工作至凌晨1时把它完成。

All in all, it was a very interesting learning experience, and one that is still in progress - but IME is now usable on my control, at last! I stayed at work till 1am to get it done.

这篇关于把输入法的自定义文本框,从Control派生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 10:10