请教怎么通过已知的控件句柄,获得该控件的父窗体句柄
请问如何通过已知的控件句柄,获得该控件的父窗体句柄
我用WindowFromPoint这个函数得到了某程序中listview的句柄,有没有什么方法通过该句柄得到父窗体的句柄吗?
------解决思路----------------------
------解决思路----------------------
一、这段代码是获取ListView1的父控件
二、这段代码是获取ListView1的窗体的句柄
三、这段代码是获取ListView1的窗体的实体(名称)
应该很明白了。
我用WindowFromPoint这个函数得到了某程序中listview的句柄,有没有什么方法通过该句柄得到父窗体的句柄吗?
------解决思路----------------------
HWND ParentHandle;
ParentHandle := GetParent(hp);
------解决思路----------------------
一、这段代码是获取ListView1的父控件
var HWND:THandle;
begin
HWND := GetParent(ListView1.Handle);
ShowMessage(IntToStr(HWND));
end;
二、这段代码是获取ListView1的窗体的句柄
var HWND: THandle;
begin
HWND := GetParent(ListViewfilelocal.Handle);
while GetParent(HWND)<>0 do // 找到最高的父控件
HWND:=GetParent(HWND);
ShowMessage(IntToStr(HWND));
end;
三、这段代码是获取ListView1的窗体的实体(名称)
function GetInstanceFromhWnd(const hWnd: Cardinal): TWinControl;
type
PObjectInstance = ^TObjectInstance;
TObjectInstance = packed record
Code: Byte; // 短跳转 $E8
Offset: Integer; // CalcJmpOffset(Instance, @Block^.Code);
Next: PObjectInstance; // MainWndProc 地址 }
Self: Pointer; // 控件对象地址 }
end;
var
wc: PObjectInstance;
begin
Result := nil;
wc := Pointer(GetWindowLong(hWnd, GWL_WNDPROC));
if wc <> nil then
Result := wc.Self;
end;
procedure TMain.ListView1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
HWND: THandle;
begin
HWND := GetParent(ListViewfilelocal.Handle);
while GetParent(HWND)<>0 do // 找到最高的父控件
HWND:=GetParent(HWND);
ShowMessage(GetInstanceFromhWnd(HWND).Name);
end;
应该很明白了。