Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.1 KiB

  1. // PrintSDIView.cpp : implementation of the CPrintSDIView class
  2. //
  3. #include "stdafx.h"
  4. #include "PrintSDI.h"
  5. #include "PrintSDIDoc.h"
  6. #include "PrintSDIView.h"
  7. #include "faxdlg.h"
  8. #include <winfax.h>
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CPrintSDIView
  16. IMPLEMENT_DYNCREATE(CPrintSDIView, CView)
  17. BEGIN_MESSAGE_MAP(CPrintSDIView, CView)
  18. //{{AFX_MSG_MAP(CPrintSDIView)
  19. ON_COMMAND(ID_FILE_FAX, OnFileFax)
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CPrintSDIView construction/destruction
  28. CPrintSDIView::CPrintSDIView()
  29. {
  30. // TODO: add construction code here
  31. }
  32. CPrintSDIView::~CPrintSDIView()
  33. {
  34. }
  35. BOOL CPrintSDIView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. // TODO: Modify the Window class or styles here by modifying
  38. // the CREATESTRUCT cs
  39. return CView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CPrintSDIView drawing
  43. void CPrintSDIView::OnDraw(CDC* pDC)
  44. {
  45. CPrintSDIDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. CRect rect;
  48. GetClientRect(rect);
  49. pDC->SetTextAlign(TA_BASELINE | TA_CENTER);
  50. pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
  51. pDC->SetBkMode(TRANSPARENT);
  52. pDC->TextOut(rect.right/2, 3*rect.bottom/4,pDoc->m_szText);
  53. CRect rect2( (rect.right-rect.left)/4 ,
  54. (rect.top),
  55. 3*(rect.right-rect.left)/4,
  56. (rect.bottom)/2);
  57. POINT pnt = {rect2.right/2,rect2.top};
  58. switch (pDoc->m_polytype) {
  59. case 0:
  60. //circle
  61. pDC->Arc(rect2,pnt,pnt);
  62. break;
  63. case 1:
  64. //sqare
  65. pDC->MoveTo(rect2.left,rect2.top);
  66. pDC->LineTo(rect2.right,rect2.top);
  67. pDC->LineTo(rect2.right,rect2.bottom);
  68. pDC->LineTo(rect2.left,rect2.bottom);
  69. pDC->LineTo(rect2.left,rect2.top);
  70. break;
  71. case 2:
  72. //triangle
  73. pDC->MoveTo(rect.right/2,rect2.top);
  74. pDC->LineTo(rect2.left,rect2.bottom);
  75. pDC->LineTo(rect2.right,rect2.bottom);
  76. pDC->LineTo(rect.right/2,rect2.top);
  77. break;
  78. default:
  79. pDC->Arc(rect2,pnt,pnt);
  80. }
  81. CString dbg;
  82. dbg.Format(TEXT("%d %d %d %d\n"),rect2.left, rect2.top, rect2.right, rect2.bottom);
  83. OutputDebugString(dbg);
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CPrintSDIView printing
  87. BOOL CPrintSDIView::OnPreparePrinting(CPrintInfo* pInfo)
  88. {
  89. // default preparation
  90. return DoPreparePrinting(pInfo);
  91. }
  92. void CPrintSDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  93. {
  94. // TODO: add extra initialization before printing
  95. }
  96. void CPrintSDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  97. {
  98. // TODO: add cleanup after printing
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CPrintSDIView diagnostics
  102. #ifdef _DEBUG
  103. void CPrintSDIView::AssertValid() const
  104. {
  105. CView::AssertValid();
  106. }
  107. void CPrintSDIView::Dump(CDumpContext& dc) const
  108. {
  109. CView::Dump(dc);
  110. }
  111. CPrintSDIDoc* CPrintSDIView::GetDocument() // non-debug version is inline
  112. {
  113. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPrintSDIDoc)));
  114. return (CPrintSDIDoc*)m_pDocument;
  115. }
  116. #endif //_DEBUG
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CPrintSDIView message handlers
  119. void CPrintSDIView::OnFileFax()
  120. {
  121. FaxDlg dlg;
  122. dlg.DoModal();
  123. FAX_CONTEXT_INFO FaxContextInfo;
  124. FAX_PRINT_INFO FaxPrintInfo = {0};
  125. DWORD JobId;
  126. FaxContextInfo.SizeOfStruct = sizeof(FAX_CONTEXT_INFO);
  127. FaxPrintInfo.SizeOfStruct = sizeof(FAX_PRINT_INFO);
  128. FaxPrintInfo.RecipientNumber = dlg.m_FaxNumber.GetBuffer(MAX_PATH);
  129. FaxPrintInfo.RecipientName = dlg.m_RecipientName.GetBuffer(MAX_PATH);
  130. // use the default FAX printer
  131. if (!FaxStartPrintJob(NULL,&FaxPrintInfo,&JobId,&FaxContextInfo) ) {
  132. CString dbg;
  133. dbg.Format(_T("FaxStartPrintJob failed, ec = %d\n"),GetLastError() );
  134. AfxMessageBox(dbg);
  135. return;
  136. }
  137. // print the document
  138. CDC dc;
  139. dc.Attach(FaxContextInfo.hDC);
  140. OnDraw(&dc);
  141. dc.EndDoc();
  142. }