我可以用findwindow取得其他窗口的句柄,但是却不知怎么取得其他窗口中的
Button控件的句柄,该控件的caption属性为“你好”,取得form2的句柄:
findwindow(0,'form2')现form2中有button1,该控件的caption属性为“你好”
请问我该怎样才能得到该控件的句柄呢??(form2为别的窗口)
Button控件的句柄,该控件的caption属性为“你好”,取得form2的句柄:
findwindow(0,'form2')现form2中有button1,该控件的caption属性为“你好”
请问我该怎样才能得到该控件的句柄呢??(form2为别的窗口)
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function mygettext(hwnd:THandle):string;
end;
var
Form1: TForm1;
// function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
implementation
{$R *.dfm}
function TForm1.mygettext(hwnd:THandle):string;
var
buf:pchar;
len:Longint;
begin
Len:=Longint(SendMessage(hWnd,WM_GETTEXTLENGTH ,0,0));
if len>0 then
begin//1
try
getmem(buf,len);
SendMessage(hWnd,WM_GETTEXT,Len+1,Int64(buf));
Result:=strpas(buf);
finally
freemem(buf);
end;
end;//1
end;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption,WindowClass:array[0..254] of Char;
begin
GetClassName(Hwnd,WindowClass,255);
if Pos('BUTTON',UpperCase(StrPas(WindowClass))) > 0 then
begin
// if Form1.mygettext(Hwnd)='Button1' then
// begin
sendmessage(hwnd,WM_LBUTTONDOWN,0,1);
sendmessage(hwnd, WM_LBUTTONUP,0,1);
// end;
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h:hwnd;
begin
h := FindWindow(nil, 'MyForm');
if h<>0 then
begin
// sendmessage(h,WM_close,0,1);
EnumChildWindows(H,@EnumChildProc,0);
end
else
showmessage('No Form');
end;
end.
begin
s:=findwindow(0,'form2');
temp:=FindWindowEx(s,0,'Button','你好');
if temp<>0 then showMessage('找到');
end;
试过了,可就是测不出来??怎办呢???