PrintPreviewView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // PrintPreviewView.cpp : implementation of the CPrintPreviewView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "PrintPreview.h"
  22. #include "PrintPreviewDoc.h"
  23. #include "PrintPreviewView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CPrintPreviewView
  31. IMPLEMENT_DYNCREATE(CPrintPreviewView, CRichEditView)
  32. BEGIN_MESSAGE_MAP(CPrintPreviewView, CRichEditView)
  33. //{{AFX_MSG_MAP(CPrintPreviewView)
  34. // NOTE - the ClassWizard will add and remove mapping macros here.
  35. //    DO NOT EDIT what you see in these blocks of generated code!
  36. //}}AFX_MSG_MAP
  37. // Standard printing commands
  38. ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  39. ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  40. ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CPrintPreviewView construction/destruction
  44. CPrintPreviewView::CPrintPreviewView()
  45. {
  46. // TODO: add construction code here
  47. }
  48. CPrintPreviewView::~CPrintPreviewView()
  49. {
  50. }
  51. BOOL CPrintPreviewView::PreCreateWindow(CREATESTRUCT& cs)
  52. {
  53. // TODO: Modify the Window class or styles here by modifying
  54. //  the CREATESTRUCT cs
  55. BOOL bPreCreated = CRichEditView::PreCreateWindow(cs);
  56. return bPreCreated;
  57. }
  58. void CPrintPreviewView::OnInitialUpdate()
  59. {
  60. CRichEditView::OnInitialUpdate();
  61. SetMargins(CRect(720, 720, 720, 720));
  62. static BOOL bLoadOnce = FALSE;
  63. if (!bLoadOnce)
  64. {
  65. bLoadOnce = TRUE;
  66. HINSTANCE hInstance = AfxGetInstanceHandle();
  67. LPCTSTR lpszResourceName = _T("PRINTPREVIEW.RTF");
  68. LPCTSTR lpszResourceType = _T("RTF");
  69. HRSRC hRsrc = ::FindResource(hInstance, lpszResourceName, lpszResourceType);
  70. if (hRsrc == NULL)
  71. return;
  72. HGLOBAL hGlobal = LoadResource(hInstance, hRsrc);
  73. if (hGlobal == NULL)
  74. return;
  75. LPCSTR pData = (LPCSTR)LockResource(hGlobal);
  76. if (pData == NULL)
  77. return;
  78. DWORD dwSize = (DWORD)SizeofResource(hInstance, hRsrc);
  79. if (dwSize == 0)
  80. return;
  81. CMemFile memRTF((BYTE*)pData, dwSize, 0);
  82. CArchive ar(&memRTF, CArchive::load | CArchive::bNoFlushOnDelete | CArchive::bNoByteSwap);
  83. Serialize(ar);
  84. }
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CPrintPreviewView drawing
  88. void CPrintPreviewView::OnDraw(CDC* /*pDC*/)
  89. {
  90. CPrintPreviewDoc* pDoc = GetDocument();
  91. ASSERT_VALID(pDoc);
  92. // TODO: add draw code for native data here
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CPrintPreviewView printing
  96. BOOL CPrintPreviewView::OnPreparePrinting(CPrintInfo* pInfo)
  97. {
  98. // default CRichEditView preparation
  99. return CRichEditView::DoPreparePrinting(pInfo);
  100. }
  101. void CPrintPreviewView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  102. {
  103. // Default CRichEditView begin printing.
  104. CRichEditView::OnBeginPrinting(pDC, pInfo);
  105. }
  106. void CPrintPreviewView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
  107. {
  108. // Default CRichEditView end printing
  109. CRichEditView::OnEndPrinting(pDC, pInfo);
  110. }
  111. void CPrintPreviewView::OnFilePrintPreview()
  112. {
  113. // In derived classes, implement special window handling here
  114. // Be sure to Unhook Frame Window close if hooked.
  115. // must not create this on the frame.  Must outlive this function
  116. CPrintPreviewState* pState = new CPrintPreviewState;
  117. // DoPrintPreview's return value does not necessarily indicate that
  118. // Print preview succeeded or failed, but rather what actions are necessary
  119. // at this point.  If DoPrintPreview returns TRUE, it means that
  120. // OnEndPrintPreview will be (or has already been) called and the
  121. // pState structure will be/has been deleted.
  122. // If DoPrintPreview returns FALSE, it means that OnEndPrintPreview
  123. // WILL NOT be called and that cleanup, including deleting pState
  124. // must be done here.
  125. if ( !DoPrintPreview( XTP_IDD_PREVIEW_DIALOGBAR, this,
  126. RUNTIME_CLASS( CXTPPreviewView ), pState ))
  127. {
  128. // In derived classes, reverse special window handling here for
  129. // Preview failure case
  130. TRACE0( "Error: DoPrintPreview failed.n" );
  131. AfxMessageBox( AFX_IDP_COMMAND_FAILURE );
  132. delete pState;      // preview failed to initialize, delete State now
  133. }
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CPrintPreviewView diagnostics
  137. #ifdef _DEBUG
  138. void CPrintPreviewView::AssertValid() const
  139. {
  140. CRichEditView::AssertValid();
  141. }
  142. void CPrintPreviewView::Dump(CDumpContext& dc) const
  143. {
  144. CRichEditView::Dump(dc);
  145. }
  146. CPrintPreviewDoc* CPrintPreviewView::GetDocument() // non-debug version is inline
  147. {
  148. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintPreviewDoc)));
  149. return (CPrintPreviewDoc*)m_pDocument;
  150. }
  151. #endif //_DEBUG
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CPrintPreviewView message handlers