简体   繁体   English

获取ActiveX窗口句柄

[英]Getting ActiveX window handle

I have followed this link to get the window handle of a ActiveX control 我已点击此链接以获取ActiveX控件的窗口句柄

Sample Code from microsoft's site 微软站点的示例代码

// The following code should return the actual parent window of the ActiveX control.
HWND CMyOleControl::GetActualParent()
{
   HWND hwndParent = 0;

   // Get the window associated with the in-place site object,
   // which is connected to this ActiveX control.
   if (m_pInPlaceSite != NULL)
       m_pInPlaceSite->GetWindow(&hwndParent);

   return hwndParent;     // Return the in-place site window handle.
}

But in my case I keep finding that "m_pInPlaceSite" is always NULL. 但就我而言,我一直发现“ m_pInPlaceSite”始终为NULL。 I'm trying to run this code in my controls FinalConstruct. 我试图在我的控件FinalConstruct中运行此代码。 Is there something else I need to implement for the m_pInPlaceSite to be given a value? 我还需要为m_pInPlaceSite赋予一个值吗? Or do I need to Query to get the value. 还是我需要查询来获取值。

Thanks 谢谢

FinalConstruct is way too early. FinalConstruct还为时过早。 In FinalConstruct your class is just being created and is not yet initialized. 在FinalConstruct中,您的类仅在创建中,尚未初始化。 There is no "in place" site, there is no yet site at all. 没有“就地”站点,根本没有站点。

Your control will be called by its owner, it will be given its site, then activated - only then you will possibly have m_pInPlaceSite available. 您的控件将由其所有者调用,将被赋予其站点,然后被激活-只有这样,您才可能有m_pInPlaceSite可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM