比如说 一个程序叫 aa.exe
程序只有一个界面
程序的标题:在每次启动的时候都不一样
我多次运行aa.exe 请问如何获得所有的aa.exe主窗口的句柄呢?我想通过进程ID来获得窗口句柄,但是不知道如何操作
分不多,望解答!如果哪位有空的话,能贴出源码,明天再追加点分,有劳各位了!
程序只有一个界面
程序的标题:在每次启动的时候都不一样
我多次运行aa.exe 请问如何获得所有的aa.exe主窗口的句柄呢?我想通过进程ID来获得窗口句柄,但是不知道如何操作
分不多,望解答!如果哪位有空的话,能贴出源码,明天再追加点分,有劳各位了!
findwindow('类名','窗口名');//我知道这个东西的用法但是 aa.exe 运行多次,那么它们的类型是一样的,前面我有说过 窗口名是动态生成的.所以您的答案可能不是正解继续求助!
1:多个aa.exe 的类名应该是一样的
2:多个aa.exe 的窗口名,是不一样的.
3:aa.exe 只有一个窗口.(所以不需要讨论如何获得主窗口句柄的问题)!
function EnumWindowsFunc(Handle:THandle;List:TStringList):boolean;stdcall;
var
buf:array[0..1024]of Char;
str:string;
begin
GetClassName(handle,buf,1024);
str:=strpas(pchar(@buf[0]));
if str='Tform1' then
List.Add(inttostr(integer(handle)));Result:=True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
EnumWindows(@EnumWindowsFunc,LParam(Memo1.Lines));
end;
我在这一句报错了,错误信息如下
[Error] Unit1.pas(45): Variable required
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
(************完整源码如下**************)unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ShellAPI;type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function EnumWindowsFunc(Handle:THandle;List:TStringList):boolean;stdcall;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function TForm1.EnumWindowsFunc(Handle:THandle;List:TStringList):boolean;stdcall;
var
buf:array[0..1024]of Char;
str:string;
begin
getClassName(handle,buf,1024);
str:=strpas(pchar(@buf[0]));
if str='Tform1' then
List.Add(inttostr(integer(handle)));
Result:=True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
EnumWindows(@EnumWindowsFunc,LParam(Memo1.Lines));
end;end.
function EnumWindowsFunc(Handle:THandle;List:TStringList):boolean;stdcall;
就可以了,不要作为Tfom1的成员函数.真要用类的成员函数也是可以的,不过比较麻烦,我没研究过,只是看有人这么说过