【问题标题】:Getting ActiveX window handle获取 ActiveX 窗口句柄
【发布时间】:2012-11-22 13:08:48
【问题描述】:

我已按照link 获取 ActiveX 控件的窗口句柄

来自微软网站的示例代码

// 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”始终为 NULL。我正在尝试在我的控件 FinalConstruct 中运行此代码。我还需要为 m_pInPlaceSite 赋予一个值吗?还是我需要 Query 来获取值。

谢谢

【问题讨论】:

    标签: c++ com activex atl


    【解决方案1】:

    FinalConstruct 太早了。在 FinalConstruct 中,您的类刚刚创建并且尚未初始化。没有“到位”的网站,根本没有网站。

    您的控件将由其所有者调用,将为其提供站点,然后激活 - 只有这样您才有可能拥有 m_pInPlaceSite 可用。

    【讨论】:

    • 你是对的。我如何知道网站何时被激活?
    • 嗯,我看到设置的是 m_spClientSite 而不是 m_spInPlaceSite。我会试着用这个来解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2013-01-25
    相关资源
    最近更新 更多