下面的代码中使用了EnumChildWindowsProc函数,编译没有通过。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
begin
hwnd := FindWindow('IEFrame',nil);
if hwnd<> 0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@buffer[0]));
Edit1.text:= StrPas(buffer);
end;
end;function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
end.[Error] Unit1.pas(36): Variable required
[Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.EnumChildWindowsProc'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
begin
hwnd := FindWindow('IEFrame',nil);
if hwnd<> 0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@buffer[0]));
Edit1.text:= StrPas(buffer);
end;
end;function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
end.[Error] Unit1.pas(36): Variable required
[Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.EnumChildWindowsProc'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
function TForm1.EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
end.
EnumChildWindows函数在delphi6下编译出错
来源:互联网 | 作者:strive2008 | 点击数: 9
我想在Delphi6下编程实现获取IE地址栏里面的信息,程序如下:
function TForm1.EnumChildWindowsProc(hwnd, lparam: Integer): Boolean;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
Begin
hwnd := FindWindow('CabinetWClass',nil);
if hwnd<> 0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Longint(@buffer[0]));
Caption := StrPas(buffer);
end;
end;
为何编译的时候,编译器报告说:EnumChildWindows(hwnd,@EnumChildWindowsProc,Longint(@buffer[0]));这一句的错误是:
Variable Required?1楼 lxpbuaa 发表于:2009-08-10 19:26:22 引用 不要将EnumChildWindowsProc定义为TForm1的方法,直接写成一个函数就可以了:
function EnumChildWindowsProc(hwnd, lparam: Integer): Boolean;
—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
————————————————————————————————— 2楼 strive2008 发表于:2009-08-10 19:26:22 引用 问题已经解决,谢谢lxpbuaa(桂枝香在故国晚秋) !!
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
begin
hwnd := FindWindow('IEFrame',nil);
if hwnd<> 0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@buffer[0]));
Edit1.text:= StrPas(buffer);
end;
end;function Tform1.EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
SendMessage(hwnd,WM_GETTEXT,256,lparam);
Result:=False;
end;
end;
end.[Error] Unit1.pas(36): Variable required
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
另外你的那个返回值实际上很可能永远是 TRUE,winapi很显然是不可能用 Boolean 类型做返回值的
从TForm1中移出来,变成全局方法
function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function EnumWindowsProc(hwnd: THandle; lParam: LPARAM): boolean; stdcall;
var
classname: array[0..255] of char;
addr: array[0..255] of char;
edith: THandle;
begin
GetClassName(hwnd,classname,256);
if classname = 'IEFrame' then
begin
edith:= findwindowex(hwnd,0,'WorkerW',nil);
edith:= findwindowex(edith,0,'ReBarWindow32',nil);
edith:= findwindowex(edith,0,'ComboBoxEx32',nil);
sendmessage(edith,wm_gettext,256,Integer(@addr));
Form1.Memo1.Lines.Add(addr);
end;
result:= true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc,0);
end;end.
d7+xp 通过