很久没来了,又有问题想向各位讨教了:(140分)

  • 主题发起人 主题发起人 netbug
  • 开始时间 开始时间
N

netbug

Unregistered / Unconfirmed
GUEST, unregistred user!
请看:<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; end;<br><br>enumwindowsproc=function (hnd:THandle;param:pointer):boolean;stdcall;<br>function gettitle(hnd:THandle;param:pointer):boolean;stdcall;<br>var<br>&nbsp; Form1: TForm1;<br><br>&nbsp;function gettitle(hnd:THandle;param:pointer):boolean;stdcall;<br>&nbsp;var text:pchar;<br>&nbsp;begin<br>&nbsp;getmem(text,255);<br>&nbsp;sendmessage(hnd,wm_gettext,255,integer(text));<br>&nbsp;form1.ListBox1.Items.Add(inttostr(hnd)+':'+strpas(text));<br>&nbsp;result:=true;<br>&nbsp;end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var i:integer;ewproc:enumwindowsproc;<br>begin<br>listbox1.Items.Clear;<br>ewproc:=gettitle;<br>i:=findwindow(nil,'Form2');<br>form1.ListBox1.Items.Add(inttostr(i)+'form2');<br>enumchildwindows(i,@ewproc,0);<br>end;<br>我想问:<br>一:什么是回调函数?它的参数是如何传递的?它的运行过程如何?<br>二:在本例中,在enumchildwindows(i,@ewproc,0)中的参数@ewproc<br>是个函数,而enumchildwindows(i,@ewproc,0)调用函数gettitle时,<br>函数gettitle中的参数hnd还是未知的,并据说它的参数hnd是由<br>enumchildwindows这个API提供的,我想问:在这里到底是谁调用谁?<br>谢谢。
 
1.所谓回函数,就是在你应用程序中,被操作系统调用的函数,<br>这些函数是由你编写的,但并不由你来调用。<br>回调函数的参数格式是固定的,<br>下面就是MSDN中对回调函数的说明:<br>The WindowProc function is an application-defined function that processes <br>messages sent to a window. The WNDPROC type defines a pointer to this <br>callback function. WindowProc is a placeholder for the application-defined<br>&nbsp;function name. <br><br>LRESULT CALLBACK WindowProc(<br>&nbsp; HWND hwnd, &nbsp; &nbsp; &nbsp;// handle to window<br>&nbsp; UINT uMsg, &nbsp; &nbsp; &nbsp;// message identifier<br>&nbsp; WPARAM wParam, &nbsp;// first message parameter<br>&nbsp; LPARAM lParam &nbsp; // second message parameter<br>);<br>&nbsp;<br>Parameters<br>hwnd <br>Handle to the window. <br>uMsg <br>Specifies the message. <br>wParam <br>Specifies additional message information. The contents of this parameter<br>&nbsp;depend on the value of the uMsg parameter. <br>lParam <br>Specifies additional message information. The contents of this parameter<br>&nbsp;depend on the value of the uMsg parameter. <br>Return Values<br>The return value is the result of the message processing and depends on<br>&nbsp;the message sent.<br><br>2.@ewproc是函数gettitle的地址。<br>&nbsp; &nbsp;在enumchildwindows(i,@ewproc,0)中,i就是窗口form2的句柄。<br>下面是EnumChildWindows的原型:<br>BOOL EnumChildWindows(<br>&nbsp; &nbsp; HWND hWndParent, // handle to parent window<br>&nbsp; &nbsp; WNDENUMPROC lpEnumFunc, // pointer to callback function<br>&nbsp; &nbsp; LPARAM lParam // application-defined value<br>&nbsp; &nbsp;);
 
接受答案了.
 
后退
顶部