在delphi中如何获取所有已运行程序的名称和该程序的窗口标题,有谁知道,非常感谢!
解决方案 »
- 急!日期 型转换为固定格式的字符串
- c/s模式下的数据读取与更新,进着有分。。。问题,再开新贴加分
- 如何把sql server 中的一个表导出到sql server 之外
- Tworddocument控件中,如何实现将Tworddocument的内容保存到指定的地方(已提供原代码参考)。请教
- 我初学,请问窗体的高度怎么设置成1200,现在只能设成612,我不知道改那个属性。请高手赐教!
- delphi小问题
- 紧急救助:线程中出现莫名问题!
- 一个sql 脚本文件怎么在delphi中执行?
- 巨分求救,我一定给分,问题对于稍微懂的人应该不在话下
- treeview在公司管理层次结构上的实现!赠送原代码!
- 如何释放掉线程
- 没辙了,只好写个dll,可是不懂delphi,手头也没有资料,请教如何输出函数。
可以得到程序名称并不是所有的程序都是有窗体的,对于有窗体的程序可以先用EnumWindows得到窗体句柄
再用GetWindowThreadProcessId得到窗体所属进程ProcessId,然后用OpenProcess得到进程句柄
用进程句柄查上面枚举出来的进程信息,就可以知道窗体所属进程其它信息
p: pProcessInfo;
ContinueLoop: BOOL;
FSnapshotHandle, hProcess: THandle;
FProcessEntry32: TProcessEntry32;begin
New(p);
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop)<>0 do
begin
p.ExeFile:= FProcessEntry32.szExeFile;
memo1.lines.add(p.ExeFile);
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;//以下MEMO2列出窗口名单
function GetWindow1(btitle:string):boolean;
var winhandle: Hwnd;
winprocess: Dword;
title:pchar;
begin
result:=false;
Getmem(title,255);
winhandle:=GetWindow(GetForeGroundWindow,GW_HWNDFIRST);
while winhandle<>0 do
begin
if (IsWindowEnabled(winhandle) and IsWindow(winhandle)) then
begin
// GetWindowThreadProcessId(winhandle,@winprocess);
GetWindowText(winhandle,title,255);
if length(title)>0 then
begin
memo2.lines.add(title);
end;
end; winhandle:=GetWindow(winhandle,GW_HWNDNEXT);
end;Freemem(title);
CloseHandle(winHandle);
result:=true;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
WindowsNameListBox: TListBox;
ListButton: TButton;
procedure ListButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ListButtonClick(Sender: TObject);
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
WindowsNameListBox.Clear;
//获取第一个窗口的句柄
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
//获取窗口的名称
if GetWindowText(hCurrentWindow, @szText, 255)>0 then
WindowsNameListBox.Items.Add(StrPas(@szText));
//获取下一窗口的句柄
hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
end.接分ing。