用EnumWindows和EnumChildWindows枚举不到全部窗口?

lght 2009-12-11 05:34:23
为什么用SPY++看到的窗口比我用这两个函数枚举出来的多?
也就是一些窗口枚举不到,为什么?

还有一些在桌面上可以用SPY++看到的都枚举不到。
...全文
1458 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
twoods 2012-06-10
  • 打赏
  • 举报
回复
最近在用 EnumChildWindows 的时候,同样发现楼主的问题。就是它枚举不全,有遗漏。找遍整个网络,也找不到解决的办法。
nanchangfantasy 2009-12-18
  • 打赏
  • 举报
回复
怎么可能,
主窗口,次窗口,你没分清楚而已
findwindow 只找顶层窗口,而findwindowex找子窗口.
----------------
spy能找的,你都能找到
lght 2009-12-15
  • 打赏
  • 举报
回复
楼上的朋友,你的代码依然枚举不完全。

楼上有朋友说是我不会用,看来不只是我。
lght 2009-12-14
  • 打赏
  • 举报
回复
GetWindow可以找到,EnumWindows不行,FindWindow,FindWindowEx也不行?
什么原因?
slmax1 2009-12-14
  • 打赏
  • 举报
回复
虽然不是全部都能用到,但可以参考其中。
slmax1 2009-12-14
  • 打赏
  • 举报
回复

unit HexDecBinInt;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
cScaleChar = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function IntPower(Base, Exponent: Integer): Integer;
function DigitToInt(mDigit: string; mScale: Byte): Integer;
function IntToDigit(mNumber: Integer; mScale: Byte;
mLength: Integer = 0): string;
implementation
//------------------------------------------------------------------------------
function IntPower(Base, Exponent: Integer): Integer; { 返回Base的Exponent次方 }
var
I: Integer;
begin
Result := 1;
for I := 1 to Exponent do
Result := Result * Base;
end; { IntPower }
//------------------------------------------------------------------------------

function DigitToInt(mDigit: string; mScale: Byte): Integer;
{ 返回进制表示转换成整数;mScale指定多少进制 }
var
I: Byte;
L: Integer;
begin
Result := 0;
mDigit := UpperCase(mDigit);
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], cScaleChar) - 1) *
IntPower(mScale, I - 1);
end; { DigitToInt }
//------------------------------------------------------------------------------
function IntToDigit(mNumber: Integer; mScale: Byte;
mLength: Integer = 0): string;
{ 返回整数的进制表示;mScale指定多少进制;mLength指定长度,长度不足时向前补0 }
var
I, J: Integer;
begin
Result := '';
I := mNumber;
while (I >= mScale) and (mScale > 1) do begin
J := I mod mScale;
I := I div mScale;
Result := cScaleChar[J + 1] + Result;
end;
Result := cScaleChar[I + 1] + Result;
for I := 1 to mLength - Length(Result) do Result := '0' + Result;
end; { IntToDigit }
end.
slmax1 2009-12-14
  • 打赏
  • 举报
回复

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, HexDecBinInt;

type
TForm1 = class(TForm)
lst1: TListBox;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//------------------------------------------------------------------------------

//回调函数

//------------------------------------------------------------------------------

function EnumChildWindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
var
ssText:array[0..254] of Char;
id:Integer;
begin
GetWindowText(hWnd,ssText,255);
id:=GetDlgCtrlID(hWnd);
if Trim(StrPas(sstext)) <> '' then
Form1.lst1.Items.Add(' ------>' + ssText + '---->' + IntToDigit(id,16,0));
result:=True;
end;
//------------------------------------------------------------------------------

function EnumwindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
var
sText:array[0..254] of Char;
id:Integer;
begin
GetWindowText(hWnd,sText,255);
id:=GetDlgCtrlID(hWnd);
if Trim(StrPas(sText)) <> '' then
begin
Form1.lst1.Items.Add(Trim(StrPas(sText)) + '---->' + IntToStr(id));;
EnumChildWindows(hWnd,@EnumChildWindowsProc,0);
end;
result:=True;
end;
//------------------------------------------------------------------------------


procedure TForm1.btn1Click(Sender: TObject);
begin
lst1.Clear;
EnumWindows(@EnumwindowsProc,0);
end;
hjkto 2009-12-11
  • 打赏
  • 举报
回复 1

function EnumWinProc(Wnd : HWND; form1 : TForm1) : Boolean; Export; {$IFDEF Win32}StdCall;{$ENDIF}
var
WinText : Array[0..255] of Char;
begin
GetWindowText(Wnd, WinText, 255);
Result := True;
if (StrPas(WinText)<>'') then
Form1.ListBox1.Items.Add(StrPas(WinText));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWinProc, LongInt(Self));
end;



你可以揭帖了
以上两段代码都能达到你的要求
hjkto 2009-12-11
  • 打赏
  • 举报
回复

procedure TForm1.Button1Click(Sender: TObject);
var
h: HWnd;
p: array[0..254] of char;
begin
h := GetWindow(Handle, GW_HWNDFIRST);
while h <> 0 do
begin
if GetWindowText(h, p, 255) > 0 then Memo1.Lines.Add(p);
h := GetWindow(h, GW_HWNDNEXT);
end;
end;



楼主试试这段代码,看看和spy找到是不是一样
lght 2009-12-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mwy654321 的回复:]
不可能枚举不到的,是你不会用所导致。
[/Quote]

那要怎么用?
无条件为你 2009-12-11
  • 打赏
  • 举报
回复
不可能枚举不到的,是你不会用所导致。

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧