(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));
}
這樣可以得到系統中安裝的所有IME。比如我的是A4IME及本機內建拼音手寫IME等。
在特定的輸入框中,我們有時只需輸入數字,或者英文,這樣要對IME“拼”“英”“符”等三項進行切換。需要使用到
BOOL ImmSetConversionStatus(
HIMC hIMC,
DWORD fdwConversion,
DWORD fdwSentence
);
參數一:控制代碼
參數二: IMN_SETCONVERSIONMODE
| 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的IME,在ppc,wm5,wm6都是無效的。。。
繼續鬱悶,強人路過請指導一下!