模擬安裝程式自動化 |
尚未結案
|
jhlin1005
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2010-03-25 發送簡訊給我 |
Hello! 大家好!
最近在實作模擬程式安裝自動化,以安裝teraterm-4.64.exe為例,在安裝的過程中會出現LogMeTT Installation Wizard視窗,我的操作流程是當跳出LogMeTT Installation Wizard視窗的時候會按Cancel按鈕,然後跳出Exit Setup視窗然後按"是"這按鈕,但是在執行的時候,當跳出LogMeTT Installation Wizard視窗時,卻偵測不到,必須手動按Cancel按鈕以及之後跳出Exit Setup視窗的"是"這個按鈕,最後程式會自動按Finish按鈕。 在此想請問一下安裝過程中所跳出的新視窗為什麼偵測不到?
------
這就是人蔘! 編輯記錄
jhlin1005 重新編輯於 2010-04-16 11:59:28, 註解 無‧
|
jhlin1005
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2010-03-25 發送簡訊給我 |
[code delphi]
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; function EnumChildProc(h: Hwnd; a: integer): Boolean; stdcall; function EnumChildProc1(b: Hwnd; a: integer): Boolean; stdcall; function EnumChildProc2(c: Hwnd; a: integer): Boolean; stdcall; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var h : HWND; begin ShellExecute(self.Handle, nil, 'teraterm-4.64.exe', nil, nil, SW_NORMAL); Sleep(2000); h:=FindWindow(nil, PChar('Setup - Tera Term')); while h <> 0 do begin h:=FindWindow(nil, PChar('Setup - Tera Term')); EnumChildWindows(h, @EnumChildProc, 0);//當Setup - Tera Term視窗沒消失則重複偵測,並執行按鈕動作 end; end; function EnumChildProc(h: hwnd; a: integer): Boolean; stdcall; var str: Array[0..1024] of Char; b : HWND; begin Result := true; if h <> 0 then begin GetClassName(h, str, 1024); SendMessage(h, WM_GETTEXT, 1024, integer(@str[0])); if str = 'I &accept the agreement' then begin SendMessage (h, WM_LBUTTONDOWN, 0, 0); SendMessage (h, WM_LBUTTONUP, 0, 0); Sleep(30); end; if str = '&Next >' then begin SendMessage (h, WM_LBUTTONDOWN, 0, 0); SendMessage (h, WM_LBUTTONUP, 0, 0); end; if str = '&Install' then begin SendMessage (h, WM_LBUTTONDOWN, 0, 0); SendMessage (h, WM_LBUTTONUP, 0, 0); //當按下install鍵後開始安裝,並偵測新的安裝視窗LogMeTT Installation Wizard b := FindWindow(nil, PChar('LogMeTT Installation Wizard')); while b <> 0 do begin b := FindWindow(nil, PChar('LogMeTT Installation Wizard')); EnumChildWindows(b, @EnumChildProc1, 0); //當偵測到LogMeTT Installation Wizard視窗,並執行Cancel按鈕動作 end; end; if str = '&Finish' then begin SendMessage (h, WM_LBUTTONDOWN, 0, 0); SendMessage (h, WM_LBUTTONUP, 0, 0); end; Sleep(30); end; end; function EnumChildProc1(b: hwnd; a: integer): Boolean; stdcall; var str: Array[0..1024] of Char; c : HWND; begin Result := true; if b <> 0 then begin GetClassName(b, str, 1024); SendMessage(b, WM_GETTEXT, 1024, integer(@str[0])); if str = 'Cancel' then begin SendMessage (b, WM_LBUTTONDOWN, 0, 0); SendMessage (b, WM_LBUTTONUP, 0, 0); //當按下Cancel鍵後開始安裝,並偵測新的Exit Setup視窗 c := FindWindow(nil, PChar('Exit Setup')); while c <> 0 do begin c := FindWindow(nil, PChar('Exit Setup')); EnumChildWindows(c, @EnumChildProc2, 0); end; //當偵測到Exit Setup視窗,並執行"是"按鈕動作 end; Sleep(30); end; end; function EnumChildProc2(c: hwnd; a: integer): Boolean; stdcall; var str: Array[0..1024] of Char; begin Result := true; if c <> 0 then begin GetClassName(c, str, 1024); SendMessage(c, WM_GETTEXT, 1024, integer(@str[0])); if str = '是(&Y)' then begin SendMessage (c, WM_LBUTTONDOWN, 0, 0); SendMessage (c, WM_LBUTTONUP, 0, 0); end; end; end; end. [/code] 在此我想問一下FindWindow以及EnumChildWindows在上述程式碼中 是否可以這樣用? 這樣用為什麼沒辦法達到我預期的效果?跳出LogMeTT Installation Wizard視窗就卡在那了
------
這就是人蔘!
編輯記錄
jhlin1005 重新編輯於 2010-04-21 12:50:56, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |