利用Delphi和金山词霸制作批量单词翻译[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 neoking 的 blog

  public
    { public declarations }
  end;

var
  form1: tform1;
  i:integer=0;//声明一个全局变量,用于单词的记数
implementation

{$r *.dfm}

//开始转换事件
procedure tform1.button1click(sender: tobject);
begin
  rtrans.clear;//清空转换区
  rconv.clear;
  timer1.interval:=strtoint(edit1.text)*1000;//设置间隔时间
  timer1.enabled :=true;//
  progressbar1.position:=0;//设置进度条状态
  i:=0;//初始化变量,用于记数
  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];
    //存储信息
    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 复制
    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;//进度条移动

本文关键:利用Delphi和金山词霸制作批量单词翻译
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top