function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := ObjectFromHWnd(Handle);
end;
end;//经过窗体测试和DLL测试以下代码也可以正常工作,请各位前辈指导!谢谢!
function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
Result := ObjectFromHWnd(Handle); //有这一句不就足矣了吗,怎么还要Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
//很不解,请前辈指导!谢谢!
end;
end;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := ObjectFromHWnd(Handle);
end;
end;//经过窗体测试和DLL测试以下代码也可以正常工作,请各位前辈指导!谢谢!
function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
Result := ObjectFromHWnd(Handle); //有这一句不就足矣了吗,怎么还要Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
//很不解,请前辈指导!谢谢!
end;
end;
解决方案 »
- 这个XML文件要怎么读取出来
- TTS 读音时提示“没有注册类别”
- 请问如何用Twebbrowser获得xml文档?
- DBExpress + MsSqlServer 的数据保存问题?
- 提问,非高手勿入,打印的问题,100分,不够另加
- 一个DLL中带FORM,带ADO连接的问题,请不吝赐教(在线等待)
- 关于一个操作的问题(INTE上遇到的问题,不是有关程序的)
- 为什么我编的有关数据库的程序每次启动都要输入密码?可是无论我输什么,我都能进入程序.怎么回事?
- 关于获取系统的防病毒软件
- 有人要买我的源代码吗???
- 怎样获取panel上面控件的句柄呢?
- 数据库为Firebird2.5 程序中当SQLDialect为3时,使用FIBDataset,怎么成了只读数据集呢?
实例句柄(hInstance)也不同,ControlAtomString也不同,所以需要
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
以确保找到的是同一地址空间的东西。
function FindControl1(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
ControlAtomString :string;
ControlAtom :TAtom;
RM_GetObjectInstance : dword;
begin
ControlAtomString := Format('ControlOfs%.8X%.8X', [HInstance, GetCurrentThreadID]);
ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
Result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
(OwningProcess = GetCurrentProcessId) then
begin
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
{if GlobalFindAtom(PChar(ControlAtomString+'x')) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
ShowMessage(IntToStr(Integer(Result))); }
end;
end;