Problem hosting WebBrowser control in an ATL app

I have a legacy atl app that hosts a webbrowser control in an ATL window. I create an instance of the client to host the browser using the following sequence

CComPtr<IOleObject> spOleObject;
HRESULT hr = CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, ID_IOleObject,(void**)&spOleObject);

spOleObject->SetClientSite(this);
GetClientRect(&rcClient);
hr = spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, m_hWnd, &rcClient);

hr = AtlAdvise(m_spWebBrowser, GetUnknown(), DIID_DWebBrowserEvents2, &m_dwCookie);

CComVariant navvar(navurl);
m_spWebBrowser->Navigate2(&navvar, NULL, NULL, NULL, NULL);

This sequence works fine to create the initial browse window. The call to navigate2 works and if I look at the window via spy++ I have Shell Embedding -> Shell DocObject View -> Internet Explorer_Server. When a popup occurs (detected through NewWindow3) I launch a new window and execute the same code sequence for the new window. In the popup window the navigate2 doesnt work, and when I look at this new window in spy++ I just have Shell Embedding. I get the same problem even if I instantiate the popup window on startup, so its not related to NewWindow3 at all - it seems the second instance of the web control isnt instantiating even though all the calls return S_OK.

This sequence worked fine under IE7 but now I am using IE8 and the popup window isnt working. There is clearly something I am missing but I cant guess what it may be. Any suggestions would be incredibly helpful.

Answers


Turns out that when I created the main window I called

m_spInPlaceObject = m_spWebBrowser;
_ASSERT(m_spInPlaceObject);

if (m_spInPlaceObject)
    m_spInPlaceObject->SetObjectRects(&rcClient, &rcClient);

But I didnt have this call in the popup initialization. Once I added this to the popup initialization it worked fine.

For whatever reason it worked on IE7 but not on IE8. Slack coding on my part. Hosting the IE control in an ATL app is still as neat as ever!


Need Your Help

NFS sync vs async

asynchronous sync nfs

I'm using NFS to allow two servers two communicate via simple text files, however sometimes it seems that the server reading the text files to get information is reading incomplete files, and then