C++ 获取ActiveX窗口句柄

C++ 获取ActiveX窗口句柄,c++,com,activex,atl,C++,Com,Activex,Atl,我按照这个方法获得了ActiveX控件的窗口句柄 来自microsoft站点的示例代码 // 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 o

我按照这个方法获得了ActiveX控件的窗口句柄

来自microsoft站点的示例代码

// 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.
}
但在我的例子中,我一直发现“m_pInPlaceSite”总是空的。我正在尝试在我的控件FinalConstruct中运行此代码。我是否需要为m_pInPlaceSite实现其他功能以获得一个值?或者我需要查询以获取值


谢谢

最后的指令
太早了。在FinalConstruct中,您的类刚刚创建,尚未初始化。没有“就地”场地,根本没有场地


您的控件将由其所有者调用,它将被赋予其站点,然后被激活-只有这样您才可能有可用的
m_pInPlaceSite

您是正确的。我怎么知道站点何时被激活?我看到的是m_spClientSite被设置为而不是m_spInPlaceSite。我要试着用这个来摆弄把手