使用EnumChildWindows(Form1.Handle,@EnumerateChildWindows,0);时出错(12分)

  • 主题发起人 主题发起人 aynes
  • 开始时间 开始时间
A

aynes

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi 7+windows xp<br>原代码:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; function EnumerateChildWindows(hWnd:HWND; lParam:LPARAM): BOOL; stdcall;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>function TForm1.EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL;<br>var<br>&nbsp; &nbsp;ClassName: Array[0..255] of char; &nbsp;// this holds the class name of our child windows<br>begin<br>&nbsp; &nbsp;{get the class name of the given child window}<br>&nbsp; &nbsp;GetClassName(hWnd,ClassName,255);<br><br>&nbsp; &nbsp;{display it in the list box}<br>&nbsp; &nbsp;Form1.ListBox1.Items.Add(ClassName);<br><br>&nbsp; &nbsp;{continue enumeration}<br>&nbsp; &nbsp;Result:=TRUE;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;ListBox1.Items.Clear;<br><br>&nbsp; &nbsp;{enumerate all child windows belonging to Form1}<br>&nbsp; &nbsp;EnumChildWindows(Form1.Handle,@EnumerateChildWindows,0);<br>end;<br><br>end.<br><br>出错信息:[Error] Unit1.pas(49): Variable required<br><br>是什么原因,如何改正。
 
怎么都没人上来啊?<br>我是照例子写的,为什么会这样,是不是我少写了什么东东啊??????<br><br>急 急 急 &nbsp; 郁闷中&gt;&gt;&gt;&gt;&gt;&gt;&gt;
 
有没有可能我的操作系统的问题啊????<br>难道说在XP中使用这个函数会出错。
 
//WINDOWS的回调函数不能是类的方法<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp;Dialogs, StdCtrls;<br><br>type<br>&nbsp;TForm1 = class(TForm)<br>&nbsp; &nbsp;Button1: TButton;<br>&nbsp; &nbsp;ListBox1: TListBox;<br>&nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br>&nbsp;private<br>&nbsp; &nbsp;{ Private declarations }<br>&nbsp;public<br>&nbsp; &nbsp;{ Public declarations }<br>&nbsp;end;<br><br>var<br>&nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM):boolean;stdcall;<br>var<br>&nbsp; ClassName: Array[0..255] of char; &nbsp;// this holds the class name of our child windows<br>begin<br>&nbsp; {get the class name of the given child window}<br>&nbsp; GetClassName(hWnd,ClassName,255);<br><br>&nbsp; {display it in the list box}<br>&nbsp; Form1.ListBox1.Items.Add(ClassName);<br><br>&nbsp; {continue enumeration}<br>&nbsp; Result:=TRUE;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; ListBox1.Items.Clear;<br>&nbsp; {enumerate all child windows belonging to Form1}<br>&nbsp; EnumChildWindows(Form1.Handle,@EnumerateChildWindows,0);<br>end;<br><br>end.
 
我照你的贴上去了,但还是错。<br>能不能把把有代码一起贴上啊????<br>谢了。
 
to ysai:<br>&nbsp; &nbsp; 原谅我的愚笨,但请帮助我。
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hF:Thandle;<br>&nbsp; function EnumChildWindowsProc(H: HWnd; TF: TForm1): Boolean; stdcall;<br>&nbsp; function EnumWindowsProc(H: HWnd; TF: TForm1): Boolean; stdcall;<br><br>implementation<br><br>{$R *.dfm}<br>function EnumChildWindowsProc(H: HWnd; TF: TForm1): Boolean; stdcall;<br>var<br>&nbsp; Buffer: array[0..255] of Char;<br>&nbsp; Buffer1: array[0..255] of Char;<br>begin<br>&nbsp; Result := True; //設定為True才會再找下一個<br>&nbsp; //開始作某事<br>&nbsp; GetWindowText(H, Buffer, 255);<br>&nbsp; GetClassName(h,buffer1,255);<br>&nbsp; TF.memo1.Lines.Add(StrPas(Buffer1)+' &nbsp;'+StrPas(Buffer)+' &nbsp;'+inttostr(h));<br>end;<br><br>function EnumWindowsProc(H: HWnd; TF: TForm1): Boolean; stdcall;<br>var<br>&nbsp; Buffer: array[0..255] of Char;<br>&nbsp; Buffer1: array[0..255] of Char;<br>begin<br>&nbsp; Result := True; //設定為True才會再找下一個<br>&nbsp; //開始作某事<br>&nbsp; GetWindowText(H, Buffer, 255);<br>&nbsp; GetClassName(h,buffer1,255);<br>&nbsp; TF.memo1.Lines.Add(StrPas(Buffer1)+' &nbsp;'+StrPas(Buffer)+' &nbsp;'+inttostr(h));<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; memo1.Clear;<br>&nbsp; if edit1.Text&lt;&gt;'' then begin<br>&nbsp; &nbsp; hF:=findwindow(nil,pchar(edit1.Text));<br>&nbsp; &nbsp; hf:=strtoint(edit1.Text);<br>&nbsp; &nbsp; if hF&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; EnumChildWindows(hF, @EnumChildWindowsProc, Longint(Self));<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; EnumWindows(@EnumChildWindowsProc, Longint(Self));<br>end;<br><br>end.<br>
 
谢了,各位
 
后退
顶部