Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.09.03;
Скачать: CL | DM;

Вниз

Перечисление окон Windows   Найти похожие ветки 

 
Delphi-Beginner   (2006-08-08 09:45) [0]

Привет всем, не пинайте сильно за вопрос, так как я еще пока учусь программировать на Delphi.
Короче мне надо перечислить все окна в системе, title которых не равно пустой строке.
Использовал два способа — EnumWindows и GetWindow, однако эти 2 способа дают разные результаты.
Окна, которые не перечисляются в первом способе, перечисляются во втором и наоборот.
Может чего делаю не так, подскажите пожалуйста.

Способ 1: EnumWindows и EnumChieldWindows с callback- oм

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
lst :TStringList;

implementation

{$R *.dfm}

//Просто добавить строку в список
procedure AddToList (s :string);
begin
lst.Add(s);
end;

//Перечислить дочерние окна
function EnumChildProc(wdc :hwnd; Param :LongInt) :boolean; stdcall;

var
buf :array[0..250] of char;
s :string;

begin
GetWindowText(wdc, buf, sizeof(buf));
s := StrPas(buf);
if (s <> "") then
AddToList(s);
EnumChildProc := true;
end;

//Перечислить основные окна
function EnumProc (Wd: HWnd; Param: LongInt): Boolean; stdcall;

var
buf :array[0..250] of char;
s :string;

begin
GetWindowText(wd, buf, sizeof(buf));
s := StrPas(buf);
if (s <> "") and (GetWindowLong(Wd, GWL_HWNDPARENT) = 0) then
begin
AddToList(s);
end else
begin
EnumChildWindows(wd, @EnumChildProc, 0);
end;
EnumProc := true;
end;

//Основная процедура перечисления
procedure TForm1.Button1Click(Sender: TObject);

begin
EnumWindows(@EnumProc, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);

begin
lst := TStringList.Create;
end;

//Сохранить список в файл
procedure TForm1.Button2Click(Sender: TObject);

begin
lst.SaveToFile("windowlist.txt");
end;

end.

Способ 2: Использование GetWindow

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
lst :TStringList;

implementation

{$R *.dfm}

procedure AddToList (s :string);
begin
lst.Add(s);
end;

//Основная процедура перечисления
procedure TForm1.Button1Click(Sender: TObject);

var
Wnd : hWnd;
buff: array [0..127] OF Char;
s :string;

begin
lst.Clear;

Wnd := GetWindow(Application.Handle, gw_HWndFirst);
while Wnd <> 0 do
begin
GetWindowText(Wnd, buff, sizeof(buff));
s := StrPas(buff);
if s <> "" then
begin
lst.add(s);
end;
Wnd := GetWindow(Wnd, gw_hWndNext);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);

begin
lst := TStringList.Create;
end;

procedure TForm1.Button2Click(Sender: TObject);

begin
lst.SaveToFile("windowlist2.txt");
end;

end.


 
Eraser ©   (2006-08-08 18:51) [1]

> [0] Delphi-Beginner   (08.08.06 09:45)

The EnumWindows function enumerates all top-level windows on the screen.. (c) MSDN
А GetWindow вообще то не предназначена для поиска всех окон в системе.


 
СисАдмин   (2006-08-09 11:21) [2]

Спасибо всем, разобрался, нашел ошибку


 
novill ©   (2006-08-11 11:20) [3]

Где была? Рабочий код покажешь?



Страницы: 1 вся ветка

Текущий архив: 2006.09.03;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.086 c
2-1155371002
SerJaNT
2006-08-12 12:23
2006.09.03
Колесо прокрутки


5-1139064519
Admeral
2006-02-04 17:48
2006.09.03
Указатель на себя


2-1155627956
fast2
2006-08-15 11:45
2006.09.03
Как разместить дочерние формы каскадом?


2-1155730366
AlexanderMS
2006-08-16 16:12
2006.09.03
Ошибка : Class TColorDialog not found .


2-1155643868
KyRo
2006-08-15 16:11
2006.09.03
Процес не завершается