16,748
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function EnumChildWndProc(AhWnd: HWND; AlParam: lParam):Boolean;stdcall;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Hwnd: THandle;
CHwnd: THandle;
Buf: array [0..20] of char;
i: LongInt;
begin
Hwnd := FindWindow(nil,Pchar('Project1'));
Edit1.Text:=IntToStr(Hwnd);
Memo1.Lines.Clear;
Memo1.Lines.Add('List of Buttons:');
if Handle <> 0 then
begin
CHwnd:=FindWindowEx(Hwnd,0,nil,nil); // Cannot Find anything, Why???
GetWindowText(CHwnd,buf,199);
Memo1.Lines.Add(IntToStr(CHwnd)+'->'+Buf);
EnumChildWindows(Self.Handle,@EnumChildWndProc,0); // Find self form ok!!!
if EnumChildWindows(Hwnd,@EnumChildWndProc,0) = True then // Return False, Why???? ShowMessage('Load items ok')
else
ShowMessage('Unload...');
{ Sleep(1000);
for i:=100000 to 999999 do // To Find Control ID, but no use, why???
begin
CHwnd := GetDlgItem(Handle,i);
GetWindowText(CHwnd,buf,20);
Memo1.Lines.Add(IntToStr(CHwnd)+':'+Buf+IntToStr(i));
if buf<>'' then
ShowMessage('Found!');
Sleep(10);
end;
}
end
else
MessageBox(self.Handle,'Window not found!','Tips',0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
function EnumChildWndProc(AhWnd: HWND; AlParam: lParam):Boolean;stdcall;
var
WndClassName: Array[0..254] of Char;
WndCaption: Array[0..254] of Char;
begin
GetClassName(AhWnd,WndClassName,254);
GetWindowText(AhWnd,WndCaption,254);
With Form1.Memo1 Do
begin
Lines.Add(String(WndClassName));
Lines.Add(String(WndCaption));
Lines.Add('-------------------');
end;
Result:= True;
end;
end.