⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpdfview.cpp

📁 使用vc模板直接调用adobe reader(7.0以上的版本)
💻 CPP
字号:
// testpdfView.cpp : implementation of the CTestpdfView class
//

#include "stdafx.h"
#include "testpdf.h"

#include "testpdfDoc.h"
#include "testpdfView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestpdfView

IMPLEMENT_DYNCREATE(CTestpdfView, CFormView)

BEGIN_MESSAGE_MAP(CTestpdfView, CFormView)
	//{{AFX_MSG_MAP(CTestpdfView)
	ON_WM_SIZE()
	ON_WM_CLOSE()
	ON_COMMAND(ID_APP_EXIT, OnAppExit)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestpdfView construction/destruction

CTestpdfView::CTestpdfView()
	: CFormView(CTestpdfView::IDD)
{
	//{{AFX_DATA_INIT(CTestpdfView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CTestpdfView::~CTestpdfView()
{
}

void CTestpdfView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestpdfView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CTestpdfView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs


	return CFormView::PreCreateWindow(cs);
}

void CTestpdfView::OnInitialUpdate()
{
	CRect rt;
	GetClientRect(&rt);
	// 利用CWnd::CreateControl创建PDF控件窗口
	// Acrobat (Reader) 5.x/6.x的控件类ID为"PDF.PdfCtrl.5",7.x为"AcroPDF.PDF.1"
	m_wndPDF.CreateControl("AcroPDF.PDF.1", NULL, WS_CHILD | WS_VISIBLE, rt, this, 0);
	// 获取IDispatch接口指针
	LPUNKNOWN lpUnknown = m_wndPDF.GetControlUnknown();

	LPDISPATCH lpDispatch;
	lpUnknown->QueryInterface(IID_IDispatch, (void**)&lpDispatch);
	// 把获得的接口指针传递给组件驱动对象m_drvPDF,通过它调用控件的属性和方法
	// 当m_drvPDF销毁时,会自动释放接口指针
	lpUnknown->Release();
	m_drvPDF.AttachDispatch(lpDispatch);
	// 弹出一个“打开”对话框,选择要显示的PDF文件
	CFileDialog dlg(TRUE, "*.pdf", "*.pdf", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "PDF文件(*.pdf)|所有文件(*.*)|*.*|", NULL);
	if (dlg.DoModal() == IDOK)
		// 利用控件的方法LoadFile读取并显示PDF文件
		m_drvPDF.LoadFile(dlg.GetPathName());

	/*else
		OnCancel(); // 退出	*/
	CFormView::OnInitialUpdate();
	
	ResizeParentToFit();
}

/////////////////////////////////////////////////////////////////////////////
// CTestpdfView printing

BOOL CTestpdfView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTestpdfView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTestpdfView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CTestpdfView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CTestpdfView diagnostics

#ifdef _DEBUG
void CTestpdfView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTestpdfView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CTestpdfDoc* CTestpdfView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestpdfDoc)));
	return (CTestpdfDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestpdfView message handlers

BOOL CTestpdfView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

void CTestpdfView::OnSize(UINT nType, int cx, int cy) 
{
	CRect rect;
	GetClientRect(&rect);
    if(m_wndPDF)
	{m_wndPDF.SetWindowPos(&wndTop, rect.left, rect.top, rect.Width(), rect.Height(), NULL);
	m_wndPDF.RedrawWindow();}
		CFormView::OnSize(nType, cx, cy);

}

void CTestpdfView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect rect;
	GetClientRect(&rect);
    if(m_wndPDF)
	{m_wndPDF.SetWindowPos(&wndTop, rect.left, rect.top, rect.Width(), rect.Height(), NULL);
	m_wndPDF.RedrawWindow();}
	
}

void CTestpdfView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CFormView::CalcWindowRect(lpClientRect, nAdjustType);
}

BOOL CTestpdfView::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	//m_wndPDF.DestroyWindow();
	return CFormView::DestroyWindow();
}

void CTestpdfView::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	//m_wndPDF.DestroyWindow();
	//m_wndPDF.Release();
	CFormView::OnClose();
}

void CTestpdfView::OnAppExit() 
{
	// TODO: Add your command handler code here
	//m_drvPDF
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -