请教(100分)

  • 主题发起人 主题发起人 Sunny18
  • 开始时间 开始时间
S

Sunny18

Unregistered / Unconfirmed
GUEST, unregistred user!
我虽已学Delphi一段时间,可仍是菜鸟一个,有如下程序段请教各位:<br>Procedure TForm1.btnRefreshClick(Sender:TObject);<br>Begin<br>&nbsp; EnumWindows(TFNWndEnumProc(@TFrom1.EnumWndProc)),LPARAM(0));<br>End;<br><br>Function TForm1.EnumWndProc(wnd:HWND;lParam:LPARAM):bool;stdcall;<br>Begin<br>&nbsp; LstWnd.Items.Add(InttoStr(wnd));<br>&nbsp; if wnd=0 then <br>&nbsp; &nbsp; &nbsp;result:=false<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp;result:=true;<br>End;<br>其中LstWnd:Tlistbox是Form1中的一个控件,EnumWndProc为自定义过程<br>可执行到LstWnd.Items.Add(IntToStr(wnd))时出现错误<br>wnd恒为0,并且不能退出.不知为何?
 
不要告诉我你这段代码能编译.......<br>要这样用<br><br>Function EnumWndProc(wnd:HWND;lParam:LPARAM):bool;stdcall;<br>Begin<br>&nbsp; Form1.LstWnd.Items.Add(InttoStr(wnd));<br>&nbsp; if wnd=0 then<br>&nbsp; &nbsp; &nbsp;result:=false<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp;result:=true;<br>End;<br><br>Procedure TForm1.btnRefreshClick(Sender:TObject);<br>Begin<br>&nbsp; EnumWindows(@EnumWndProc, 0);<br>End;
 
Function EnumWndProc(wnd:HWND;lParam:LPARAM):bool;stdcall;<br>我已在接口部分申明;可以编译。<br>将LstWnd.Items.Add(InttoStr(wnd));改为Form1.LstWnd.Items.Add(InttoStr(wnd));后<br>错误消除,可是wnd一直为调用EnumWindows时所给的lParam的值呀.<br>这是为什么啊?请各位高手不帮帮忙!先谢过!<br>单元文件如下:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; LstWnd: TListBox;<br>&nbsp; &nbsp; btnRefresh: TButton;<br>&nbsp; &nbsp; btnClose: TButton;<br>&nbsp; &nbsp; procedure btnCloseClick(Sender: TObject);<br>&nbsp; &nbsp; procedure btnRefreshClick(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; function enumwndProc(wnd:HWND;lParam:LPARAM):bool;stdcall;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.btnCloseClick(Sender: TObject);<br>begin<br>&nbsp; Close;<br>end;<br><br>procedure TForm1.btnRefreshClick(Sender: TObject);<br>begin<br>&nbsp; Form1.LstWnd.Clear;<br>&nbsp; EnumWindows(@TForm1.enumwndProc,LPARAM(1));//application.handle));<br>end;<br><br>function TForm1.enumwndProc(wnd: HWND; lParam: LPARAM): bool;stdcall;<br>begin<br>&nbsp; Form1.LstWnd.Items.Add(IntToStr(wnd));<br>&nbsp; if wnd=0 then<br>&nbsp; &nbsp; &nbsp;Result:=false<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp;Result:=true;<br>end;<br><br>end.
 
已经解决了,谢谢unreal!
 
后退
顶部