如何通过 COM 接口以编程方式激活 OLE 控件?
我有一个通过 ActiveX 嵌入按钮控件的应用程序。该按钮由第三方提供,它实现了一系列 ActiveX 接口(其中包括 IOleInPlaceObject
)。我确实有一个对 IUnknown 的引用
按钮的实现。
我面临的问题是 IOleWindow::GetWindow
函数总是返回错误;错误代码是 0x80004005,这显然是一个 常见的 HRESULT值表示E_FAIL
。不太描述性。
就其价值而言,该对象还通过其 IDispatch
实现;查询成功,但属性值始终为零。
一些谷歌搜索表明我可能需要在 hWnd
属性产生有用值之前“激活”OLE 对象。有谁知道如何做到这一点,是否有一个专用的 COM 接口用于激活 OLE 对象?
有趣的是,该按钮确实似乎有一个窗口句柄,如间谍++。
更新:我刚刚发现IQuickActivate
由我正在处理的按钮控件实现,可用于“快速”(咳咳...)激活项目。但是,填写 QACONTAINER
结构似乎很痛苦,所以我现在不想这样做。
I have an application which embeds a button control via ActiveX. The button was provided by a third party, and it implements a whole range of ActiveX interfaces (among which is IOleInPlaceObject
). I do have an reference to the IUnknown
implementation of the button.
The problem I'm facing is that the IOleWindow::GetWindow
function provided by the object always returns an error; the error code is 0x80004005 which is apparently a common HRESULT value meaning E_FAIL
. Not too descriptive.
For what it's worth, the object also exposes a hWnd
property via it's IDispatch
implementation; querying it succeeds, but the value of the property is always zero.
A bit of googling suggested that I may need to 'activate' the OLE object before the hWnd
property yields a useful value. Does anybody know how to do this, is there a dedicated COM interface for activating OLE objects?
Interestingly, the button does seem to have a window handle, as is visible in Spy++.
UPDATE: I just found IQuickActivate
which is implemented by the button control I'm dealing with, and which can be used to 'quickly' (ahem...) activate an item. However, filling the QACONTAINER
structure seems to be quite a pain, so I'll rather not do that right now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,使用
IOleClientSite::DoVerb
函数发送OLEIVERB_INPLACEACTIVATE
动词有所帮助,如下所示:unk
是一个IUnknownPtr 我正在尝试获取
HWND
。CheckAndThrow
函数是一个辅助宏,如果给定的返回代码指示失败,它会产生异常。It turned out that sending the
OLEIVERB_INPLACEACTIVATE
verb using theIOleClientSite::DoVerb
function helped, like this:unk
is anIUnknownPtr
for which I'm trying to get theHWND
. TheCheckAndThrow
function is a helper macro which yields an exception in case the given return code indicates a failure.当然,按钮有一个有效的
HWND
,否则它就不是一个按钮/窗口。您可以使用
GetDlgItem
或类似方法获取任何控件的HWND
。我也不确定如何以编程方式激活对象。我会尝试以下操作:
ReactivateAndUndo
。根据文档,这可能会满足您的需要,恕我直言。HWND
(并且如果存在的话您肯定可以获得它) - 可以模拟用户鼠标输入Naturally button has a valid
HWND
, othrewise it wouldn't be a button/window.You may get the
HWND
of any control by usingGetDlgItem
or similar.I'm not certain either about how to activate the object programmatically. I'd try the following:
ReactivateAndUndo
. According to doc this may do what you need IMHO.HWND
(and you definitely may obtain it if it exists) - it's possible to simulate user mouse input