20101019 10:48 Activex调试以及m_hWnd为空 解决办法

1. 点击【开始】->【运行】 命令:regedit.
2. 定位到HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3. 在【右边区域】【右键】新建一个名称为TabProcGrowth的DWORD值, 数值数据设置为0.

VS不用重启,直接可以按F5进行调试ActiveX了!

参看: http://social.microsoft.com/Forums/en-US/vsdebug/thread/e2c795cd-b7a0-4fad-b7c9-b1ca40d7302e

网页中OCX控件HWND为空问题当网页中的OCX控件没有出现到屏幕上之前(或者尺寸为0时),它的WM_CREATE消息将不会被调用. 这样当script程序调用一些必须要有有效HWND的操作时就会导致MFC/ATL底层库的崩溃(调试版本则会ASSERT)。 在MFC中的调试版本:
ASSERT(::IsWindow(m_hWnd)); 在ATL中的调试版本:
ATLASSERT(::IsWindow(m_hWnd)); MFC的解决办法是:在派生类中钩住OnSetClientSite,创建一个窗口,代码如下:// CMyControl is derived from COleControl.
void CMyControl::OnSetClientSite()
{
// 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.
if (m_pClientSite)
    VERIFY (CreateControlWindow (::GetDesktopWindow(), CRect(0,0,0,0), CRect(0,0,0,0)));
COleControl::OnSetClientSite();
}ATL的解决办法:
// 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);
}

参看:http://support.microsoft.com/kb/195188

原文地址:https://www.cnblogs.com/lidabo/p/2815199.html