如何取得每个汉字的五笔打法的第一个字母和拼音的第一个字母?

zym_double 2003-10-16 10:22:58
如何取得每个汉字的五笔打法的第一个字母和拼音的第一个字母?

谢谢!!
...全文
128 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pankun 2003-10-19
  • 打赏
  • 举报
回复
五笔的.

根据汉字查输入法的编码
function 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 + iMaxKey * 2 do

AppendStr(Result, szBuffer[i]);

end;

end;

但是上面的程序有问题,解决如下:

------------------------------------------------------------

在QueryCompStr中做如下修改就好(test in:win98 se+delphi5)

dwGCL := dwGCL+sizeof(TCandidateList); //add this line then ok,编码查询功能只支持单字,不支持词组。

dwGCL := ImmGetConversionList(hKB,0,pchar(sChinese),@szBuffer,dwGCL,GCL_REVERSECONVERSION);

----------------------------------------------------------------

按照pqx给我的答案,问题已解决部分,但用这种方法并不是所有的输入法都能查出,而用Windows自已的编码查询功能(右击输入法提示条,设置->编码查询,选择相应的输入法)则都能查出来,这是为什么呢?(如“王码五笔4.0”就查不出,而微软的“王码五笔86版”、“王码五笔98版”则都能查到。)

反查编码的的例子可以到 http://www.mildragon.com 的“学习园地”下载。本例是改自台湾钱达智先生的一个例子QRYCOMP(可以在Delphi深度历险中下载)。

*********

var

iHandleCount: integer;

pList: array[1..nHKL_LIST] of HKL;

szImeName: array[0..254] of char;

i: integer;

sFound: string;

begin

lstComposition.Items.Clear;

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;

 


pankun 2003-10-19
  • 打赏
  • 举报
回复
从汉字来得到首字母的方法,你再扩展一下应就可以满足你的需求了.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function getpy(hzchar:string):char;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

function TForm1.getpy(hzchar: string): char;
begin
case WORD(hzchar[1])shl(8)+WORD(hzchar[2]) of
$B0A1..$B0C4 : result:='A';
$B0C5..$B2C0 : result:='B';
$B2C1..$B4ED : result:='C';
$B4EE..$B6E9 : result:='D';
$B6EA..$B7A1 : result:='E';
$B7A2..$B8C0 : result:='F';
$B9C1..$B9FD : result:='G';
$B9FE..$BBF6 : result:='H';
$BBF7..$BFA5 : result:='J';
$BFA6..$C0AB : result:='K';
$C0AC..$C2E7 : result:='L';
$C2E8..$C4C2 : result:='M';
$C4C3..$C5B5 : result:='N';
$C5B6..$C5BD : result:='O';
$C5BE..$C6D9 : result:='P';
$C6DA..$C8BA : result:='Q';
$C8BB..$C8F5 : result:='R';
$C8F6..$CBF9 : result:='S';
$CBFA..$CDD9 : result:='T';
$CDDA..$CEF3 : result:='W';
$CEF4..$D188 : result:='X';
$D189..$D4D0 : result:='Y';
$D4D1..$D7F9 : result:='Z';
else
result:=char(0);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:=getpy('新')+getpy('闻')+getpy('频')+getpy('道');
showmessage(s);
end;

end.
zym_double 2003-10-16
  • 打赏
  • 举报
回复
给源码最好!!

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧