如何得到同名的所有窗体的句柄? 我在做联众的自动走棋程序,在同一机子上登多个号,出现的下棋窗口名称都一样,请问我该怎么得到他们的句柄,并轮流的向他们发送走棋的消息? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用EnumWindows API函数获取 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Boolean; stdcall;var Form1: TForm1;implementation{$R *.dfm}function GetTitle (Hwnd: THandle;Param: Pointer): Boolean; stdcall; //传入窗口句柄var MyCaption: string;begin SetLength (MyCaption, 100); GetWindowText (Hwnd, PChar (MyCaption), 100); //每列举一个窗口,就利用获得的句柄去读标题 setlength(MyCaption,strlen(PChar (MyCaption))); if MyCaption = '联众象棋' then // 你要寻找的标题 begin showmessage('找到了,^_^');// 插入要处理的过程 ,这句是示例 end; //form1.ListBox1.Items.Add (MyCaption); Result := True;end;procedure TForm1.Button1Click(Sender: TObject);var EWProc: EnumWindowsProc;begin EWProc := GetTitle; EnumWindows (@EWProc, 0); //回调函数 ,能列举系统出所有的窗口end;end. 思路是先获取系统所有窗口的句柄,然后获取这些窗口的标题,如果窗口标题符合条件,则执行设定语句:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Boolean; stdcall;var Form1: TForm1;implementation{$R *.dfm}function GetTitle (Hwnd: THandle;Param: Pointer): Boolean; stdcall; //传入窗口句柄var MyCaption: string;begin SetLength (MyCaption, 100); GetWindowText (Hwnd, PChar (MyCaption), 100); //每列举一个窗口,就利用获得的句柄去读标题 setlength(MyCaption,strlen(PChar (MyCaption))); if MyCaption = '我的电脑' then // 你要寻找的标题,这里是'我的电脑 ',建议按Ctrl+E打开一个Explorer试试看结果 begin showmessage('找到了,改你的标题^_^');// 插入要处理的过程 ,这句是示例 SetWindowText (Hwnd, PChar ('怎么不是我的电脑了呢?')); // 插入要处理的过程 ,这句是示例,改变标题 end; 、、form1.ListBox1.Items.Add (MyCaption); Result := True;end;procedure TForm1.Button1Click(Sender: TObject);var EWProc: EnumWindowsProc;begin EWProc := GetTitle; EnumWindows (@EWProc, 0); //回调函数 ,能列举系统出所有的窗口end;end. 注意把 、、form1.ListBox1.Items.Add (MyCaption);删掉,这是我测试的语句 delphi ADO控件,插入记录到数据库表,第二次出错 如何读取windows域的用户在程序中 fastreport怎样调整日期显示格式 已经是第二次提问了可加分.如何读取数据库中用2进制存放的WAV文件数据,并播放出来? sql数据更新 求教,如下数据格式用DELPHI怎么解析到数据库(mdb)中效率最高 delphi中怎么关闭IE浏览器? 编程至尊宝,请进 曾经看到一位大虾说,他们的系统有600多个表,有一个Form上放了2000个控件,有可能吗? 串口通信API函数在NT下和98下使用上有什么不同? rave导出html为什么只有一页?? 找IBM笔记本9460LR2驱动
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Boolean; stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
function GetTitle (Hwnd: THandle;Param: Pointer): Boolean; stdcall; //传入窗口句柄
var
MyCaption: string;
begin
SetLength (MyCaption, 100);
GetWindowText (Hwnd, PChar (MyCaption), 100); //每列举一个窗口,就利用获得的句柄去读标题
setlength(MyCaption,strlen(PChar (MyCaption)));
if MyCaption = '联众象棋' then // 你要寻找的标题
begin
showmessage('找到了,^_^');// 插入要处理的过程 ,这句是示例
end;
//form1.ListBox1.Items.Add (MyCaption); Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
EWProc := GetTitle;
EnumWindows (@EWProc, 0); //回调函数 ,能列举系统出所有的窗口
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Boolean; stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
function GetTitle (Hwnd: THandle;Param: Pointer): Boolean; stdcall; //传入窗口句柄
var
MyCaption: string;
begin
SetLength (MyCaption, 100);
GetWindowText (Hwnd, PChar (MyCaption), 100); //每列举一个窗口,就利用获得的句柄去读标题
setlength(MyCaption,strlen(PChar (MyCaption)));
if MyCaption = '我的电脑' then // 你要寻找的标题,这里是'我的电脑 ',建议按Ctrl+E打开一个Explorer试试看结果
begin
showmessage('找到了,改你的标题^_^');// 插入要处理的过程 ,这句是示例
SetWindowText (Hwnd, PChar ('怎么不是我的电脑了呢?')); // 插入要处理的过程 ,这句是示例,改变标题
end;
、、form1.ListBox1.Items.Add (MyCaption); Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
EWProc := GetTitle;
EnumWindows (@EWProc, 0); //回调函数 ,能列举系统出所有的窗口
end;end.