我来贴点代码吧
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ComCtrls, ToolWin, StdCtrls, ImgList, ExtCtrls;
type
CodeLib=array[1..10000] of string;
TForm1 = class(TForm)
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
ImageList1: TImageList;
MainMenu1: TMainMenu;
N1: TMenuItem;
mnuClearText: TMenuItem;
mnuSearch: TMenuItem;
N4: TMenuItem;
mnuSetupInputMethod: TMenuItem;
N6: TMenuItem;
mnuHelpContents: TMenuItem;
mnuHelpOnHelp: TMenuItem;
N9: TMenuItem;
About: TMenuItem;
ToolButton1: TToolButton;
N2: TMenuItem;
mnuToolsBar: TMenuItem;
mnuStatusBar: TMenuItem;
Panel1: TPanel;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
mnuShowInputPicture: TMenuItem;
N3: TMenuItem;
mnuProgramInTop: TMenuItem;
N5: TMenuItem;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
mnuMinimizeAndTrayIcon: TMenuItem;
ImageList2: TImageList;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
ListBox1: TListBox;
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure AboutClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure mnuClearTextClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure mnuSearchClick(Sender: TObject);
procedure mnuHelpContentsClick(Sender: TObject);
procedure mnuHelpOnHelpClick(Sender: TObject);
procedure mnuSetupInputMethodClick(Sender: TObject);
procedure mnuShowInputPictureClick(Sender: TObject);
procedure mnuToolsBarClick(Sender: TObject);
procedure mnuStatusBarClick(Sender: TObject);
procedure mnuProgramInTopClick(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CoolTrayIcon1Click(Sender: TObject);
procedure mnuMinimizeAndTrayIconClick(Sender: TObject);
procedure ToolButton10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
sChinese : codelib;
sCode : codelib;
sInputMethodFile : string[50];
inFile : text;
LibNo : integer;
procedure ReadFromInputMethodFile(); forward;
procedure SetWinCaption(); forward;
procedure GeneralSearch(); forward;
procedure SearchQuwei(); forward;
procedure SearchAscii(); forward;
procedure SearchQpNot(); forward;
implementation
uses SetupInputMethod, About;
{$R *.DFM}
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
case Key of
{ VK_DOWN: CurrentLine :=CurrentLine + 1;
VK_UP: CurrentLine :=CurrentLine - 1;
VK_NEXT: CurrentLine :=CurrentLine + FVisibleLines;
VK_PRIOR: CurrentLine :=CurrentLine - FVisibleLines;
VK_HOME: CurrentLine :=0;
VK_END: CurrentLine :=FLineCount - 1;}
VK_RETURN:
self.mnuSearchClick(sender);
end;
end;
procedure TForm1.AboutClick(Sender: TObject);
begin
aboutbox.show;
aboutbox.left:=self.Left +50;
aboutbox.top:=self.top +50;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
iniFile :textFile;
begin
try
AssignFile(iniFile, 'diction.ini');
reset(iniFile);
readln(iniFile, sInputMethodFile);
CloseFile(iniFile);
except
sInputMethodFile :='wbx.lib';
end;
SetWinCaption;
ReadFromInputMethodFile();
ComboBox1.text:='';
label1.Caption :='按回车键查询';
label2.Caption :='';
label3.Caption :='';
label4.Caption :='';
end;
procedure TForm1.mnuClearTextClick(Sender: TObject);
begin
combobox1.Text :='';
end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
mnuClearTextClick(Sender);
end;
procedure TForm1.mnuSearchClick(Sender: TObject);
begin
label1.Caption :='';
label2.Caption :='';
label3.Caption :='';
label4.Caption :='';
ListBox1.Items.Clear;
if Form1.combobox1.Text ='' then
begin
Form1.label2.Caption :='请输入待查询的汉字';
exit;
end;
if sTemp = 'quwei.lib' then
SearchQuwei()
else if sTemp = 'ascii.lib' then
SearchAscii()
else if sTemp = 'qpnot.lib' then
SearchQpNot()
else GeneralSearch();
end;
procedure TForm1.mnuHelpContentsClick(Sender: TObject);
begin
winhelp(self.handle,'diction.hlp', HELP_CONTENTS,0);
end;
procedure TForm1.mnuHelpOnHelpClick(Sender: TObject);
begin
winhelp(self.handle,'diction.hlp', HELP_HELPONHELP,0);
end;
procedure TForm1.mnuSetupInputMethodClick(Sender: TObject);
var
sTemp ,sOld :string;
begin
sTemp :=ComboBox1.Text;
ComboBox1.Text :='';
sOld := sInputMethodFile;
dlgSetupInputMethod.ShowModal();
ComboBox1.Text :=sTemp;
SetWinCaption;
if sOld<>sInputMethodFile then ReadFromInputMethodFile();
end;
procedure TForm1.mnuShowInputPictureClick(Sender: TObject);
begin
if sTemp = 'wbx.lib' then
Winexec('wbxbmp.exe',SW_MAXIMIZE)
else if sTemp = 'zrm.lib' then
Winexec('zrmbmp.exe',SW_MAXIMIZE)
else if sTemp = 'zhengma.lib' then
Winexec('zmbmp.exe',SW_MAXIMIZE)
else if sTemp = 'bxm.lib' then
Winexec('bxmbmp.exe',SW_MAXIMIZE)
else if sTemp = 'bxmnt.lib' then
Winexec('bxmbmp.exe',SW_MAXIMIZE)
else Winexec('wbxbmp.exe',SW_MAXIMIZE);
end;
procedure TForm1.mnuToolsBarClick(Sender: TObject);
begin
if Toolbar1.visible = true then
Toolbar1.visible :=false
else if Toolbar1.visible = false then
Toolbar1.visible :=true ;
if mnuToolsbar.Checked =true then
mnuToolsbar.Checked :=false
else if mnuToolsbar.Checked =false then
mnuToolsbar.Checked :=true;
end;
procedure TForm1.mnuStatusBarClick(Sender: TObject);
begin
if Statusbar1.visible = true then
Statusbar1.visible :=false
else if Statusbar1.visible = false then
Statusbar1.visible :=true ;
if mnuStatusbar.Checked =true then
mnuStatusbar.Checked :=false
else if mnuStatusbar.Checked =false then
mnuStatusbar.Checked :=true;
end;
procedure ReadFromInputMethodFile();
var
i: integer;
j: integer;
ch : char;
begin
for j :=1 to 8000 do {初始化,这里是关键}
begin
{ sChinese[j]:= '';}
sCode[j]:=''; {只需对sCode进行初始化}
end;
if sInputMethodFile='qpnot.lib' then
AssignFile(inFile, 'qp.lib')
else if sInputMethodFile ='quwei.lib'then
AssignFile(inFile, 'wbx.lib')
else if sInputMethodFile = 'ascii.lib' then
AssignFile(inFile, 'wbx.lib')
else AssignFile(inFile, sInputMethodFile);
reset(inFile);
i :=1; {i表示行号}
while i>0 do
begin
read(inFile,ch);
if eof(inFile) =true then
begin
sChinese:=copy(sCode,1,2);
break;
end;
sCode :=sCode+ch;
if eoln(inFile) =true then
begin
sChinese:=copy(sCode,1,2);
delete(sCode,1,2);
readln(inFile); {文件指针指向下一行的第一个字符}
i:=i+1;
end;
end;
LibNo :=i;
CloseFile(inFile);
end;
procedure TForm1.mnuProgramInTopClick(Sender: TObject);
begin
if mnuProgramInTop.Checked =true then
SetWindowPos(self.Handle , HWND_NOTOPMOST, 0,0,0,0, SWP_NOMOVE + SWP_NOSIZE)
else
SetWindowPos(self.Handle, HWND_TOPMOST, 0,0, 0,0, SWP_NOMOVE + SWP_NOSIZE);
if mnuProgramInTop.Checked =true then
mnuProgramInTop.Checked :=false
else if mnuProgramInTop.Checked =false then
mnuProgramInTop.Checked :=true;
end;
procedure TForm1.N5Click(Sender: TObject);
begin
ComboBox1.Items.Clear ;
end;
procedure TForm1.ToolButton8Click(Sender: TObject);
begin
mnuMinimizeAndTrayIconClick(Sender);
end;
procedure TForm1.ToolButton6Click(Sender: TObject);
begin
mnuSetupInputMethodClick(Sender);
end;
procedure TForm1.ToolButton4Click(Sender: TObject);
begin
mnuShowInputPictureClick(Sender);
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
mnuSearchClick(Sender);
end;
procedure SetWinCaption();
var
sTemp : string;
begin
sTemp :=Main.sInputMethodFile;
if sTemp='wbx.lib' then Form1.Caption :='天文编码字典—五笔字型'
else if sTemp = 'qp.lib' then Form1.Caption :='天文编码字典—全拼(带音调)'
else if sTemp = 'qpnot.lib' then Form1.Caption :='天文编码字典—全拼(不带音调)'
else if sTemp = 'zrm.lib' then Form1.Caption :='天文编码字典—自然码'
else if sTemp = 'cjj.lib' then Form1.Caption :='天文编码字典—仓吉简体'
else if sTemp = 'cjf.lib' then Form1.Caption :='天文编码字典—仓吉繁体'
else if sTemp = 'bxm.lib' then Form1.Caption :='天文编码字典—表形码(31键)'
else if sTemp = 'bxmnt.lib' then Form1.Caption :='天文编码字典—表形码(26键)'
else if sTemp = 'sw.lib' then Form1.Caption :='天文编码字典—首尾码'
else if sTemp = 'ptm.lib' then Form1.Caption :='天文编码字典—普通码'
else if sTemp = 'rzm.lib' then Form1.Caption :='天文编码字典—认知码'
else if sTemp = 'dianbao.lib' then Form1.Caption :='天文编码字典—电报码'
else if sTemp = 'zhengma.lib' then Form1.Caption :='天文编码字典—郑码'
else if sTemp = 'quwei.lib' then Form1.Caption :='天文编码字典—区位码'
else if sTemp = 'ascii.lib' then Form1.Caption :='天文编码字典—汉字内码或ASCII码'
else
begin
Main.sInputMethodFile :='wbx.lib';
Form1.Caption :='天文编码字典—五笔字型';
end;
end;
procedure GeneralSearch();
var
sTemp, sTemp1, sTemp2 : string;
sList :string;
i , j, k, strLength :integer;
nToLen :integer;
begin
nToLen := length(Form1.combobox1.Text);
k :=1;
while k <nToLen do begin
stemp:=copy(Form1.combobox1.Text,k,2);
if (ord(stemp[1])<$a0) then
begin
Form1.label1.Caption :=sTemp;
Form1.label2.Caption :='不是汉字,请输入汉字';
exit;
end;
for i :=1 to LibNo do
begin
if stemp = sChinese then
begin
Form1.label1.Caption :=sChinese;
strLength :=length(sCode);
sTemp1:='';
for j :=1 to strlength do
begin
sTemp2 :=copy(sCode,j,1);
if sTemp2<>'|' then
Stemp1 :=Stemp1+sTemp2
else
Stemp1 :=Stemp1+' ';
end;
// Form1.label2.Caption :=STemp1; { sCode;}
sList :=STemp+' '+Stemp1;
Form1.ListBox1.Items.Add(sList);
break;
end;
end;
Form1.ComboBox1.Items.Add(sTemp);
k :=k+2;
end;
end;
(*************************************)
procedure SearchQuwei();
var
sTemp, sTemp1, sTemp2 : string;
i , j ,nLen :integer;
begin
sTemp1 :=''; sTemp2 :='';
stemp:=copy(Form1.combobox1.Text,1,2);
Form1.Label1.Caption :=sTemp;
nLen :=length(sTemp);
if nLen <2 then
begin
Form1.label2.Caption :='不是汉字,请输入汉字';
if sTemp ='' then Form1.label2.Caption :='请输入待查询的汉字';
exit;
end;
sTemp1 :=copy(sTemp,1,1); sTemp2 :=copy(sTemp,2,1);
i :=ord(sTemp1[1]) - $a0; j :=ord(Stemp2[1]) - $a0;
str(i, sTemp1); str(j, sTemp2);
if length(sTemp1) <2 then sTemp1 :='0'+sTemp1;
if length(sTemp2) <2 then sTemp2 :='0'+sTemp2;
if (i>=0) and (j>=0) then Form1.label2.Caption :=sTemp1+sTemp2
else Form1.label2.Caption :='不是汉字,请输入汉字';
Form1.ComboBox1.Items.Add(sTemp);
end;
(*************************************)
procedure SearchAscii();
var
sTemp, sTemp1, sTemp2 : string;
i , j, nLen :integer;
begin
sTemp1 :=''; sTemp2 :='';
sTemp :=copy(Form1.combobox1.Text,1,2);
nLen :=length(sTemp);
Form1.Label1.Caption :=sTemp;
sTemp1 :=copy(sTemp,1,1);
i :=ord(sTemp1[1]);
sTemp1 :=Format('%x', );
if nLen =1 then
begin
if (i>=0) then Form1.label2.Caption :=sTemp1+' Hex'
else Form1.label2.Caption :='不是汉字';
end;
if nLen = 2 then
begin
sTemp2 :=copy(sTemp,2,1);
j :=ord(Stemp2[1]);
sTemp2 :=Format('%x', [j]);
if (i>=0) or (j>=0) then Form1.label2.Caption :=sTemp1+sTemp2+' Hex'
else Form1.label2.Caption :='不是汉字';
end;
Form1.ComboBox1.Items.Add(sTemp);
end;
procedure SearchQpNot();
var
sTemp, sTemp2, sOld, sQpStr : string;
sTemp1 : array [1..50] of string;
i , j,k, kk, strLength,nToLen :integer;
begin
nToLen := length(Form1.combobox1.Text);
kk :=1;
while kk <nToLen do begin
stemp:=copy(Form1.combobox1.Text,kk,2);
if (ord(stemp[1])<$a0) then
begin
Form1.label1.Caption :=sTemp;
Form1.label2.Caption :='不是汉字,请输入汉字';
exit;
end;
for i :=1 to LibNo do
begin
if stemp = sChinese then
begin
Form1.label1.Caption :=sChinese;
strLength :=length(sCode);
k :=1;
Stemp1[k] :='';
for j :=1 to strlength do
begin
sTemp2 :=copy(sCode,j,1);
if sTemp2 = '|' then
begin
k :=k+1; sTemp1[k] :='';
end
else if (sTemp2 <> '1') and
(sTemp2 <> '2') and
(sTemp2 <> '3') and
(sTemp2 <> '4')
then Stemp1[k] :=Stemp1[k]+sTemp2
end;
sOld :=sTemp1[1];
sQpStr :=sTemp1[1];
for j :=2 to k do
begin
if sOld <> sTemp1[j] then
begin
sQpStr :=sQpStr +' '+sTemp1[j];
sOld := sTemp1[j];
end;
end;
// Form1.label2.Caption :=sQpStr; { sCode;}
Form1.listbox1.Items.add(sTemp+' '+sQpStr);
break;
end;
end;
Form1.ComboBox1.Items.Add(sTemp);
kk :=kk+2;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
iniFile :textFile;
begin
AssignFile(iniFile, 'diction.ini');
rewrite(iniFile);
writeln(iniFile, sInputMethodFile);
CloseFile(iniFile);
end;
procedure TForm1.CoolTrayIcon1Click(Sender: TObject);
begin
// CoolTrayIcon1.ShowMainForm ;
end;
procedure TForm1.mnuMinimizeAndTrayIconClick(Sender: TObject);
begin
// CoolTrayIcon1.HideMainForm;
end;
procedure TForm1.ToolButton10Click(Sender: TObject);
begin
AboutClick(Sender);
end;
end.