读书人

findwindow 如何找同时有好几个窗口标

发布时间: 2012-03-09 16:54:57 作者: rapoo

findwindow 怎么找同时有好几个窗口标题一样的程序了
比如同一个程序运行了好多个,标题名也是一样的,用findwindow想得到第三个窗口的句柄要怎么做了

[解决办法]
枚举窗口EnumWindows
[解决办法]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
function EnumWindowsFunc(Handle: THandle; List: TStringList) : boolean ; stdcall;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
EnumWindows(@EnumWindowsFunc, LParam(Memo1.Lines));
end;

function EnumWindowsFunc(Handle: THandle; List: TStringList) : boolean ; stdcall;
var Caption: array[0..256] of Char;
begin
if GetWindowText
(Handle, Caption, SizeOf(Caption)-1) <> 0 then
begin
List.Add(Caption);
SetWindowText(Handle, PChar( 'About - ' + Caption));
end;

Result :=True;
end;


end.

读书人网 >.NET

热点推荐