如何捕获激活窗体的句柄呢(150分)

  • 主题发起人 主题发起人 forever_ao
  • 开始时间 开始时间
F

forever_ao

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。如何捕获激活窗体的句柄呢?<br>谢谢
 
如果是系统的窗体:<br>GetActiveWindow<br>如果是自己程序的<br>Screen.ActiveForm.Handle
 
还有吗?
 
Screen.ActiveForm.handle
 
还有 GetForegroundWindow
 
//新建app,放memo1,button1.[:)]<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; Memo1: TMemo;<br>&nbsp; &nbsp; Button1: TButton;<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>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;hCurrentWindow: HWnd;<br>&nbsp; &nbsp;szText: array[0..254] of char;<br>begin<br>&nbsp; &nbsp; &nbsp;hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; &nbsp; &nbsp;while hCurrentWindow &lt;&gt; 0 do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if iswindowvisible(hCurrentWindow) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetWindowText(hCurrentWindow, @szText, 255)&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memo1.Lines.Add(StrPas(@szText));<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br><br>end.<br>
 
顶一下。<br>
 
GetActiveWindow
 
GetForegroundWindow
 
后退
顶部