我是用定时器枚举一个特定的句柄的窗口,if找到就建立一个窗口,不过关掉时它又弹出一个,如何if条件成立只建立一个窗口?
也就是找到一个特定的窗口只为他建立一个窗口,那边定时器一直在枚举窗口。
下面是我的代码,function EnumChildProc (Childhwnd: THandle; Param: Pointer): Boolean; stdcall;
var
dlghwnd:THandle;
path : string;
Modal :TWinSortDialog;
begin
Result := True;
Setlength(childwindowtext,100);
getwindowtext (Childhwnd,pchar(childwindowtext),100);
childwindowtext := pchar(childwindowtext);
Reg:=tregistry.create;
if AnsiStartsText(Path,childwindowtext)=true then
begin
modal:=TWinSortDialog.Create (Application);
try
Modal.ShowModal;
finally
Modal.Free;
end;
end;
Result := False;
end;procedure TWinSort.Timer1Timer(Sender: TObject);
begin
EnumChildWindows(FoundWnd,@EnumChildProc,0);
end;
也就是找到一个特定的窗口只为他建立一个窗口,那边定时器一直在枚举窗口。
下面是我的代码,function EnumChildProc (Childhwnd: THandle; Param: Pointer): Boolean; stdcall;
var
dlghwnd:THandle;
path : string;
Modal :TWinSortDialog;
begin
Result := True;
Setlength(childwindowtext,100);
getwindowtext (Childhwnd,pchar(childwindowtext),100);
childwindowtext := pchar(childwindowtext);
Reg:=tregistry.create;
if AnsiStartsText(Path,childwindowtext)=true then
begin
modal:=TWinSortDialog.Create (Application);
try
Modal.ShowModal;
finally
Modal.Free;
end;
end;
Result := False;
end;procedure TWinSort.Timer1Timer(Sender: TObject);
begin
EnumChildWindows(FoundWnd,@EnumChildProc,0);
end;
flag:boolean;
procedure TWinSort.Timer1Timer(Sender: TObject);
begin
if not flag then
EnumChildWindows(FoundWnd,@EnumChildProc,0);
end;在你建立的那个模态窗口的onclose事件里 flag:=true;这样应该可以了
var
HWNDPREVhwnd : thandle;
flag:boolean;
begin
好像还不行,我的Timer1Timer事件是这样的
var
HWNDPREVhwnd : thandle;
flag:boolean;
begin
EnumWindows(@EnumProc,0);
if FoundWnd <> 0 then
begin
if not flag then
EnumChildWindows(FoundWnd,@EnumChildProc,0);
end;
end;