(Input Method Manager,简称IMM)
using Microsoft.WindowsCE.Forms;
InputPanel ip = new InputPanel();
foreach(InputMethod p in ip.InputMethods)
{
treeView1.Nodes.Add(new TreeNode(p.Name));
}
这样可以得到系统中安装的所有输入法。比如我的是A4输入法及本机自带拼音手写输入法等。
在特定的输入框中,我们有时只需输入数字,或者英文,这样要对输入法“拼”“英”“符”等三项进行切换。需要使用到
BOOL ImmSetConversionStatus(
HIMC hIMC,
DWORD fdwConversion,
DWORD fdwSentence
);
参数一:句柄
Value | Description |
---|---|
IME_CMODE_CHARCODE | Set to 1 if character code input mode; 0 if not. |
IME_CMODE_EUDC | Set to 1 if EUDC conversion mode; 0 if not. |
IME_CMODE_FULLSHAPE | Set to 1 if full shape mode; 0 if half shape mode. |
IME_CMODE_HANJACONVERT | Set to 1 if HANJA convert mode; 0 if not. |
IME_CMODE_KATAKANA | Set to 1 if KATAKANA mode; 0 if HIRAGANA mode. |
IME_CMODE_NATIVE | Set to 1 if NATIVE mode; 0 if ALPHANUMERIC mode. |
IME_CMODE_NOCONVERSION | Set to 1 to prevent processing of conversions by IME; 0 if not. |
IME_CMODE_ROMAN | Set to 1 if ROMAN input mode; 0 if not. |
IME_CMODE_SOFTKBD | Set to 1 if Soft Keyboard mode; 0 if not.
|
参数三: IMN_SETSENTENCEMODE
Value | Description |
---|---|
IME_SMODE_AUTOMATIC | The IME carries out conversion processing in automatic mode. |
IME_SMODE_NONE | No information for sentence. |
IME_SMODE_PHRASEPREDICT | The IME uses phrase information to predict the next character. |
IME_SMODE_PLURALCLAUSE | The IME uses plural clause information to carry out conversion processing. |
IME_SMODE_SINGLECONVERT | The IME carries out conversion processing in single-character mode. |
C/C++ code HIMC hImc;
DWORD dwConv, dwSent;
hImc = ImmGetContext(hwndTarget);
ImmGetConversionStatus(hImc, &dwConv, & dwSent);
if (ImmSetConversionStatus(hImc, IME_CMODE_ALPHANUMERIC, dwSent) == 0 )
{
// error
}
ImmReleaseContext(hwndTarget, hImc);
C# code
IntPtr hwndInput = ImmGetContext(this.Handle);
IntPtr dw1 = IntPtr.Zero;
IntPtr dw2 = IntPtr.Zero;
bool isSuccess = ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);
if (isSuccess)
{
int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;
if (intTemp > 0)
dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);
else
dw1 = (IntPtr)(dw1.ToInt32() | IME_CMODE_SOFTKBD);
}
isSuccess = ImmSetConversionStatus(hwndInput, dw1, dw2);
ImmReleaseContext(this.Handle, hwndInput);
public const int IME_CMODE_SOFTKBD = 0x80;
唉!我内流满面啊! 找了半天在Coredll.DLL中没有ImmSetConversionStatus 现在在MSDN帮助中找到
// Set input mode for name text box to AlphaCurrent.
InputModeEditor.SetInputMode(textBox1, InputMode.AlphaCurrent);
// Set input mode for phone number text box to Numeric.
InputModeEditor.SetInputMode(textBox2, InputMode.Numeric);
// Set input mode for city text box to AlphaCurrent.
InputModeEditor.SetInputMode(textBox3, InputMode.AlphaCurrent);
命名空间:Microsoft.WindowsCE.Forms
但是经测试发现,只支持设置smartphone的输入法,在ppc,wm5,wm6都是无效的。。。
继续郁闷,强人路过请指导一下!