就是输入汉字,自动生成拼音玛(每个汉字拼音的首字母),请各位老大帮忙,分一定多给!!!

解决方案 »

  1.   

    程序代码如下:
    unit Unit1; 
    interface 
    uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
    StdCtrls, ExtCtrls, Buttons, IMM; type TForm1 = class(TForm) OpenDialog1: TOpenDialog; BitBtn2: TBitBtn; BitBtn3: TBitBtn; Edit2: TEdit; Edit1: TEdit; Label5: TLabel; Label1: TLabel; BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); public iHandleCount: integer; pList : array[1..20] of HKL; szImeName : array[0..254] of char; II : integer; end; 
    const pych: array[1..6,1..5] of string[2]= (('ā', 'á','ǎ','à','a'),('ō', 'ó','ǒ','ò','o'), ('ē', 'é','ě','è','e'),('ī', 'í','ǐ','ì','i'), ('ū', 'ú','ǔ','ù','u'),('ǖ', 'ǘ','ǚ','ǜ','ü')); 
    var Form1: TForm1; 
    implementation 
    {$R *.DFM} 
    procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin II := 0; //retrieves the keyboard layout handles corresponding to the current set of input locales in the system. iHandleCount := GetKeyboardLayoutList(20, pList); for i := 1 to iHandleCount do begin if ImmEscape(pList[i], 0, IME_ESC_IME_NAME, @szImeName) > 0 then if szImeName='微软拼音输入法' then begin 
    StdCtrls, ExtCtrls, Buttons, IMM; type TForm1 = class(TForm) OpenDialog1: TOpenDialog; BitBtn2: TBitBtn; BitBtn3: TBitBtn; Edit2: TEdit; Edit1: TEdit; Label5: TLabel; Label1: TLabel; BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); public iHandleCount: integer; pList : array[1..20] of HKL; szImeName : array[0..254] of char; II : integer; end; 
    const pych: array[1..6,1..5] of string[2]= (('ā', 'á','ǎ','à','a'),('ō', 'ó','ǒ','ò','o'), ('ē', 'é','ě','è','e'),('ī', 'í','ǐ','ì','i'), ('ū', 'ú','ǔ','ù','u'),('ǖ', 'ǘ','ǚ','ǜ','ü')); 
    var Form1: TForm1; 
    implementation 
    {$R *.DFM} 
    procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin II := 0; //retrieves the keyboard layout handles corresponding to the current set of input locales in the system. iHandleCount := GetKeyboardLayoutList(20, pList); for i := 1 to iHandleCount do begin if ImmEscape(pList[i], 0, IME_ESC_IME_NAME, @szImeName) > 0 then if szImeName='微软拼音输入法' then begin 
    ii := i; exit; end; end; ShowMessage('请你安装"微软拼音输入法"!'); end;金山词霸(2.0-2000版本)内有gb2py.idx和gbk2py.idx,内有国标
    GB、GBK的每个汉字的拼音和声调。可用拿来一用。下面上Delphi写的gb2py函数。
    function gb2py(hanzi:pchar):pchar;
    var
    Sfile:Tmemorystream;
    pos,temp,ipos,len:integer;
    py:array[0..20] of char;
    begin
      pos:=($fe-$a1)*(ord(hanzi[0])-$b0)+ord(hanzi[1])-$a1;
      sfile:=Tmemorystream.create;
      sfile.loadfromfile('C:\Program Files\KINGSOFT\XDICT\gb2py.idx');
      //data:=sfile.memory;
      sfile.Seek($1608+pos*4,soFromBeginning);
      sfile.Read(ipos,4);
      sfile.Read(temp,4);
      len:=temp-ipos;
      sfile.Seek(ipos+1,soFromBeginning);
      sfile.Read(py,len);
      py[len-1]:=#0;
      sfile.Free;
      result:=py;
    end; 
    来自超级猛料
      

  2.   

    // FileName: PY.pas//// Copyright (C) 1999 By Zhang Qing//// You can use and modify it ,but please send me an email.//// E-Mail: [email protected]/////////////////////////////////////////////////////////////////////////////unit PY;interfaceuses sysutils;// 获取汉字的拼音首字符,这个函数将用在GetPYIndexStr 中.function GetPYIndexChar(strChinese: string; bUpCase: Boolean = True): char;// 获取多个汉字的拼音首字符组成的字符串.function GetPYIndexStr(strChinese: string; bUpCase: Boolean = True): string;implementation////////////////////////////////////////////////////////////////////////////// 函数: GetPYIndexChar(strChinese: string;bUpCase: Boolean = True): char;//// 函数功能:获取汉字的拼音首字符.// 例: GetPYIndexChar('程') 将返回'C'.//// 注意:对于多于一个汉字的输入(string类型)只有第一个有效,但不会产生错误// 例如,GetPYIndexChar('程序')也将返回'C'.//// 第二个参数决定返回大写还是小写 , 缺省为大写 .////////////////////////////////////////////////////////////////////////////function GetPYIndexChar(strChinese: string;bUpCase: Boolean = True): char;begin// 根据汉字表中拼音首字符分别为“A”至“Z”的汉字内码范围,// 要检索的汉字只需要检查它的内码位于哪一个首字符的范围内,// 就可以判断出它的拼音首字符。case WORD(strChinese[1]) shl 8 + WORD(strChinese[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';$B8C1..$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';$D1B9..$D4D0 : result := 'Y';$D4D1..$D7F9 : result := 'Z';elseresult := char(0);end;if not bUpCase thenbegin // 转换为小写result := Chr(Ord(result)+32);end;end;////////////////////////////////////////////////////////////////////////////// 函数: GetPYIndexStr(strChinese: string;bUpCase: Boolean = True): string;//// 函数功能:获取多个汉字的拼音首字符组成的字符串.// 例: GetPYIndexStr('程') 将返回'C'.// GetPYIndexStr('程序')将返回'CX'.//// 第二个参数决定返回大写还是小写 , 缺省为大写 .////////////////////////////////////////////////////////////////////////////function GetPYIndexStr(strChinese: string;bUpCase: Boolean = True): string;varstrChineseTemp : string;cTemp : Char;beginresult := '';strChineseTemp := strChinese;while strChineseTemp<>'' dobegincTemp := GetPYIndexChar(strChineseTemp);if not bUpCase thenbegin // 转换为小写cTemp := Chr(Ord(cTemp)+32);end;result := result + string(cTemp);strChineseTemp := Copy(strChineseTemp,3,Length(strChineseTemp));end;end;end. 
     
      

  3.   

    上两种方法真太可怕了.对第一种方法如果人家机器上没有"微软拼音"或是以后"微软拼音"升级了,接口改了怎么办呢?第二种方法如果是GBK汉字是否仍管用?遇到这种问题我都是直接反编译IME文件,得码表,再将码表作成一个字典文件备查的.
      

  4.   

    都是高手啊,不过我自己 作了一个Dll,可以得到一组汉字的拼首,
    可以,可大家分享,有需要的 可以给我发E-mail
    E-mail:
    [email protected]