呵呵,给你这么多源码,还不给我分先??
type
pfindwindowstruct=^tfindwindowstruct;
tfindwindowstruct=record
caption:string;
classname:string;
windowhandle:thandle;
end;
function enumwindowsproc(hwindow:hwnd;lparam:longint):bool
{$IFDEF WIN32}STDCALL;{$ELSE};EXPORT;{$ENDIF}
VAR lpbuffer
char;
windowcaptionfound:bool;
classnamefound:bool;
begin
getmem(lpbuffer,255);
result:=true;
windowcaptionfound:=false;
classnamefound:=false;
try
if getwindowtext(hwindow,lpbuffer,255)>0 then
if pos(pfindwindowstruct(lparam).caption,strpas(lpbuffer))>0 then
windowcaptionfound:=true;
if pfindwindowstruct(lparam).classname='' then
classnamefound:=true else
if getclassname(hwindow,lpbuffer,255)>0 then
if pos(pfindwindowstruct(lparam).classname,strpas(lpbuffer))>0 then
classnamefound:=true;
if (windowcaptionfound and classnamefound) then begin
pfindwindowstruct(lparam).windowhandle:=hwindow;
result:=false;
end;
finally
freemem(lpbuffer,sizeof(lpbuffer^));
end;
end;
function findawindow(caption:string;classname:string):thandle;
var windowinfo:tfindwindowstruct;
begin
begin
windowinfo.caption:=caption;
windowinfo.classname:=classname;
windowinfo.windowhandle:=0;
enumwindows(@enumwindowsproc,longint(@windowinfo));
findawindow:=windowinfo.windowhandle;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var thewindowhandle:thandle;
begin
thewindowhandle:=findawindow('浏','');
if thewindowhandle=0 then
begin
showmessage('window not found!');
winexec('explorer.exe',sw_show);
end
else
bringwindowtotop(net);
end;
end;