• 大小: 91.42MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2022-02-17
  • 语言: C/C++
  • 标签: VS2017  MFC  

资源简介

研究了网上大量的MFC对话框打印及打印预览功能的demo之后,网上现有的版本都比较旧,所以选中了几个版本,合并修改,得到这个比较完美的最新版本,编译无错,成功运行。

资源截图

代码片段和文件信息

// CPrintframe.cpp: 实现文件
//

#include “stdafx.h“
#include “PrintPreview.h“
#include “CPrintframe.h“
#include “CPrintView.h“

// CPrintframe

IMPLEMENT_DYNCREATE(CPrintframe CframeWnd)

CPrintframe::CPrintframe()
{

}

CPrintframe::CPrintframe(CPrintPreviewDlg * pOld)
{
m_pOldWnd = pOld;
if (!Create(NULL _T(“打印预览“) WS_OVERLAPPEDWINDOW | FWS_ADDTOtitle CRect(100 100 520 694)))
TRACE0(“Failed to create view window! \n“);
}

CPrintframe::~CPrintframe()
{
m_pOldWnd->ShowWindow(SW_SHOW);
}



BEGIN_MESSAGE_MAP(CPrintframe CframeWnd)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_DESTROY()
END_MESSAGE_MAP()


// CPrintframe 消息处理程序


int CPrintframe::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CframeWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO:  在此添加您专用的创建代码
CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CPrintView);
context.m_pCurrentframe = this;
context.m_pCurrentDoc = NULL;
context.m_pLastView = NULL;
m_pView = STATIC_DOWNCAST(CPrintView CreateView(&context));

if (m_pView != NULL)
{
m_pView->ShowWindow(SW_SHOW);
SetActiveView(m_pView);
// SetLandscapeMode(DMORIENT_LANDSCAPE);
}

SetIcon(m_pOldWnd->GetIcon(FALSE) FALSE);
SetIcon(m_pOldWnd->GetIcon(TRUE) TRUE);
ShowWindow(SW_RESTORE);
CWinApp *pApp = AfxGetApp();
pApp->m_pMainWnd = this;
m_pView->OnFilePrintPreview();//打印预览
m_pView->SendMessageW(WM_COMMAND ID_FILE_PRINT);  // 直接打印
m_pOldWnd->ShowWindow(SW_SHOW);
return 0;
}


void CPrintframe::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CPrintframe* pf = (CPrintframe*)::AfxGetMainWnd();
CWinApp *pApp = AfxGetApp();
pApp->m_pMainWnd = pf->m_pOldWnd;
pf->DestroyWindow();

}

void CPrintframe::SetLandscapeMode(int PrintMode)
{
PRINTDLG   pd;
pd.lStructSize = (DWORD)sizeof(PRINTDLG);
BOOL   bRet = AfxGetApp()->GetPrinterDeviceDefaults(&pd);
if (bRet)
{
//   protect   memory   handle   with   ::GlobalLock   and   ::GlobalUnlock  
DEVMODE   FAR   *pDevMode = (DEVMODE   FAR   *)::GlobalLock(pd.hDevMode);
pDevMode->dmPaperSize = DMPAPER_A4;   //将打印纸设置为A4   
  //   set   orientation   to   landscape   
if (PrintMode == 1)     //纵向打印   
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
else   if (PrintMode == 2)    //横向打印   
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
::GlobalUnlock(pd.hDevMode);
}
}


void CPrintframe::OnDestroy()
{
if (m_pView != NULL)
m_pView->DestroyWindow();

CframeWnd::OnDestroy();
CframeWnd::OnDestroy();
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-28 09:42  PrintPreview\
     目录           0  2019-03-26 20:07  PrintPreview\.vs\
     目录           0  2019-03-26 20:07  PrintPreview\.vs\PrintPreview\
     目录           0  2019-03-28 17:11  PrintPreview\.vs\PrintPreview\v15\
     文件       49152  2019-03-28 17:11  PrintPreview\.vs\PrintPreview\v15\.suo
     文件    76984320  2019-03-28 17:11  PrintPreview\.vs\PrintPreview\v15\Browse.VC.db
     目录           0  2019-03-27 09:44  PrintPreview\.vs\PrintPreview\v15\ipch\
     文件   134873088  2019-03-28 17:04  PrintPreview\.vs\PrintPreview\v15\ipch\319eda88333220d2.ipch
     文件   115146752  2019-03-26 20:10  PrintPreview\.vs\PrintPreview\v15\ipch\45827e4d18c47407.ipch
     目录           0  2019-03-28 17:06  PrintPreview\PrintPreview\
     文件        5148  2019-03-28 16:44  PrintPreview\PrintPreview\CPrintframe.cpp
     文件        1488  2019-03-28 16:31  PrintPreview\PrintPreview\CPrintframe.h
     文件        2960  2019-03-28 15:46  PrintPreview\PrintPreview\CPrintPreviewView.cpp
     文件        1804  2019-03-28 15:44  PrintPreview\PrintPreview\CPrintPreviewView.h
     文件       10348  2019-03-28 16:00  PrintPreview\PrintPreview\CPrintView.cpp
     文件        2886  2019-03-28 16:50  PrintPreview\PrintPreview\CPrintView.h
     文件         612  2019-03-26 20:29  PrintPreview\PrintPreview\MFCClass.cpp
     文件      108536  2019-03-28 17:06  PrintPreview\PrintPreview\PrintPreview.aps
     文件        4288  2019-03-26 20:07  PrintPreview\PrintPreview\PrintPreview.cpp
     文件         872  2019-03-26 20:07  PrintPreview\PrintPreview\PrintPreview.h
     文件       10866  2019-03-28 17:06  PrintPreview\PrintPreview\PrintPreview.rc
     文件       10644  2019-03-26 20:38  PrintPreview\PrintPreview\PrintPreview.vcxproj
     文件        2602  2019-03-26 20:38  PrintPreview\PrintPreview\PrintPreview.vcxproj.filters
     文件         235  2019-03-26 20:38  PrintPreview\PrintPreview\PrintPreview.vcxproj.user
     文件        6308  2019-03-28 15:57  PrintPreview\PrintPreview\PrintPreviewDlg.cpp
     文件        1296  2019-03-28 15:57  PrintPreview\PrintPreview\PrintPreviewDlg.h
     目录           0  2019-03-26 20:07  PrintPreview\PrintPreview\res\
     文件       67777  2018-06-24 13:36  PrintPreview\PrintPreview\res\PrintPreview.ico
     文件         680  2019-03-26 20:07  PrintPreview\PrintPreview\res\PrintPreview.rc2
     文件        1426  2019-03-28 17:06  PrintPreview\PrintPreview\resource.h
     文件         234  2019-03-26 20:07  PrintPreview\PrintPreview\stdafx.cpp
............此处省略32个文件信息

评论

共有 条评论