for i := 0 to Screen.FormCount - 1 do begin ShowMessage(Screen.Forms[i].Caption); // Screen.Forms[i].Name ??? ShowMessage(IntToStr(Screen.Forms[i].Height)); ShowMessage(IntToStr(Screen.Forms[i].Width)); end;
To Chechy 你的方法好象不可以吧,Forms属性只是当前应用程序包含窗口的列表,不是系统中所有应用程序包含窗口的列表! “请问如何遍历现在系统中所有的窗口”,楼主要的是“系统”中所有窗口.....
你是不是要列出所有的进程啊??如果是的话看看下面的函数对你有没有用 //uses TLHelp32 var lppe: TProcessEntry32; found : boolean; Hand : THandle; begin Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); found := Process32First(Hand,lppe); while found do begin ListBox.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。 found := Process32Next(Hand,lppe); end; end;
procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin for i:=1 to application.componentcount-1 do begin showmessage(application.components[i].name); //其他自己写 end end;
用api函数 BOOL EnumWindows( WNDENUMPROC lpEnumFunc, // pointer to callback function LPARAM lParam // application-defined value ); 这样,自己还要写一个回掉函数,来处理显示这些Windows得特性。
搞定,下面得函数我测试过! function MyProc(AHandle: HWND; lParam: Longint): Boolean; stdcall; var Name: string; ARect: TRect; begin SetLength(Name, 256); GetWindowText(AHandle, PChar(Name), 255); GetWindowRect(AHandle, ARect); TListBox(lParam).Items.Add(Format('Width=%d, Height=%d, Name:%s', [ARect.Right - ARect.Left, ARect.Bottom - ARect.Top, Name])); Result := True; end;procedure TForm1.Button1Click(Sender: TObject); begin EnumWindows(@MyProc, Integer(ListBox1)); end;
begin
ShowMessage(Screen.Forms[i].Caption); // Screen.Forms[i].Name ???
ShowMessage(IntToStr(Screen.Forms[i].Height));
ShowMessage(IntToStr(Screen.Forms[i].Width));
end;
你是不是要列出所有的进程啊??如果是的话看看下面的函数对你有没有用
//uses TLHelp32
var lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
begin
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found := Process32First(Hand,lppe);
while found do
begin
ListBox.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。
found := Process32Next(Hand,lppe);
end;
end;
我本来想贴点代码出来,看来不用了
api函数里有查看进程的函数.(我以前用vb作过,但delphi其实也是一样的)
var
i:integer;
begin
for i:=1 to application.componentcount-1 do
begin
showmessage(application.components[i].name);
//其他自己写
end
end;
BOOL EnumWindows( WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);
这样,自己还要写一个回掉函数,来处理显示这些Windows得特性。
function MyProc(AHandle: HWND; lParam: Longint): Boolean; stdcall;
var
Name: string;
ARect: TRect;
begin
SetLength(Name, 256);
GetWindowText(AHandle, PChar(Name), 255);
GetWindowRect(AHandle, ARect);
TListBox(lParam).Items.Add(Format('Width=%d, Height=%d, Name:%s',
[ARect.Right - ARect.Left, ARect.Bottom - ARect.Top, Name]));
Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@MyProc, Integer(ListBox1));
end;