如何从 Win32::OLE 中的 HWND 获取 COM 对象?

发布于 2024-08-09 20:06:23 字数 102 浏览 8 评论 0 原文

在 Perl 中,如果我有窗口对象的 HWND,如何使用该句柄访问该 COM 对象?我查看了 Win32::OLE,但我得到的最接近的是 GetActiveObject 方法,它需要一个类。

In Perl, if I have HWND of a window object, how can I get access to that COM object using that handle? I looked at Win32::OLE but the closest I got was the GetActiveObject method, which expects a class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若沐 2024-08-16 20:06:23

没有标准方法可以从 HWND 获取 COM 接口指针,因为窗口不是 COM 对象。基本的 Windows API(包括窗口句柄)早于 OLE 和 COM 的发明。特定窗口的实现可以通过 COM 接口公开其部分或全部功能,但这些接口将是特定于应用程序的。

如果有记录表明您要控制的窗口公开了公共 COM 接口,则该窗口的文档还将告诉您如何在窗口中查询接口指针。最有可能的是,它需要发送特定于应用程序的 窗口消息

There is no standard way to obtain a COM interface pointer from an HWND, because a window is not a COM object. The basic Windows API, including window handles, predates the invention of OLE and COM. The implementation of a particular window may expose some or all of its functionality through COM interfaces, but those interfaces will be application-specific.

If it is documented that the window you want to control exposes a public COM interface, the documentation for that window will also tell you how to query the window for an interface pointer. Most likely, it will require sending an application-specific window message.

隐诗 2024-08-16 20:06:23

从可访问对象获取 HWND 或位置并使用 Windows API 操作它:

use Win32::GuiTest;

使用 HWND

my $hwnd = $ao->WindowFromAccessibleObject();
my $name = Win32::GuiTest::GetWindowText($hwnd);

Get an HWND or location from an Accessible Object and manipulate it with the Windows API:

use Win32::GuiTest;

use a HWND

my $hwnd = $ao->WindowFromAccessibleObject();
my $name = Win32::GuiTest::GetWindowText($hwnd);
把回忆走一遍 2024-08-16 20:06:23

如果您希望从 HWND 获取 IAccessible 接口,可以尝试使用 WM_GETOBJECT(注意:我假设有某种方法可以在 Perl 中发送窗口消息 - 众所周知,我没有 Perl 知识)。

并不是每个人都这样做,所以请确保以某种方式处理失败。例如,Internet Explorer 公开 WM_HTML_GETOBJECT 来获取 IHTMLDocument2 指针。

If you're looking to get the IAccessible interface from an HWND, you can try using WM_GETOBJECT (note: I assume there is someway to send window messages in Perl—it is well established that I have no Perl knowledge).

Not everyone does it this way, so make sure you handle failure somehow. For example, Internet Explorer exposes WM_HTML_GETOBJECT to get the IHTMLDocument2 pointer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文