本文整理自网络,侵删。
源码unit Unit1;
interface
usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, ShellAPI, StdCtrls;
typeTForm1 = class(TForm)btn1: TButton;mmo1: TMemo;procedure btn1Click(Sender: TObject);procedure FormCreate(Sender: TObject);procedure FormDestroy(Sender: TObject);private{ Private declarations }public{ Public declarations }TSL: TStringList;end; varForm1: TForm1; implementation
{$R *.dfm}
function EnumChildWndProc(AhWnd: LongInt;AlParam: lParam): boolean; stdcall;varWndClassName: array[0..254] of Char;WndCaption: array[0..254] of Char;cRect: TRect;begin
GetClassName(AhWnd, wndClassName, 254); //获取类名GetWindowText(aHwnd, WndCaption, 254); //获取控件captionGetWindowRect(aHwnd, cRect); //获取控件的Rectwith form1.mmo1 dobeginif (string(wndClassName) = 'TEdit') or (string(wndCaption) = '确定')or (string(wndClassName) = 'TComboBox') thenbeginForm1.TSL.Add(IntToStr(cRect.Top) + '=' + IntToStr(AhWnd));//把句柄保存下来备用
lines.add(string(wndClassName));lines.add(string(wndCaption));Lines.Add(IntToStr(cRect.Top) + ' ' + IntToStr(AhWnd) + ' ' + IntToStr(aHwnd));lines.add('-------');end;end;result := true;end;
procedure TForm1.btn1Click(Sender: TObject);varFrmHandle: THandle;name: string;beginShellExecute(self.Handle, 'open', 'F:\zzx\PLSQL\plsqldev.exe', nil, nil, SW_HIDE);//打开外部应用程序 使用 ShellExecute需引用 ShellAPISleep(2000); //休眠2秒 为了能获取到窗体句柄FrmHandle := FindWindow(nil, PChar('Oracle 登录')); //获取pl/sql登录窗体的句柄if FrmHandle <> 0 thenbeginEnumChildWindows(FrmHandle, @EnumChildWndProc, 0); //遍历登录窗体里面的子控件 获取其句柄endelse MessageBox(self.handle, '没找到该窗口句柄', '提示', 0);
name := 'name';SendMessage(StrToInt(TSL.ValueFromIndex[0]), WM_SETTEXT, 0, LPARAM(name)); //nameSendMessage(StrToInt(TSL.ValueFromIndex[1]), WM_SETTEXT, 0, LPARAM(name)); //PWSendMessage(StrToInt(TSL.ValueFromIndex[2]), WM_SETTEXT, 0, LPARAM(name)); //server//上面是向各个子控件 (Edit) 发送设置文本消息 特殊原因统一写成了name 可以自行编写其他的
// SendMessage(StrToInt(TSL.ValueFromIndex[3]), WM_LBUTTONDOWN, 0, 0); //鼠标按下// SendMessage(StrToInt(TSL.ValueFromIndex[3]), WM_LBUTTONUP, 0, 0); // 鼠标抬起// SendMessage(StrToInt(TSL.ValueFromIndex[3]), WM_KEYDOWN, VK_DOWN, 0); // 发送向下键// SendMessage(StrToInt(TSL.ValueFromIndex[3]), WM_LBUTTONDOWN, 0, 0); //鼠标按下// SendMessage(StrToInt(TSL.ValueFromIndex[3]), WM_LBUTTONUP, 0, 0); // 鼠标抬起//这里是选择ComboBox的第二项 sysdba用
SendMessage(StrToInt(TSL.ValueFromIndex[4]), BM_CLICK, 0, 0);//点击确定按钮 登录end;
procedure TForm1.FormCreate(Sender: TObject);beginTSL := TStringList.Create;TSL.Sorted := True;end;
procedure TForm1.FormDestroy(Sender: TObject);beginFreeAndNil(TSL);end;
end.
相关阅读 >>
Delphi dll注入x86/x64/win2k~win8.1全可用
Delphi xe8中的正则表达式提取日语(平假名,片假名,汉字)
Delphi 提升进程权限到sedebugprivilege
Delphi: ttreeview 中禁止双击事件展开或关闭节点
Delphi android实例-读取设备联系人(xe8+小米2)
更多相关阅读请进入《Delphi》频道 >>