PRB: ActiveX 控件窗口才创建在 Internet Explorer 中可见
注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。
点击这里察看该文章的英文版: 195188
本文已归档。它按“原样”提供,并且不再更新。
症状
ASSERT(::IsWindow(m_hWnd));
ATLASSERT(::IsWindow(m_hWnd));
原因
解决方案
MFC
MFC 提供调用 COleControl::CreateControlWindow() 来创建控件的窗口的函数。MFC 的 IOleObject::SetClientSite() 实现调用 COleControl::OnSetClientSite()。向您 COleControl 派生的类中添加以下项 ︰
// CMyControl is derived from COleControl.
void CMyControl::OnSetClientSite()
{
if (m_pClientSite)
// It doesn't matter who the parent window is or what the size of
// the window is because the control's window will be reparented
// and resized correctly later when it's in-place activated.
VERIFY (CreateControlWindow (::GetDesktopWindow(), CRect(0,0,0,0),
CRect(0,0,0,0)));
COleControl::OnSetClientSite();
}
ATL
ATL 还提供了一个名为 CComControl::CreateControlWindow() 的函数。
// CMyControl is derived from CComControl
STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
{
if (pClientSite)
{
RECT rc = {0,0,0,0};
// Don't have access to the container's window so just use the
// desktop. Window will be resized correctly during in-place
// activation.
HWND hWnd = CreateControlWindow(::GetDesktopWindow(), rc);
_ASSERT (hWnd);
}
return IOleObjectImpl<CMyControl>::SetClientSite (pClientSite);
}
HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect)
{
// Get the container's window.
_ASSERT (m_spClientSite);
LPOLEINPLACESITE pInPlaceSite = NULL;
HRESULT hr = m_spClientSite->QueryInterface(IID_IOleInPlaceSite,
(void **)&pInPlaceSite);
_ASSERT (SUCCEEDED (hr) && pInPlaceSite);
HWND hParent = NULL;
hr = pInPlaceSite->GetWindow (&hParent);
_ASSERT (SUCCEEDED (hr) && hParent);
pInPlaceSite->Release ();
// Set container window as our parent window
SetParent (hParent);
return CComControlBase::InPlaceActivate(iVerb, prcPosRect);
}
状态
更多信息
无窗口控件、 窗体控件在 Internet Explorer 中支持的 4.x 和 Visual C++ 4.2 或更高版本,采用第一种方法。
但是,它可能是极难或不可能重新设计现有的控件,在这些情况中工作。某些控制措施可能需要太多额外的代码来有效地不在窗口。对于此类控件,可以在解决方法部分中使用此替代方法。
如果 ActiveX 控件定位上的可见部分的 HTML 页,但控件的窗口仍未创建了,则从本文中讨论的一个不同的问题。该控件可能无窗口控件的默认值。