interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,Forms, Dialogs, StdCtrls, ComCtrls, Clipbrd,Buttons, ExtCtrls, Menus;
type
TForm1 = class(TForm)
MList: TMemo;
RTrans: TRichEdit;
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
RConv: TRichEdit;
Button3: TButton;
od: TOpenDialog;
RichEdit3: TRichEdit;
MainMenu1: TMainMenu;
F1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
C1: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
RTF1: TMenuItem;
Panel1: TPanel;
PRogressBar1: TProgressBar;
Splitter1: TSplitter;
Splitter2: TSplitter;
E1: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N8Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer=0;//聲明一個(gè)全局變量,用于單詞的記數(shù)
implementation
{$R *.dfm}
//開始轉(zhuǎn)換事件
procedure TForm1.Button1Click(Sender: TObject);
begin
RTrans.Clear;//清空轉(zhuǎn)換區(qū)
RConv.Clear;
timer1.Interval:=strtoint(edit1.Text)*1000;//設(shè)置間隔時(shí)間
timer1.Enabled :=true;//
progressbar1.Position:=0;//設(shè)置進(jìn)度條狀態(tài)
i:=0;//初始化變量,用于記數(shù)
progressbar1.Max:=MList.Lines.Count;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
King,//金山詞霸 2002 主窗口句柄
combo,//單詞輸入框父窗口句柄
edit,//單詞輸入框句柄
means:thandle;//翻譯顯示窗口句柄
begin
if i<=MList.Lines.Count-1 then
begin
king:=findwindow(nil,pchar('金山詞霸 2002'));
combo:=findwindowex(king,0,'ComboBox',nil);
edit:=findwindowex(combo,0,'Edit',nil);
means:=findwindowex(king,0,'XDICT_ExplainView',nil);
//信息顯示
label3.Caption :='('+inttostr(i+1)+'/'+inttostr(MList.Lines.Count)+') '+MList.Lines[i];
//存儲(chǔ)信息
clipboard.AsText := MList.Lines[i];
showwindow(king,sw_shownormal);
bringwindowtotop(king);
SetForegroundWindow(king);
windows.SetFocus(edit);
//模擬Ctrl+V 粘貼
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
SetForegroundWindow(means);
windows.SetFocus(means);
//模擬Ctrl+A 全選
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(Ord('A'), MapVirtualKey(Ord('A'), 0), 0, 0);
keybd_event(Ord('A'), MapVirtualKey(Ord('A'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
SetForegroundWindow(means);
windows.SetFocus(means);
//模擬Ctrl+C 復(fù)制
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(Ord('C'), MapVirtualKey(Ord('C'), 0), 0, 0);
keybd_event(Ord('C'), MapVirtualKey(Ord('C'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
windows.SetFocus(RTrans.Handle );
//模擬Ctrl+V 粘貼
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), 0, 0);
keybd_event(Ord('V'), MapVirtualKey(Ord('V'), 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
RTrans.Lines.Add('=================='+#13);
progressbar1.StepIt;//進(jìn)度條移動(dòng)
inc(i);//增加記數(shù)
end else
begin
timer1.Enabled :=false;
RTrans.Lines.SaveToFile('Temp.txt');
end;
end;
//讀取單詞列表到Mlist中
procedure TForm1.Button2Click(Sender: TObject);
begin
if od.Execute then
MList.Lines.LoadFromFile(od.FileName );
end;
//轉(zhuǎn)換功能,因?yàn)镽Trans中得到的翻譯中,音標(biāo)還不可以正確的顯示
//必須先安裝金山詞霸中的Font目錄中的Phonetic Plain字體
//實(shí)現(xiàn)音標(biāo)的正確顯示
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
start,ends:integer;
begin
RConv.Clear;
for i:=0 to RTrans.Lines.Count-1 do
begin
richedit3.Text :=RTrans.Lines[i];
start:=pos('[',richedit3.Text);//查找音標(biāo)位置,音標(biāo)在[]中
if start>0 then
begin
ends:=pos(']',richedit3.Text);
richedit3.SelStart :=start;
richedit3.SelLength :=ends-start-1;
richedit3.SelAttributes.Name :='Kingsoft Phonetic Plain';
end;
richedit3.SelectAll ;
richedit3.CopyToClipboard ;
RConv.PasteFromClipboard;
application.ProcessMessages;
end;
end;
//程序退出
procedure TForm1.N3Click(Sender: TObject);
begin
application.Terminate ;
end;
//復(fù)制 功能
procedure TForm1.N6Click(Sender: TObject);
begin
RConv.SelectAll ;
RConv.CopyToClipboard;
end;
//停止轉(zhuǎn)換
procedure TForm1.N8Click(Sender: TObject);
begin
timer1.Enabled :=false;
end;
end.
好了,到此為止,全部的程序就設(shè)計(jì)完畢了。
如何運(yùn)行:
保證“金山詞霸 2002”和該程序一起運(yùn)行,如果你使用其他版本的詞霸的話,請(qǐng)自行更改其中的查找句柄代碼,以實(shí)現(xiàn)支持其他版本。
好了,我現(xiàn)在已經(jīng)成功將這600個(gè)單詞翻譯完成,并用Word打印到紙上了,非常的快捷,如果你還有什么好的建議,歡迎回復(fù)!
如何獲得編譯好的可執(zhí)行程序和源代碼:
可以給我發(fā)電子郵件:[email protected]
或者登陸我的站點(diǎn)留言:http://redlegend.51.net
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注