如何获得当前窗口的句柄?(我编写的程序要获得另一个程序的句柄)(50分)

F

facat

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获得当前窗口的句柄?(我编写的程序要获得另一个程序的句柄)
 
TForm 的句柄应该是 handle 属性。我觉得你的表达不是太清楚。

查阅可视窗口标题

下面只是举出一个例子提供参考:运用API函数GetWindow()配合GetWindowText()逐一
查出各视窗的标题 ,你可以注意一下其中的 hCurrentWindow,这应该是各窗口的句柄。

1. File | New Project 开始一个新的工程
2. 在 Form1 中安排 Button 与 Memo 各一
3. 在 Button1 的 OnClick 事件中撰写程式如下:
procedure TForm1.Button1Click(Sender: TObject);
var
 hCurrentWindow: HWnd;
 szText: array[0..254] of char;
begin
 hCurrentWindow :=
GetWindow(Handle, GW_HWNDFIRST);
 while hCurrentWindow <> 0 do
 begin
 if GetWindowText(
hCurrentWindow, @szText, 255)>0 then
Memo1.Lines.Add(StrPas(@szText));
 hCurrentWindow:=
GetWindow(hCurrentWindow, GW_HWNDNEXT);
 end;
end;

 
当前应该是最前的吧
用GetTopWindow就可以了
如果是知道对端标题要查找,可以FindWindow,windowclassname用nil
 
顶部