帖出来方便大家吧
这个方法说白了就是捕捉警告窗口然后再做处理,但还是需要鼠标点一下
由于警告窗口出现时调用过程会被挂起,因此做了个2个进程,次进程反复监视这个窗口
[只支持简体中文]
希望大家继续完善
代码如下
//监视的进程
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes;
type
TSearchOEThread = class (TThread)
Public
procedure Execute;override;
end;
implementation
function EnumChildProc(AHWnd: HWnd;LPARAM: lParam): boolean; stdcall;
var
WndCaption: array[0..254] of char;
WndClassName: array[0..254] of char;
Caption:String;
WndGetCaption
char;
TextLength:Integer;
begin
GetWindowText(AHWnd, @WndCaption, 254);
GetClassName(AHWnd, @WndClassName, 254);
Caption:=strpas(WndCaption);
if Caption='' then
begin
TextLength:= SendMessage(AHWnd, WM_GETTEXTLENGTH, 0, 0);
if TextLength>0 then
begin
GetMem(WndGetCaption,TextLength+1);
SendMessage(AHWnd, WM_GETTEXT, TextLength+1, LongInt(WndGetCaption));
Caption:=WndGetCaption;
FreeMem(WndGetCaption);
end;
end;
if Caption='允许访问(&A)' then //自动打钩允许
if SendMessage(AHWnd,BM_GETCHECK, 0, 0)=BST_UNCHECKED then begin
PostMessage(AHWnd,WM_LBUTTONDOWN,0,0);
PostMessage(AHWnd,WM_LBUTTONUP,0,0);
end;
if strpas(WndClassName)='ComboBox' then begin //设置为最长时间
PostMessage(AHWnd,CB_SETCURSEL,SendMessage(AHWnd,CB_GETCOUNT,0,0)-1,0);
end;
if Caption='是' then begin //按确认(效果不完全,郁闷啊)
PostMessage(AHWnd,BM_CLICK,0,0);
end;
EnumChildWindows(AHWnd, @EnumChildProc, LParam+1);
Result := True;
end;
procedure TSearchOEThread.Execute;
var
wH: HWND;
begin
FreeOnTerminate := True;
OnTerminate := ThreadTerminate;
While not Terminated do begin
//捕捉窗口
//Outlook2002
wH:=FindWindow('#32770','Microsoft Outlook');
//Outlook2003
if wH=0 then wH:=FindWindow('#32770','Microsoft Office Outlook');
//前置窗口
SetWindowLong(wH, GWL_EXSTYLE, GetWindowLong(wH, GWL_EXSTYLE) or WS_EX_TOPMOST);
//枚举窗口控件
if wH<>0 then EnumChildWindows(wH,@EnumChildProc,0);
sleep(100);
end;
end;
end.
//调用方法
uses Unit2
var
SearchOEThread:TSearchOEThread;
//运行
SearchOEThread:=TSearchOEThread.Create(True);
SearchOEThread.Priority:=tpLower;
SearchOEThread.Resume;
//结束
if Assigned(SearchOEThread) then begin
while SearchOEThread.Suspended do SearchOEThread.Resume;
SearchOEThread.Terminate;
end;