开发者

How do I get the COM object from a HWND in Win32::OLE?

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.


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.


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜