例:<br>type<br> { Define a record/class to hold the window name and class name for<br> each window. Instances of this class will get added to ListBox1 }<br> TWindowInfo = class<br> WindowName, // The window name<br> WindowClass: String; // The window's class name<br> fmhwnd: thandle;<br> end;<br><br>// lbWinInfo: TListBox;<br><br>function EnumWindowsProc(Hw: HWnd; AMainForm: TMainForm): Boolean; stdcall;<br>var<br> WinName, CName: array[0..144] of char;<br> i: integer;<br>begin<br> Result := True;<br> GetWindowText(Hw, WinName, 144); // Obtain the current window text<br> GetClassName(Hw, CName, 144); // Obtain the class name of the window<br> if iswindowvisible(hw) then<br> begin<br> WindowInfo := TWindowInfo.Create;<br> with WindowInfo do<br> begin<br> SetLength(WindowName, strlen(WinName));<br> SetLength(WindowClass, StrLen(CName));<br> WindowName := StrPas(WinName);<br> WindowClass := StrPas(CName);<br> fmhwnd := hw;<br> end;<br>// lbWinInfo.Items.AddObject('', WindowInfo); // Add to Objects array<br> end;<br>end;<br>