1,183
社区成员
发帖
与我相关
我的任务
分享
//句柄和进程一一对应的结构体
type twindata=record
pid: DWORD;
hwd:hwnd;
end;
var
all_td:array of twindata;
function EnumWindowsProc(Wnd: HWND; var lp: integer): Bool; stdcall;
var
PID: DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
setlength(all_td,length(all_td)+1);
all_td[length(all_td)-1].pid:=PID;
all_td[length(all_td)-1].hwd:=Wnd;
end;
Result := True;
end;
procedure get_all_window_list();
begin
EnumWindows(@EnumWindowsProc, 0);
//EnumDesktopWindows(0,@EnumWindowsProc, 0); //两个好像没区别
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
tmp_wintext:array[0..254] of wideChar;
begin
setlength(all_td,0);
get_all_window_list();
ListView1.Clear;
for I := Low(all_td) to High(all_td) do
begin
GetWindowTextW(all_td[i].hwd,@tmp_wintext,SizeOf(tmp_wintext));
with listview1.items.add do
begin
caption:= inttostr(all_td[i].pid); //pid
subitems.add(inttostr(all_td[i].hwd)); //hwd
subitems.add(tmp_wintext); //标题
subitems.Add(booltostr(IsWindowVisible(all_td[i].hwd),true)); //是否显示
subitems.Add(inttostr(GetParent(all_td[i].hwd))); //父句柄
subitems.Add(inttostr(GetWindow(all_td[i].hwd, GW_OWNER))); //状态1
subitems.Add(inttostr(GetWindow(all_td[i].hwd, GW_CHILD))); //状态2
subitems.Add(inttostr(GetTopWindow(all_td[i].hwd))); //状态3
subitems.Add(inttostr(GetWindowLong(all_td[i].hwd, GWL_HWNDPARENT))); //状态4
subitems.Add(inttostr((GetWindowLong(all_td[i].hwd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW))); //状态5
end;
end;
end;