delphi – 有没有办法通过Windows API获取VCL控件的名称?
发布时间:2020-12-15 10:07:59 所属栏目:大数据 来源:网络整理
导读:我有一个位于另一个进程窗口的VCL控件的Hwnd.有没有办法通过 Windows API获取该控件的VCL名称(TControl.Name属性)? 我需要该名称,因为该窗口上有几个TEdit,我需要识别我想要的一个,以便向其发送WM_SETTEXT消息. 这两个应用程序都是用Delphi 2010构建的. 解
我有一个位于另一个进程窗口的VCL控件的Hwnd.有没有办法通过
Windows API获取该控件的VCL名称(TControl.Name属性)?
我需要该名称,因为该窗口上有几个TEdit,我需要识别我想要的一个,以便向其发送WM_SETTEXT消息. 这两个应用程序都是用Delphi 2010构建的. 解决方法
Delphi具有内置函数FindControl(),返回指定hWnd的TWinControl.但它适用于VCL的相同实例.我想你应该调查一下.指向TWinControl对象后,其名称(字符串)位于8个偏移量.您可以尝试ReadProcessMemory读取它.这里的主要问题是创建适合您需要的FindControl()版本.
编辑:(最后得到它:D)调用GetWinControlName函数 // Get Pointer to TWinControl in another process function GetWinControl(Wnd: HWND; out ProcessId: THandle): Pointer; var WindowAtomString: String; WindowAtom: ATOM; begin if GetWindowThreadProcessId(Wnd,ProcessId) = 0 then RaiseLastOSError; // This is atom for remote process (See controls.pas for details on this) WindowAtomString := Format('Delphi%.8X',[ProcessID]); WindowAtom := GlobalFindAtom(PChar(WindowAtomString)); if WindowAtom = 0 then RaiseLastOSError; Result := Pointer(GetProp(Wnd,MakeIntAtom(WindowAtom))); end; function GetWinControlName(Wnd: HWND): string; var ProcessId: THandle; ObjSelf: Pointer; Buf: Pointer; bytes: Cardinal; destProcess: THandle; begin ObjSelf := GetWinControl(Wnd,ProcessId); destProcess := OpenProcess(PROCESS_VM_READ,TRUE,ProcessId); if destProcess = 0 then RaiseLastOSError; try GetMem(Buf,256); try if not ReadProcessMemory(destProcess,Pointer(Cardinal(ObjSelf) + 8),Buf,4,bytes) then RaiseLastOSError; if not ReadProcessMemory(destProcess,Pointer(Cardinal(Buf^)),256,bytes) then RaiseLastOSError; Result := PChar(Buf); finally FreeMem(Buf); end; finally CloseHandle(destProcess); end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 《Speed-BI云平台-基于Excel数据源的技巧应用:区域销售收入
- perl6:对于用户定义的变量,我需要@ -sigil吗?
- 如何在Perl中动态切换到STDOUT / STDERR?
- perl – Moose“builder”vs“default”
- 在Perl中对字母数字哈希键进行排序?
- [bigdata-66] ubuntu 14.04 + keepalived+mysql5.5 mysql双
- Thinkphp+smarty+uploadify实现无刷新上传
- makecab cabwiz 制作PPC中文程序名的安装包;makecab中利用
- BI分析报表开源工具套件SpagoBI
- golang json 为map[string] interface{}