回调涵数就是给系统涵数调用的涵数,由自己定义的。跟普通涵数的区别就是要 符合某种协约; 如下是实例 function Enumwndproc( Hwindow:Hwnd;param: lparam): boolean stdcall ; var buffer1,buffer2:Pchar; //FoundCaption:boolean; // FoundClname:boolean; begin result:=true; getmem(buffer1,255); getmem(buffer2,255); try if GetWindowText(Hwindow,buffer1,255)>0 then if pos( PwindowstructInfo(param).caption,strpas(buffer1))>0 then result := false; if GetClassName(hwindow,buffer2,255)>0 then if pos( PwindowstructInfo(param).calname,strpas(buffer2))>0 then Result := False; if Result = False then PwindowstructInfo(param).wndhandle:=Hwindow; //返回查找到的窗口句柄 finally freemem(buffer1); freemem(buffer2); end;
end;这是调用; function FindAwindow(caption, clname: string): Thandle; var wndInfo:Twindowstruct; begin wndInfo.caption:=caption; wndInfo.calname:=clName; wndInfo.wndhandle:=0; EnumWindows(@Enumwndproc,Lparam(@wndInfo)); FindAwindow:=wndInfo.wndhandle; end;
符合某种协约; 如下是实例
function Enumwndproc( Hwindow:Hwnd;param: lparam): boolean stdcall ;
var
buffer1,buffer2:Pchar;
//FoundCaption:boolean;
// FoundClname:boolean;
begin
result:=true;
getmem(buffer1,255);
getmem(buffer2,255);
try
if GetWindowText(Hwindow,buffer1,255)>0 then
if pos( PwindowstructInfo(param).caption,strpas(buffer1))>0 then
result := false; if GetClassName(hwindow,buffer2,255)>0 then
if pos( PwindowstructInfo(param).calname,strpas(buffer2))>0 then
Result := False; if Result = False then
PwindowstructInfo(param).wndhandle:=Hwindow; //返回查找到的窗口句柄
finally
freemem(buffer1);
freemem(buffer2);
end;
end;这是调用;
function FindAwindow(caption, clname: string): Thandle;
var
wndInfo:Twindowstruct;
begin
wndInfo.caption:=caption;
wndInfo.calname:=clName;
wndInfo.wndhandle:=0;
EnumWindows(@Enumwndproc,Lparam(@wndInfo));
FindAwindow:=wndInfo.wndhandle;
end;