关于EnumChildWindows的用法!(50分)

BOOL EnumChildWindows(
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);

关键在于定义一个回调函数,EnumChildWindows每取到一个ChileWindow,
就会执行回调函数,回调函数有ChildWindow的Handle
回调函数:
BOOL CALLBACK EnumChildProc(
HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
);
Win32API的说明更详细
 
{our callback function prototype}
function EnumerateChildWindows(hWnd:HWND; lParam:LPARAM): BOOL; stdcall;

var
Form1: TForm1;

implementation

procedure TForm1.EnumerateChildWindows1Click(Sender: TObject);
begin
{empty our list box}
ListBox1.Items.Clear;

{enumerate all child windows belonging to Form1}
EnumChildWindows(Form1.Handle,@EnumerateChildWindows,0);

end;

{these steps execute for every child window belonging to the parent}
function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL;
var
ClassName: Array[0..255] of char; // this holds the class name of our child windows
begin
{get the class name of the given child window}
GetClassName(hWnd,ClassName,255);

{display it in the list box}
Form1.ListBox1.Items.Add(ClassName);

{continue enumeration}
Result:=TRUE;
end;

 
定义一个回调函数:
function EnumChildProc(Myhwnd: HWND; lParam: LPARAM): Boolean;stdCall;
begin
  //你的代码
  Result:=False;//设为True则停止
end;


在程序中调用:
enumchildwindows(hWndProgram,@EnumChildProc,0);//hWndProgram为父窗口的句柄
 
接受答案了.
 
我想收藏 
 
顶部