procedure TForm1.Button1Click(Sender: TObject); var hCurrentWindow: HWnd; szText: array[0..254] of char; begin hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST); While hCurrentWindow <> 0 Do Begin If GetWindowText(hCurrentWindow, @szText, 255) > 0 Then ListBox1.Items.add(Strpas(@szText)); hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT); End; end;
TProcessinfo的定义 type TProcessInfo=Record ExeFileName:String; ProcessID:DWord; end;参数 l 一个ListView的变量,P一个TProcessInfo的变量Function Findthread(var l:TListView,P:Tprocessinfo): Boolean; Var Ok:Bool; Processlisthandle:Thandle; Processstruct:Tprocessentry32; Begin Result:=False; Processlisthandle:=Createtoolhelp32Snapshot(Th32Cs_Snapprocess,0); ProcessStruct.dwSize:=SizeOf(ProcessStruct); Ok:=Process32First(Processlisthandle,Processstruct); While Integer(Ok)<>0 Do Begin P.Exefilename:=Processstruct.Szexefile; P.Processid:=Processstruct.Th32Processid; Ok:=Process32Next(Processlisthandle,Processstruct); l:=ListView1.Items.Add; l.Caption:= P.ExefileName; l.SubItems.Add(inttoStr(P.Processid)); l.SubItems.Add(inttoStr(Processstruct.pcPriClassBase)); End; Closehandle(Processlisthandle); End;你试试看。有什么问题贴出来。
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
While hCurrentWindow <> 0 Do
Begin
If GetWindowText(hCurrentWindow, @szText, 255) > 0 Then
ListBox1.Items.add(Strpas(@szText));
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
End;
end;
TProcessInfo=Record
ExeFileName:String;
ProcessID:DWord;
end;参数 l 一个ListView的变量,P一个TProcessInfo的变量Function Findthread(var l:TListView,P:Tprocessinfo): Boolean;
Var
Ok:Bool;
Processlisthandle:Thandle;
Processstruct:Tprocessentry32;
Begin
Result:=False;
Processlisthandle:=Createtoolhelp32Snapshot(Th32Cs_Snapprocess,0);
ProcessStruct.dwSize:=SizeOf(ProcessStruct);
Ok:=Process32First(Processlisthandle,Processstruct);
While Integer(Ok)<>0 Do
Begin
P.Exefilename:=Processstruct.Szexefile;
P.Processid:=Processstruct.Th32Processid;
Ok:=Process32Next(Processlisthandle,Processstruct);
l:=ListView1.Items.Add;
l.Caption:= P.ExefileName;
l.SubItems.Add(inttoStr(P.Processid));
l.SubItems.Add(inttoStr(Processstruct.pcPriClassBase));
End;
Closehandle(Processlisthandle);
End;你试试看。有什么问题贴出来。
http://www.csdn.net/Develop/Read_Article.asp?Id=15817
你在前面Uses一下就可以啦~~naughtyboy都是一些API函数。naughtyboy的方法不能说不好,我原来就写过类似的程序,但发现它不能找到没有标题的
窗口(没有标题栏或者标题为空),有其局限性。