Windows - 从 TreeView 获取 HWND 以获得 GetScrollInfo?

Windows - Get HWND from TreeView for GetScrollInfo?

我是 Windows 编程新手,正在尝试获取 TreeView 滚动条的位置。

SCROLLINFO scrollInfo;
ZeroMemory(&scrollInfo, sizeof(scrollInfo));
scrollInfo.cbSize = sizeof(scrollInfo);
scrollInfo.fMask = SIF_TRACKPOS;
tbool gotScrollInfo = GetScrollInfo(poTreeView->Handle, SB_VERT, &scrollInfo);

我收到一个错误:

'BOOL GetScrollInfo(HWND,int,LPSCROLLINFO)': cannot convert argument 1 from 'System::IntPtr' to 'HWND'.

我在网上看过,但找不到如何从 TreeView 指针获取 HWND。 Windows' 文档假定您已经拥有 HWND。

我在其他地方见过人们使用 TreeView.hwnd 或将 TreeView.Handle 转换为 IntPtr - 我猜函数用来代替 HWND

有人知道怎么做吗?这应该很简单,但我找不到答案。

根据 Control.Handle 文档:

An IntPtr that contains the window handle (HWND) of the control.

...

The value of the Handle property is a Windows HWND. If the handle has not yet been created, referencing this property will force the handle to be created.

所以是的,您可以简单地将 IntPtr 类型转换为 HWND,例如:

(HWND)(poTreeView->Handle.ToPointer())

static_cast<HWND>(poTreeView->Handle.ToPointer())