有没有办法通过IMM。PAS,得到某一个汉字的五笔编码??

lxl lxl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以前使用码表对应的方法,
通过程序附带一个码表文件,
可以查到一个汉字的五笔编码
但也想找到更好的方法,
如使用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.
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
lxl
Delphi 5,944 成员 262,941 内容