用回调函数:<br>var<br> HandleList: array of Longint; //存储窗口句柄的数组<br> WndClass, WndTitle: string; //窗口类名、窗口标题<br><br>procedure FindWindowEx;<br> function EnumFunc(const hWnd: Longword; lParam: Longint): BOOL; stdcall;<br> var<br> lpWndClass, lpWndTitle: array[0..255] of Char;<br> len: Integer;<br> begin<br> GetClassName(hWnd, lpWndClass, 255);<br> GetWindowText(hWnd, lpWndTitle, 255);<br> if (lpWndClass = WndClass) and (lpWndTitle = WndTitle) then<br> begin<br> len := Length(HandleList);<br> SetLength(HandleList, len + 1);<br> HandleList[len] := hWnd;<br> end;<br> Result := True;<br> end;<br>begin<br> EnumWindows(@EnumFunc, 0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> WndClass := 'TForm1';<br> WndTitle := 'Form1';<br> FindWindowEx;<br> ShowMessage(IntToStr(Length(HandleList)));<br>end;