Implementation steps
The following to Acrobat (Reader) 5.x/6.x for example, describes how to use the new controls achieve the display of PDF documents.
Run VC, create a new MFC dialog-based applications ViewPDF, generating option in the settings, select the "ActiveX Controls", the rest can use the default values. Generated after the dialog box to delete all of the controls.
Automation components to create the next-driven categories: Open Class Wizard, click on "Add Class" button in the pop-up menu, select "From a type library", with the type library file pdf.tlb category have the necessary components, the Acrobat software installation file is located in the ActiveX directory subdirectory.
Editor ViewPDFDlg.h, to add two data categories CViewPDFDlg members:
# include "pdf.h"//header file class components class CViewPDFDlg: public CDialog ( Protected: _DPdf M_drvPDF;//PDF driver object components, _DPdf is we have just generated component class CWnd m_wndPDF;//PDF control window ... ... in the class member functions CViewPDFDlg:: OnInitDialog, insert the following statement in:
//the main window to add WS_CLIPCHILDREN style, or show abnormal control ModifyStyle (0, WS_CLIPCHILDREN); //Access to the client area rectangle dialog box CRect rt; GetClientRect (& rt); //Use CWnd:: CreateControl create PDF control window //Acrobat (Reader) 5.x/6.x category ID for the control "PDF.PdfCtrl.5", 7.x for "AcroPDF.PDF.1" m_wndPDF.CreateControl ( "PDF.PdfCtrl.5", NULL, WS_CHILD | WS_VISIBLE, rt, this, 0); //Obtain IDispatch interface pointer LPUNKNOWN lpUnknown = m_wndPDF.GetControl Unknown (); LPDISPATCH lpDispatch; lpUnknown-> QueryInterface (IID_IDispatch, (void **) & lpDispatch); //To get the interface pointer passed to the component-driven object m_drvPDF, call control through its properties and methods //When m_drvPDF destroyed, it will automatically release interface pointer m_drvPDF.AttachDispatch (lpDispatch); //Pop up a "Open" dialog box, select to display PDF documents CFileDialog dlg (TRUE); if (dlg.DoModal () == IDOK) //Use the methods of control LoadFile read and display PDF documents M_drvPDF.LoadFile (dlg.GetPathName ());< br/> else OnCancel ();//from the |