Question : Embedding iwebbrowser control inside ATL window.

Hi.

I have created an ATL window and using the below code i can attach a webbrowser control inside my ATL window. But the below code inserts the internet explorer as such (with the menu bar, headers and all) inside the window.
But i dont want to show any of internet explorer references inside my window. I want my ATL window to look like a plain window with HTML contents displayed. I tried the below code with

 CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER, IID_IWebBrowser2, (void**)&m_pBrowser);

But its not working.     i am not getting handle later code. (pWB->get_HWND(&IE_HWND)).

I found reference of this problem in codeproject. But they have used plain C to embed html inside the window. I need to use C++ for this.

Could you please help me.


#include <mshtml.h>
#include <exdisp.h>
CLSID clsid;
LPUNKNOWN punk=NULL;
IWebBrowser2 *pWB = NULL;
IHTMLDocument2 *pHTML = NULL;
IHTMLElementCollection *pElement = NULL;
IDispatch *pdisp = NULL;
DISPID  dispidNamed = DISPID_PROPERTYPUT;
VARIANT_BOOL bBusy;
VARIANT var;

void PutIE_InWindow(HWND hWnd)
{
     OleInitialize (NULL);
     CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IUnknown, (LPVOID *) &punk);    
     punk->QueryInterface (IID_IWebBrowser2, (LPVOID *) &pWB);
     pWB->put_Visible (TRUE);
     BSTR bstrVal = SysAllocString (L"www.experts-exchange.com"); //Set web page on  IE
     var.vt = VT_I4;
     var.lVal = 0;
     pWB->Navigate (bstrVal, &var, &var, &var, &var);
     SysFreeString (bstrVal);
     do
     {
          Sleep (500);
          pWB->get_Busy (&bBusy);
     }
     while (bBusy);
     
     
     long IE_HWND = 0;
     if (pWB->get_HWND(&IE_HWND) != S_OK)
     {
        AfxMessageBox("Failed: pWB->get_HWND");
        return;
     }

     HWND IEhWnd = (HWND)IE_HWND;

     //Code to put IE into a window
     //This will put IE into your app window
     ::SetParent(IEhWnd ,hWnd);

}


Thanks & Regards,
Smitha

Answer : Embedding iwebbrowser control inside ATL window.

Is CWebWindow your window class?  If so, you need to have that class inherit the required interfaces (IOleClientSite, etc), and the you need to implement all the the methods for those classes.  I have found that you don't necessarily need to implement all of the methods (although they must all be present).  What I have done in the past is put in each method and have it return E_NOTIMPL.  Then I put breakpoints in and figured out which methods were called, and implemented those.  I don't remember it being that difficult, but I do recall that there were some gotchas.
Random Solutions  
 
programming4us programming4us