有没有办法通过IMM。PAS,得到某一个汉字的五笔编码??
lxl 2003-03-04 04:59:12 以前使用码表对应的方法,
通过程序附带一个码表文件,
可以查到一个汉字的五笔编码
但也想找到更好的方法,
如使用IMM。PAS来查找
1、使用类于下面的程序可以查得到一个汉字的拼音编码,
但为什么不可以用“五笔86版”来得到一个汉字的五笔编码呢?
unit Unit1;
interface
uses
imm,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
function getfirstpy(hz: string): string;
function QueryCompstr(hKB: HKL; const sChinese: AnsiString): string;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.getfirstpy(hz : string ) : string;
var k : hkl;
j,ihandlecount : integer;
pList: array[1..10] of HKL;
szImeName: array[0..254] of char;
cchinese,py : string;
begin
iHandleCount := GetKeyboardLayoutList(10, pList);
for k := 1 to 10 do
if ImmEscape(pList[k], 0, IME_ESC_IME_NAME, @szImeName)>0 then
if szImeName= '微软拼音输入法' then
break;
cchinese:=hz;
j:=1;
py:='';
while j<= strlen(pchar(cchinese)) do
begin
if ord(cchinese[j])>128 then
begin
hz:=cchinese[j]+cchinese[j+1];
py:=py+QueryCompStr(plist[k],pchar(hz));
inc(j,2);
end
else
begin
if ord(cchinese[j])<>39 then
py:=py+cchinese[j];
inc(j,1);
end;
end;
result:=py;
end;
function tform1.QueryCompstr(hKB: HKL; const sChinese: AnsiString): string;
var
dwGCL: DWORD;
szBuffer: array[0..254] of char;
iMaxKey, iStart, i: integer;
begin
Result := '';
iMaxKey := ImmEscape(hKB, 0, IME_ESC_MAX_KEY, nil);
if iMaxKey <= 0 then exit;
dwGCL := ImmGetConversionList(hKB,0,pchar(sChinese),nil,0,GCL_REVERSECONVERSION);
if dwGCL <= 0 then Exit;
dwGCL := ImmGetConversionList(hKB,0,pchar(sChinese),@szBuffer,dwGCL,GCL_REVERSECONVERSION);
if dwGCL > 0 then
begin
iStart := byte(szBuffer[24]);
for i := iStart to iStart do //iMaxKey * 2 do
begin
AppendStr(Result, szBuffer[i]);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(getfirstpy(edit1.text));
end;
end.