Search code examples
winapiiwebbrowser2

Hide WebBrowser control


I have a Win32 application which converts HTML into an image without displaying the control. (I dont have much experience to use ActiveX in a Win32 application).

I followed this MSDN article to create the control and call Navigate(): http://msdn.microsoft.com/en-us/library/aa451946.aspx

When I need to convert the image, I call IViewObjec::Draw(). The problem is the control is always visible even if I call the following function:

browser->put_Visible(VARIANT_FALSE); // browser is IWebBrowser2

When I stepped into the code I found out that when I call

mOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, mControlSite, 0, NULL, NULL)

the control becomes visible immediately. But from what I can see from MSDN is that OLEIVERB_INPLACEACTIVATE means

Activates an object in place without displaying tools, such as menus and toolbars, that end users need to change the behavior or appearance of the object. Single-clicking such an object causes it to negotiate the display of its user-interface tools with its container. If the container refuses, the object remains active but without its tools displayed.

I am a bit confused, I only want to hide it.


Solution

  • I found another solution.

    I just make normal window and put the html control into the windown and hide it, which solves all the problems that I mentioned above.

    In the ControlSite I implemented IOleWindow::GetWindow() to put control like following code (mWindow is just my Basic window class), just return this normal window's handle.

    HRESULT STDMETHODCALLTYPE GetWindow(/* [out] */ HWND __RPC_FAR* theWindow)
    {   
        *theWindow = mWindow.GetHandle();
        return S_OK;    
    }