环境: 有一个Form1,里面有三个TEdit生成的Edit1,Edit2,Edit3而且都是没有caption的
要求: 编写另外一个程序,能分别获得Form1里面三个Edit的句柄
要求: 编写另外一个程序,能分别获得Form1里面三个Edit的句柄
解决方案 »
- 用WinSocket做的Server,无法send的数据给客户端(附源码)
- 请各位帮忙修改一个备份数据库的代码,谢谢
- idhttp使用get方法获取“*.asp”的问题?
- 急求IntraWeb编译问题
- 又是一个stringgrid问题
- 运行程序时出现 BDE error $0007是什么原因有什么解决办法???
- 最近要考3级A,有些题不会做,参考书上好像也没有。若谁能帮助请访问http://cjsyf_cn.myetang.com/3a.htm
- TPopupMenu动态添加MenuItem?
- !!!比较复杂的MDI子窗口问题!!!
- I/O打印???!!!
- 谁有Power-Designer 9 Studio的注册码??给一个啊,谢谢!
- case xx of
TEdit(FindComponent('edit'+inttostr(i)));
TEdit(FindComponent('edit'+inttostr(i)));
findwindow
findwindowex
具体的帮助可以参考delphi在线帮助!
用api函数呀
findwindow
findwindowex
具体的帮助可以参考delphi在线帮助!简单使用上面的应该不可以
还要用GetClassName来确定该控件是Edit控件
那么容易的话,为什么不把代码给我?!
GetClassName得到的三个都是Edit类,怎样区分?
那么,如何用findwindowex,得到我想得到的某个edit的handel呢??我始终没有解决,不知道还有哪个高人,帮忙~~
获得位置的函数GetWindowRect
获得位置的函数GetWindowRect不知道可以吗,
一会试试
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(Edit1.Name + '的句柄 ' + IntToStr(Edit1.Handle));
ShowMessage(Edit2.Name + '的句柄 ' + IntToStr(Edit1.Handle));
ShowMessage(Edit3.Name + '的句柄 ' + IntToStr(Edit1.Handle));
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(Edit1.Name + '的句柄 ' + IntToStr(Edit1.Handle));
ShowMessage(Edit2.Name + '的句柄 ' + IntToStr(Edit1.Handle));
ShowMessage(Edit3.Name + '的句柄 ' + IntToStr(Edit1.Handle));
end;end.
用ChildWindowFromPointEx可以得到,hParent是窗体句柄,Point(x, y) 是控件的大约
位置,CWP_ALL表示所有控件,也可以制定只取某类控件,函数返回值为控件句柄。
ChildWindowFromPointEx(hParent, Point(x, y) , CWP_ALL);
下面是我写的一个获取别的程序edit的内容的例子
procedure TForm1.Button1Click(Sender: TObject);
var
hParent, hEdit: HWND;
u: pchar;
begin
try
hParent := FindWindow(nil, 'fromB的标题');
if hParent = 0 then
showmessage('窗口没有找到!')
else
begin
hEdit := ChildWindowFromPointEx(hParent, Point(10, 10) //大约位置
, CWP_ALL);
if hEdit = 0 then
showmessage('Edit没有找到!')
else
begin
U := StrAlloc(250);
SendMessage(hEdit, WM_GETTEXT, 249, Integer(U));
edit1.Text := Strpas(u);
end;
end;
except
end;
end;
Edit2.tag := 2;Edit3.tag := 3for i := 1 to Form.ComponentCount do begin
if (Form.Components[i] is TEdit) begin
case (Form.Component[i] as TEdit).tag of
1: Edit1
2: Edit2
3: Edit3
end;
end;
end;这样就区分了3个Edit控件,我目前想到的比较简单的方法,如果各位有更好的方法,跟着贴啊
var
FoundWindow: HWND;
WindowText: array[0..255] of char;
begin
{find a TEdit child window}
FoundWindow:=FindWindowEx(Form1.Handle, 0, 'TEdit',nil); {get its text...}
GetWindowText(FoundWindow, WindowText, 255); {...and display it}
Label1.Caption:='FindWindowEx found window handle '+IntToStr(FoundWindow)+
': '+WindowText;end;
to apololi(杭州小子) ,如果是外部程序的edit,它的tag我就无法知道,怎么用你的方法?