Share via


Printing Pages with the WebBrowser Control

Although the WebBrowser control does not support a print method, you can print its contents by using one of the following methods:

  • Set the focus to the WebBrowser control and send a key combination of CTRL+P.

  • Call the IWebBrowser2::get_Document method, as shown in this example.

    LPDISPATCH lpDispatch = NULL;
    LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
    lpDispatch = m_pBrowser.get_Document();
    ASSERT(lpDispatch);
    lpDispatch->QueryInterface(IID_IOleCommandTarget, (void**)&lpOleCommandTarget);
    ASSERT(lpOleCommandTarget);
    lpDispatch->Release();
    // Print contents of WebBrowser control.
    lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);
    lpOleCommandTarget->Release();
    

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.