📄 textznpdfprintdlldlg.cpp
字号:
// TextznPDFPrintDLLDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TextznPDFPrintDLL.h"
#include "TextznPDFPrintDLLDlg.h"
#include "SetPrintDlg.h"
#include <winspool.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTextznPDFPrintDLLDlg dialog
CTextznPDFPrintDLLDlg::CTextznPDFPrintDLLDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTextznPDFPrintDLLDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTextznPDFPrintDLLDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTextznPDFPrintDLLDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTextznPDFPrintDLLDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTextznPDFPrintDLLDlg, CDialog)
//{{AFX_MSG_MAP(CTextznPDFPrintDLLDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_PRINT, OnPrint)
ON_COMMAND(ID_SET_PRINT, OnSetPrint)
ON_COMMAND(ID_ABORT_PRINT, OnAbortPrint)
ON_COMMAND(ID_PRINTWITHDC, OnPrintwithdc)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTextznPDFPrintDLLDlg message handlers
BOOL CTextznPDFPrintDLLDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString strSNFilePath,strTemp ;
char *strFilePath;
strFilePath = new char[MAX_PATH+1];
GetModuleFileNameA( NULL , strFilePath , MAX_PATH );
char *p = strrchr( strFilePath, '\\' );
if (NULL == p)
return FALSE ;
strcpy(p, "\\Serial Number.txt");
CStdioFile mFile(strFilePath , CFile::modeCreate|CFile::modeNoTruncate|CFile::modeRead|CFile::typeText ) ;
mFile.Seek( 0, CStdioFile::begin );
mFile.ReadString( strTemp );
// TODO: Add extra initialization here
CoInitialize(NULL);
m_pPrint.CreateInstance( CLSID_PDFPrint );
m_pPrint->Initialize( strTemp.AllocSysString() , 0 );
OnSetPrint();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTextznPDFPrintDLLDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTextznPDFPrintDLLDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTextznPDFPrintDLLDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTextznPDFPrintDLLDlg::OnPrint()
{
// TODO: Add your command handler code here
CPrintDialog dlg(false);
CString filepath,printname;
CFileDialog fdlg(TRUE);
if(fdlg.DoModal())
filepath = fdlg.GetPathName();
if(dlg.DoModal())
{
HDC PDC = dlg.CreatePrinterDC();
printname = dlg.GetDeviceName();
m_pPrintevent.Initialize(m_pPrint,DIID__IPDFPrintEvents);
HDC hPrinterDC = NULL ;
HANDLE hPrinter = NULL ;
OpenPrinter( (LPTSTR)(LPCTSTR)printname, &hPrinter, NULL ) ;
DWORD cbNeeded = 0 ;
cbNeeded = DocumentProperties( NULL, hPrinter, (LPTSTR)(LPCTSTR)printname, NULL, NULL, NULL ) ;
PDEVMODE pDevMode = (PDEVMODE) new BYTE[cbNeeded] ;
memset( pDevMode, 0, cbNeeded ) ;
if (DocumentProperties(NULL, hPrinter, (LPTSTR)(LPCTSTR)printname, pDevMode, NULL, DM_OUT_BUFFER) > 0)
HDC hPrinterDC = CreateDC( "winspool", (LPTSTR)(LPCTSTR)printname, NULL, pDevMode ) ;
delete[] pDevMode ;
ClosePrinter( hPrinter ) ;
try
{
VARIANT vr ;
V_VT(&vr) = VT_BSTR ;
V_BSTR(&vr) = filepath.AllocSysString() ;
m_pPrint->Print( printname.AllocSysString() ,vr,_bstr_t(""));
}
catch(_com_error e)
{
AfxMessageBox( e.Description() ) ;
}
m_pPrintevent.Uninitialize(m_pPrint,DIID__IPDFPrintEvents);
OnCancel();
}
}
void CTextznPDFPrintDLLDlg::OnSetPrint()
{
// TODO: Add your command handler code here
CSetPrintDlg *pDlg,dlg1(this);
ZPP_PrintContent context;
ZPP_PrintPageScaling pagescaling;
ZPP_PrintCutMarks pagecutmark;
ZPP_PrintUpSelector UpSelector;
ZPP_PrintOddEvenRange OddEvenRange;
VARIANT_BOOL collate,m_pPrintAsImage,removeWhiteMargin,reverse,tileLablesb,waitforcompleteb,autoRotateAndCenter;
ZPP_PrintContent m_pPrintContent;
ZPP_PrintOddEvenRange m_pPrintOddEvenRange;
ZPP_PrintUpSelector m_pPrintUpSelector;
ZPP_PrintPageScaling m_pPrintPageScaling ;
ZPP_PrintCutMarks m_pPrintCutMarks ;
pDlg = new CSetPrintDlg(this);
m_pPrint->get_copies( &pDlg->m_copies );
m_pPrint->get_tileScale(&pDlg->m_tilescale );
m_pPrint->get_tileOverlap(&pDlg->m_tileoverlap);
m_pPrint->get_content(&context );
pDlg->m_ContextEnum = context;
m_pPrint->get_pageScaling(&pagescaling);
pDlg->m_PageScalingEnum = pagescaling;
m_pPrint->get_tileCutMarks(&pagecutmark);
pDlg->m_TileCutmarkEnum = pagecutmark;
m_pPrint->get_Nup(&UpSelector);
pDlg->m_NupEnum = UpSelector;
m_pPrint->get_evenOdd( &OddEvenRange );
pDlg->m_EvenOddEnum = OddEvenRange;
m_pPrint->get_printAsImage(&m_pPrintAsImage);
pDlg->m_printAsImageb = m_pPrintAsImage;
m_pPrint->get_removeWhiteMargin(&removeWhiteMargin);
pDlg->m_removeWhiteMarginb = removeWhiteMargin;
m_pPrint->get_reverse(&reverse);
pDlg->m_reverseb = reverse;
m_pPrint->get_tileLabels(&tileLablesb);
pDlg->m_tileLabelsb = tileLablesb;
m_pPrint->get_waitForComplete(&waitforcompleteb);
pDlg->m_waitforcompleteb = waitforcompleteb;
m_pPrint->get_autoRotateAndCenter(&autoRotateAndCenter);
pDlg->m_autorotateandcenterb =autoRotateAndCenter;
m_pPrint->get_collate(&collate);
pDlg->m_collateb = collate;
UpdateData(false);
if(pDlg->DoModal() == IDOK)
{
UpdateData(true);
m_pPrint->put_pageRange( pDlg->m_PageRange.AllocSysString() );
m_pPrint->put_autoRotateAndCenter( pDlg->m_autorotateandcenterb );
m_pPrint->put_collate( pDlg->m_collateb );
m_pPrint->put_reverse( pDlg->m_reverseb );
m_pPrint->put_printAsImage( pDlg->m_printAsImageb );
m_pPrint->put_removeWhiteMargin( pDlg->m_removeWhiteMarginb );
m_pPrint->put_tileLabels( pDlg->m_tileLabelsb );
m_pPrint->put_waitForComplete( pDlg->m_waitforcompleteb );
m_pPrint->put_copies( pDlg->m_copies );
m_pPrint->put_tileOverlap( pDlg->m_tileoverlap );
m_pPrint->put_tileScale( pDlg->m_tilescale );
UpdateData(true);
switch( pDlg->iPrintContent )
{
case 0:
m_pPrintContent = ZPP_ContentAndMarkup ;
break;
case 1:
m_pPrintContent = ZPP_ContentOnly ;
break;
case 2:
m_pPrintContent = ZPP_FormOnly ;
break;
}
m_pPrint->put_content( m_pPrintContent );
switch( pDlg->iPrintOddEvenRange )
{
case 0:
m_pPrintOddEvenRange = ZPP_OddEven ;
break;
case 1:
m_pPrintOddEvenRange = ZPP_OddOnly ;
break;
case 2:
m_pPrintOddEvenRange = ZPP_EvenOnly ;
break;
}
m_pPrint->put_evenOdd( m_pPrintOddEvenRange );
switch( pDlg->iPrintUpSelector )
{
case 0:
m_pPrintUpSelector = ZPP_2UP ;
break;
case 1:
m_pPrintUpSelector = ZPP_4UP ;
break;
case 2:
m_pPrintUpSelector = ZPP_6UP ;
break;
case 3:
m_pPrintUpSelector = ZPP_8UP ;
break;
case 4:
m_pPrintUpSelector = ZPP_16UP ;
break;
}
m_pPrint->put_Nup( m_pPrintUpSelector );
switch(pDlg->IPrintPageScaling)
{
case 0:
m_pPrintPageScaling = ZPP_None ;
break;
case 1:
m_pPrintPageScaling = ZPP_FitToPaper ;
break;
case 2:
m_pPrintPageScaling = ZPP_ShrinkLargePage ;
break;
case 3:
m_pPrintPageScaling = ZPP_TileLargePage ;
break;
case 4:
m_pPrintPageScaling = ZPP_Nup ;
break;
case 5:
m_pPrintPageScaling = ZPP_ChooseByPageSize ;
break;
}
m_pPrint->put_pageScaling( m_pPrintPageScaling );
switch( pDlg->IPrintCutMarks )
{
case 0:
m_pPrintCutMarks = ZPP_CutMark_None ;
break;
case 1:
m_pPrintCutMarks = ZPP_CutMark_WesternStyle ;
break;
case 2:
m_pPrintCutMarks = ZPP_CutMark_EasternStyle ;
break;
}
m_pPrint->put_tileCutMarks( m_pPrintCutMarks );
UpdateData( TRUE );
}
delete pDlg;
}
void CTextznPDFPrintDLLDlg::OnAbortPrint()
{
// TODO: Add your command handler code here
VARIANT_BOOL printflag ;
m_pPrint->IsPrinting( &printflag );
if( printflag )
{
m_pPrint->AbortPrinting();
}
}
void CTextznPDFPrintDLLDlg::OnOK()
{
// CDialog::OnOK();
}
void CTextznPDFPrintDLLDlg::OnPrintwithdc()
{
// TODO: Add your command handler code here
CPrintDialog dlg(false);
CString filepath;
CFileDialog fdlg(TRUE);
if(fdlg.DoModal())
filepath = fdlg.GetPathName();
if(dlg.DoModal())
{
HDC PDC = dlg.CreatePrinterDC();
try
{
VARIANT vr ;
V_VT(&vr) = VT_BSTR ;
V_BSTR(&vr) = filepath.AllocSysString() ;
m_pPrint->PrintWithDC((long)PDC , vr,_bstr_t(""));
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
}
}
}
void CTextznPDFPrintDLLDlg::OnDestroy()
{
CDialog::OnDestroy();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -