這里有一段Delphi的源碼, 看一看定有收獲 ////////////////////////// procedure TfrmQueryComposition.btnExecuteClick(Sender: TObject); var iHandleCount: integer; pList: array[1..nHKL_LIST] of HKL; szImeName: array[0..254] of char; i: integer; sFound: string; begin lstComposition.Items.Clear; // 取得目前系統已安裝輸入法之各個鍵盤配置(Keyboard Layout) iHandleCount := GetKeyboardLayoutList(nHKL_LIST, pList); for i := 1 to iHandleCount do begin if ImmEscape(pList[i], 0, IME_ESC_IME_NAME, @szImeName) > 0 then begin sFound := QueryCompStr(pList[i], edtExam.Text); if sFound <> '' then lstComposition.Items.Add(StrPas(szImeName) + ': ' + sFound); end; end; // 將鍵盤焦點交給 edtExam, 方便繼續查下一個字 with edtExam do begin SetFocus; SelStart := 0; SelLength := 2; ToChinese(Handle, True); end; end; { of btnExecuteClick }
1.确定用户正在用那一个编码方案(这一步可能最麻烦)
2.按WHQ的思路找到你准备好的码表数据(内含或外带的)
3.按图索骥查码表
不知是否可行,祝你好运气
//////////////////////////
procedure TfrmQueryComposition.btnExecuteClick(Sender: TObject);
var
iHandleCount: integer;
pList: array[1..nHKL_LIST] of HKL;
szImeName: array[0..254] of char;
i: integer;
sFound: string;
begin
lstComposition.Items.Clear;
// 取得目前系統已安裝輸入法之各個鍵盤配置(Keyboard Layout)
iHandleCount := GetKeyboardLayoutList(nHKL_LIST, pList);
for i := 1 to iHandleCount do
begin
if ImmEscape(pList[i], 0, IME_ESC_IME_NAME, @szImeName) > 0 then
begin
sFound := QueryCompStr(pList[i], edtExam.Text);
if sFound <> '' then
lstComposition.Items.Add(StrPas(szImeName) + ': ' + sFound);
end;
end; // 將鍵盤焦點交給 edtExam, 方便繼續查下一個字
with edtExam do
begin
SetFocus;
SelStart := 0;
SelLength := 2;
ToChinese(Handle, True);
end;
end; { of btnExecuteClick }
1.ImmEscape调用只取到了“微软拼音输入法”一种输入法,但我的系统中共有4种输入法。GetKeyboardLayoutList()调用中取得的数字是对的;
2.我找不到QueryCompStr在VC++中对应的API。