攻击Wordpress网站,建设信基金管理有限公司网站,用nas建设服务器网站,阳江招聘网最新招聘信息首先在这里感谢互联网的大哥们#xff01;同时我讨厌动不动就是要vip才能查看#xff01;所以我写的不需要vip就能看。只求点个赞。
直接上代码#xff0c;新建6个文件CPrintFrame.cpp#xff1b;CPrintFrame.h#xff1b;CPrintPreviewView.cpp#xff1b;CPrintPrevie…首先在这里感谢互联网的大哥们同时我讨厌动不动就是要vip才能查看所以我写的不需要vip就能看。只求点个赞。
直接上代码新建6个文件CPrintFrame.cppCPrintFrame.hCPrintPreviewView.cppCPrintPreviewView.hCPrintView.cppCPrintView.h
下面是代码
CPrintFrame.h
#pragma once// CPrintFrame 框架
#include CPrintView.h
#include CertEditPage.h
#include DemarManageDlg.hclass CPrintFrame : public CFrameWnd
{DECLARE_DYNCREATE(CPrintFrame)
protected:CPrintFrame(); // 动态创建所使用的受保护的构造函数virtual ~CPrintFrame();public:CPrintFrame(CCertEditPage* pCCertEditPage, CDemarManageDlg* pDemarManageDlg, BOOL bPreview);CCertEditPage* m_pCCertEditPage;CPrintView* m_pCPrintView;CDemarManageDlg* m_pDemarManageDlg;BOOL m_bPreview;
protected:DECLARE_MESSAGE_MAP()
public:afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnClose();void SetOrientation(short orientation);virtual BOOL PreCreateWindow(CREATESTRUCT cs);virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
};
CPrintFrame.cpp
// CPrintFrame.cpp: 实现文件
//#include stdafx.h
#include CPrintFrame.h// CPrintFrameIMPLEMENT_DYNCREATE(CPrintFrame, CFrameWnd)CPrintFrame::CPrintFrame():m_pCCertEditPage(NULL),m_pCPrintView(NULL), m_bPreview(TRUE)
{m_pCCertEditPage NULL;
}CPrintFrame::CPrintFrame(CCertEditPage* pCCertEditPage, CDemarManageDlg* pDemarManageDlg,BOOL bPreview): m_pCCertEditPage(NULL), m_pCPrintView(NULL)
{m_bPreview bPreview;m_pCCertEditPage pCCertEditPage;m_pDemarManageDlg pDemarManageDlg;CString title;if (m_bPreview)title L打印预览;elsetitle L打印;if (Create(NULL, title, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CRect(200, 200, 500, 500))){//创建失败return;}SetOrientation(DMORIENT_LANDSCAPE);
}CPrintFrame::~CPrintFrame()
{//CWinApp* pApp AfxGetApp();//pApp-m_pMainWnd m_pDemarManageDlg;if (m_pCCertEditPage)m_pCCertEditPage-ShowWindow(SW_SHOW);
}BEGIN_MESSAGE_MAP(CPrintFrame, CFrameWnd)ON_WM_CREATE()ON_WM_CLOSE()
END_MESSAGE_MAP()// CPrintFrame 消息处理程序int CPrintFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{if (CFrameWnd::OnCreate(lpCreateStruct) -1)return -1;if (!m_pCCertEditPage)return -1;// TODO: 在此添加您专用的创建代码CCreateContext context;context.m_pNewViewClass RUNTIME_CLASS(CPrintView);context.m_pCurrentFrame this;context.m_pCurrentDoc NULL;context.m_pLastView NULL;m_pCPrintView STATIC_DOWNCAST(CPrintView, CreateView(context));if (!m_pCPrintView)return -1;if (m_bPreview){m_pCPrintView-ShowWindow(SW_SHOW);}SetActiveView(m_pCPrintView);SetIcon(m_pCCertEditPage-GetIcon(FALSE), FALSE);SetIcon(m_pCCertEditPage-GetIcon(TRUE), TRUE);//ShowWindow(SW_MAXIMIZE);CRect rect;m_pCCertEditPage-GetWindowRect(rect);MoveWindow(rect);ShowWindow(SW_SHOW);m_pCPrintView-m_pCPrintFrame this;CWinApp* pApp AfxGetApp();pApp-m_pMainWnd this;if (m_bPreview){m_pCPrintView-OnFilePrintPreview();m_pCCertEditPage-ShowWindow(SW_HIDE);}elsem_pCPrintView-SendMessage(WM_COMMAND, ID_FILE_PRINT);return 0;
}void CPrintFrame::OnClose()
{// TODO: 在此添加消息处理程序代码和/或调用默认值CWinApp* pApp AfxGetApp();pApp-m_pMainWnd m_pDemarManageDlg;this-DestroyWindow();//CFrameWnd::OnClose();
}
void CPrintFrame::SetOrientation(short orientation)
{PRINTDLG pd;pd.lStructSize (DWORD)sizeof(PRINTDLG);BOOL bRet AfxGetApp()-GetPrinterDeviceDefaults(pd);if (bRet){LPDEVMODE lpDevMode (LPDEVMODE) ::GlobalLock(pd.hDevMode);if (lpDevMode ! NULL)lpDevMode-dmOrientation orientation;::GlobalUnlock(pd.hDevMode);}
}BOOL CPrintFrame::PreCreateWindow(CREATESTRUCT cs)
{// TODO: 在此添加专用代码和/或调用基类if (!CFrameWnd::PreCreateWindow(cs))return FALSE;// TODO: Modify the Window class or styles here by modifying// the CREATESTRUCT cscs.dwExStyle ~WS_EX_CLIENTEDGE;cs.lpszClass AfxRegisterWndClass(0);return TRUE;//return CFrameWnd::PreCreateWindow(cs);
}BOOL CPrintFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{// TODO: 在此添加专用代码和/或调用基类if (m_pCPrintView m_pCPrintView-OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))return TRUE;return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}CPrintView.h
#pragma once
#include afxpriv.h// CPrintView 视图class CPrintView : public CScrollView
{DECLARE_DYNCREATE(CPrintView)protected:CPrintView(); // 动态创建所使用的受保护的构造函数virtual ~CPrintView();public:
#ifdef _DEBUGvirtual void AssertValid() const;
#ifndef _WIN32_WCEvirtual void Dump(CDumpContext dc) const;
#endif
#endifprotected:virtual void OnDraw(CDC* pDC); // 重写以绘制该视图virtual void OnInitialUpdate(); // 构造后的第一次DECLARE_MESSAGE_MAP()
public:void SetPaper(short dmOrientation, short dmPaperSize);void OnFilePrintPreview();afx_msg void OnFilePrint();void DrawCertification(CDC* pDC, CPrintInfo* pInfo);virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);CFrameWnd* m_pCPrintFrame;virtual void OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);void DrawCardData(CDC* pDC, CPrintInfo* pInfo);afx_msg void OnClose();BOOL DoPrintPreview(UINT nIDResource, CView* pPrintView, CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState);
};
CPrintView.cpp
// CPrintView.cpp: 实现文件
//#include stdafx.h
#include DemarManage.h
#include CPrintView.h
#include DemarManageDlg.h
#include CPrintFrame.h
#include CPrintPreviewView.h
// CPrintViewIMPLEMENT_DYNCREATE(CPrintView, CScrollView)CPrintView::CPrintView():m_pCPrintFrame(NULL)
{m_nMapMode MM_TEXT;}CPrintView::~CPrintView()
{
}BOOL CALLBACK _AfxMyPreviewCloseProc(CFrameWnd* pFrameWnd)
{ASSERT_VALID(pFrameWnd);CPrintPreviewView* pView (CPrintPreviewView*)pFrameWnd-GetDlgItem(AFX_IDW_PANE_FIRST);ASSERT_KINDOF(CPrintPreviewView, pView);pView-OnPreviewClose();return FALSE;
}BEGIN_MESSAGE_MAP(CPrintView, CScrollView)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CPrintView::OnFilePrintPreview)ON_COMMAND(ID_FILE_PRINT, CPrintView::OnFilePrint)ON_WM_CLOSE()
END_MESSAGE_MAP()// CPrintView 诊断#ifdef _DEBUG
void CPrintView::AssertValid() const
{CScrollView::AssertValid();
}#ifndef _WIN32_WCE
void CPrintView::Dump(CDumpContext dc) const
{CScrollView::Dump(dc);
}
#endif
#endif //_DEBUG// CPrintView 绘图void CPrintView::OnInitialUpdate()
{CScrollView::OnInitialUpdate();CSize sizeTotal;// TODO: 计算此视图的合计大小sizeTotal.cx sizeTotal.cy 100;SetScrollSizes(MM_TEXT, sizeTotal);
}void CPrintView::OnDraw(CDC* pDC)
{CDocument* pDoc GetDocument();// TODO: 在此添加绘制代码}/************************************************************************/
/* 设置纸张 */
/************************************************************************/
void CPrintView::SetPaper(short dmOrientation, short dmPaperSize)
{PRINTDLG pd;pd.lStructSize (DWORD)sizeof(PRINTDLG);BOOL bRet AfxGetApp()-GetPrinterDeviceDefaults(pd);if (bRet){LPDEVMODE lpDevMode (LPDEVMODE) ::GlobalLock(pd.hDevMode);if (lpDevMode ! NULL){lpDevMode-dmOrientation dmOrientation;lpDevMode-dmPaperSize dmPaperSize;}::GlobalUnlock(pd.hDevMode);}
}void CPrintView::OnFilePrintPreview()
{CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame-m_pCCertEditPage)return;switch (pCPrintFrame-m_pCCertEditPage-m_nPrintMode){case 1:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 2:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 4:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;}//CView::OnFilePrintPreview();CPrintPreviewState* pState new CPrintPreviewState;pState-lpfnCloseProc _AfxMyPreviewCloseProc;if (!DoPrintPreview(AFX_IDD_PREVIEW_TOOLBAR, this, RUNTIME_CLASS(CPrintPreviewView), pState)){TRACE0(Error: DoPrintPreview failed.\n);AfxMessageBox(AFX_IDP_COMMAND_FAILURE);delete pState;}
}
BOOL CPrintView::DoPrintPreview(UINT nIDResource, CView* pPrintView, CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState)
{ASSERT_VALID_IDR(nIDResource);if (!m_pCPrintFrame || !pPrintView || !pPreviewViewClass)return FALSE;ASSERT(pPreviewViewClass-IsDerivedFrom(RUNTIME_CLASS(CPreviewView)));if(!pState)return FALSE;CCreateContext context;context.m_pCurrentFrame m_pCPrintFrame;context.m_pCurrentDoc GetDocument();context.m_pLastView this;// Create the preview view objectCPrintPreviewView* pView (CPrintPreviewView*)pPreviewViewClass-CreateObject();if (!pView){TRACE0(Error: Failed to create preview view.\n);return FALSE;}ASSERT_KINDOF(CPreviewView, pView);pView-m_pPreviewState pState; // save pointerm_pCPrintFrame-OnSetPreviewMode(TRUE, pState); // Take over Frame Window//Create the toolbar from the dialog resourcepView-m_pToolBar new CDialogBar;if (!pView-m_pToolBar-Create(m_pCPrintFrame, MAKEINTRESOURCE(nIDResource),CBRS_TOP, AFX_IDW_PREVIEW_BAR)){TRACE0(Error: Preview could not create toolbar dialog.\n);m_pCPrintFrame-OnSetPreviewMode(FALSE, pState); // restore Frame Windowdelete pView-m_pToolBar; // not autodestruct yetpView-m_pToolBar NULL;pView-m_pPreviewState NULL; // do not delete state structuredelete pView;return FALSE;}pView-m_pToolBar-m_bAutoDelete TRUE; // automatic cleanupif (!pView-Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,CRect(0, 0, 0, 0), m_pCPrintFrame, AFX_IDW_PANE_FIRST, context)){TRACE0(Error: couldnt create preview view for frame.\n);m_pCPrintFrame-OnSetPreviewMode(FALSE, pState); // restore Frame WindowpView-m_pPreviewState NULL; // do not delete state structuredelete pView;return FALSE;}pState-pViewActiveOld m_pCPrintFrame-GetActiveView();CPrintView* pActiveView (CPrintView*)m_pCPrintFrame-GetActiveFrame()-GetActiveView();if (pActiveView ! NULL)pActiveView-OnActivateView(FALSE, pActiveView, pActiveView);if (!pView-SetPrintView(pPrintView)){pView-OnPreviewClose();return TRUE; // signal that OnEndPrintPreview was called}m_pCPrintFrame-SetActiveView(pView); // set active view - even for MDI// update toolbar and redraw everythingpView-m_pToolBar-SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE);m_pCPrintFrame-RecalcLayout(); // position and size everythingm_pCPrintFrame-UpdateWindow();return TRUE;
}void CPrintView::OnFilePrint()
{// TODO: 在此添加命令处理程序代码CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame-m_pCCertEditPage)return;if (!pCPrintFrame-m_bPreview)pCPrintFrame-ShowWindow(SW_HIDE);switch (pCPrintFrame-m_pCCertEditPage-m_nPrintMode){case 1:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 2:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 4:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;}CView::OnFilePrint();if (!pCPrintFrame-m_bPreview){CWinApp* pApp AfxGetApp();pApp-m_pMainWnd pCPrintFrame-m_pDemarManageDlg;pCPrintFrame-DestroyWindow();}
}void CPrintView::DrawCertification(CDC* pDC, CPrintInfo* pInfo)
{if (!pDC)return;CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;if(!pCPrintFrame || !pCPrintFrame-m_pDemarManageDlg)return;POINT point { 0, 0 };SIZE size { pDC-GetDeviceCaps(HORZRES),pDC-GetDeviceCaps(VERTRES) };CRect clientRect(point, size);double nLeftSpace(0.8), nTopSpace(0.8), nRightSpace(0.8), nBottomSpace(0.8);int iLeftSpace(0), iTopSpace(0), iRightSpace(0), iBottomSpace(0);iLeftSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nLeftSpace);iTopSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nTopSpace);iRightSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nRightSpace);iBottomSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nBottomSpace);//这里添加打印代码打印自己想要的
}BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame-m_pCCertEditPage)return FALSE;// TODO: 调用 DoPreparePrinting 以调用“打印”对话框switch (pCPrintFrame-m_pCCertEditPage-m_nPrintMode){case 1:pInfo-SetMaxPage(1);pInfo-m_bDirect FALSE;break;case 2:pInfo-SetMaxPage(1);pInfo-m_bDirect FALSE;break;case 4:pInfo-SetMaxPage(2);pInfo-m_bDirect FALSE;break;default:break;}return DoPreparePrinting(pInfo);
}void CPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{// TODO: 在此添加专用代码和/或调用基类CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame-m_pCCertEditPage)return;switch (pCPrintFrame-m_pCCertEditPage-m_nPrintMode){case 1:DrawCertification(pDC, pInfo);break;case 2:DrawCardData(pDC, pInfo);break;case 4:if (pInfo-m_nCurPage 1)DrawCertification(pDC, pInfo);else if (pInfo-m_nCurPage 2)DrawCardData(pDC, pInfo);break;default:break;}//CScrollView::OnPrint(pDC, pInfo);
}void CPrintView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{// TODO: 在此添加专用代码和/或调用基类if (!m_pCPrintFrame || !pView || !pDC)return;//pInfo-m_nCurPage 1;//CScrollView::OnEndPrintPreview(pDC, pInfo, point, pView);CPrintPreviewView* pCPrintPreviewView (CPrintPreviewView*)pView;if (!pCPrintPreviewView-m_pPrintView)OnEndPrinting(pDC, pInfo);// restore the old main windowm_pCPrintFrame-OnSetPreviewMode(FALSE, pCPrintPreviewView-m_pPreviewState);// Force active view back to old onem_pCPrintFrame-SetActiveView(pCPrintPreviewView-m_pPreviewState-pViewActiveOld);if (m_pCPrintFrame ! GetParentFrame())OnActivateView(TRUE, this, this);pView-DestroyWindow();m_pCPrintFrame-RecalcLayout();m_pCPrintFrame-SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE, 0L);m_pCPrintFrame-UpdateWindow();
}void CPrintView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{// TODO: 在此添加专用代码和/或调用基类CScrollView::OnEndPrinting(pDC, pInfo);//CPrintFrame* pCPrintFrame (CPrintFrame*)m_pCPrintFrame;//if (!pCPrintFrame || !pCPrintFrame-m_pDemarManageDlg)// return;//if(pInfo-m_bPreview 0)// pCPrintFrame-PostMessageW(WM_CLOSE);
}
void CPrintView::DrawCardData(CDC* pDC, CPrintInfo* pInfo)
{if (!pDC || !pInfo) return;CPrintFrame* pMainFrm (CPrintFrame*)m_pCPrintFrame;if (!pMainFrm) return;POINT point { 0, 0 };SIZE size { pDC-GetDeviceCaps(HORZRES),pDC-GetDeviceCaps(VERTRES) };CRect clientRect(point, size);chartParam.m_showRect clientRect;double nLeftSpace(0.8), nTopSpace(0.8), nRightSpace(0.8), nBottomSpace(0.8);int iLeftSpace(0), iTopSpace(0), iRightSpace(0), iBottomSpace(0);iLeftSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nLeftSpace);iTopSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nTopSpace);iRightSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nRightSpace);iBottomSpace (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nBottomSpace);//这里添加打印代码打印自己想要的}void CPrintView::OnClose()
{// TODO: 在此添加消息处理程序代码和/或调用默认值CScrollView::OnClose();
}CPrintPreviewView.h
#pragma once// CPrintPreviewView 视图class CPrintPreviewView : public CPreviewView
{DECLARE_DYNCREATE(CPrintPreviewView)protected:CPrintPreviewView(); // 动态创建所使用的受保护的构造函数virtual ~CPrintPreviewView();public:
#ifdef _DEBUGvirtual void AssertValid() const;
#ifndef _WIN32_WCEvirtual void Dump(CDumpContext dc) const;
#endif
#endiffriend class CPrintView;
protected:DECLARE_MESSAGE_MAP()afx_msg void OnPreviewClose();afx_msg void OnPreviewPrint();friend BOOL CALLBACK _AfxMyPreviewCloseProc(CFrameWnd* pFrameWnd);virtual void OnDraw(CDC* pDC);
};CPrintPreviewView.cpp
// CPrintPreviewView.cpp: 实现文件
//#include stdafx.h
#include DemarManage.h
#include CPrintPreviewView.h// CPrintPreviewViewIMPLEMENT_DYNCREATE(CPrintPreviewView, CPreviewView)CPrintPreviewView::CPrintPreviewView()
{}CPrintPreviewView::~CPrintPreviewView()
{
}BEGIN_MESSAGE_MAP(CPrintPreviewView, CPreviewView)ON_COMMAND(AFX_ID_PREVIEW_CLOSE, OnPreviewClose)ON_COMMAND(AFX_ID_PREVIEW_PRINT, OnPreviewPrint)
END_MESSAGE_MAP()// CPrintPreviewView 诊断#ifdef _DEBUG
void CPrintPreviewView::AssertValid() const
{CPreviewView::AssertValid();
}#ifndef _WIN32_WCE
void CPrintPreviewView::Dump(CDumpContext dc) const
{CPreviewView::Dump(dc);
}
#endif
#endif //_DEBUG// CPrintPreviewView 消息处理程序
#include CPrintFrame.h
void CPrintPreviewView::OnPreviewClose()
{CPrintFrame* pf (CPrintFrame*)::AfxGetMainWnd();CWinApp * pApp AfxGetApp();pApp-m_pMainWnd pf-m_pDemarManageDlg;pf-DestroyWindow();
}void CPrintPreviewView::OnPreviewPrint()
{m_pPrintView-SendMessage(WM_COMMAND, ID_FILE_PRINT);OnPreviewClose();
}void CPrintPreviewView::OnDraw(CDC* pDC)
{// TODO: 在此添加专用代码和/或调用基类CPreviewView::OnDraw(pDC);m_pToolBar-PostMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE);// 控制条的命令状态更新
}