Microsoft KB Archive/156732: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(3 intermediate revisions by the same user not shown)
Line 70: Line 70:
       CDialog::OnInitDialog();
       CDialog::OnInitDialog();


       m_ctlWebBrowser.Navigate(_T("http://www.microsoft.com"),
       m_ctlWebBrowser.Navigate(_T("http://www.microsoft.com"),
                                 NULL, NULL, NULL, NULL);
                                 NULL, NULL, NULL, NULL);
       return TRUE;
       return TRUE;
Line 90: Line 90:
       // set focus to control that previously had focus
       // set focus to control that previously had focus
       if (pWnd);
       if (pWnd);
           pWnd->SetFocus ();
           pWnd->SetFocus ();
   }
   }
                 </pre>
                 </pre>
Line 96: Line 96:


<pre class="codesample">  // DOCOBJ.H comes with the Internet Client SDK and is installed by
<pre class="codesample">  // DOCOBJ.H comes with the Internet Client SDK and is installed by
   // default in the &quot;\INetSDK\Include&quot; directory
   // default in the "\INetSDK\Include" directory
   #include &lt;docobj.h&gt;
   #include <docobj.h>


   void CAboutDlg::OnPrint()
   void CAboutDlg::OnPrint()
Line 107: Line 107:
       ASSERT(lpDispatch);
       ASSERT(lpDispatch);


       lpDispatch-&gt;QueryInterface(IID_IOleCommandTarget,
       lpDispatch->QueryInterface(IID_IOleCommandTarget,
                                   (void**)&amp;lpOleCommandTarget);
                                   (void**)&lpOleCommandTarget);
       ASSERT(lpOleCommandTarget);
       ASSERT(lpOleCommandTarget);


       lpDispatch-&gt;Release();
       lpDispatch->Release();


       // print contents of web browser control
       // print contents of web browser control
       lpOleCommandTarget-&gt;Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);
       lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);


       lpOleCommandTarget-&gt;Release();
       lpOleCommandTarget->Release();
   }
   }
   
   

Latest revision as of 12:28, 21 July 2020

Article ID: 156732

Article Last Modified on 7/1/2004



APPLIES TO

  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2



This article was previously published under Q156732

SUMMARY

The Web Browser component of Internet Explorer 3.x and 4.x does not support a Print method. You can still print the contents of the Web Browser control using one of these methods:

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


-or-

  • Call the GetDocument() method that returns an IDispatch*. Using the IDispatch*, call QueryInterface() on IID_IOleCommandTarget. With the object pointer returned, call Exec(NULL, OLECMDID_PRINT,0, NULL,NULL).


MORE INFORMATION

The following code can be used to cause the Web Browser control to print its contents. In this example, m_ctlWebBrowser is an instance of the wrapper class generated by Class Wizard for the control. m_ctlWebBrowser is contained in a dialog and initialized in the OnInitDialog function. A Print button on the dialog is wired to an OnPrint function. The Print button is enabled in response to the NavigateComplete event of the Web Browser control.



Sample Code

BOOL CAboutDlg::OnInitDialog()
   {
       CDialog::OnInitDialog();

       m_ctlWebBrowser.Navigate(_T("http://www.microsoft.com"),
                                NULL, NULL, NULL, NULL);
       return TRUE;
   }
   
                

First Method

   
 void CAboutDlg::OnPrint()
   {
       CWnd* pWnd = GetFocus ();

       m_ctlWebBrowser.SetFocus ();
       // send Ctrl-P
       keybd_event (VK_CONTROL, 0, 0, 0);
       keybd_event ('P', 0, 0, 0);

       // set focus to control that previously had focus
       if (pWnd);
           pWnd->SetFocus ();
   }
                

Second Method

   // DOCOBJ.H comes with the Internet Client SDK and is installed by
   // default in the "\INetSDK\Include" directory
   #include <docobj.h>

   void CAboutDlg::OnPrint()
   {
       LPDISPATCH lpDispatch = NULL;
       LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

       lpDispatch = m_ctlWebBrowser.GetDocument();
       ASSERT(lpDispatch);

       lpDispatch->QueryInterface(IID_IOleCommandTarget,
                                  (void**)&lpOleCommandTarget);
       ASSERT(lpOleCommandTarget);

       lpDispatch->Release();

       // print contents of web browser control
       lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);

       lpOleCommandTarget->Release();
   }
 

                

REFERENCES

Internet Client SDK Online documentation.

Keywords: kbhowto kbprint KB156732