DEMOVIEW.CPP
上传用户:wep9318
上传日期:2007-01-07
资源大小:893k
文件大小:4k
源码类别:

图片显示

开发平台:

Visual C++

  1. // demoView.cpp : implementation of the CDemoView class
  2. //
  3. #include "stdafx.h"
  4. #include "cimage.h"
  5. #include "demo.h"
  6. #include "demoDoc.h"
  7. #include "demoView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDemoView
  15. IMPLEMENT_DYNCREATE(CDemoView, CScrollView)
  16. BEGIN_MESSAGE_MAP(CDemoView, CScrollView)
  17. //{{AFX_MSG_MAP(CDemoView)
  18. // NOTE - the ClassWizard will add and remove mapping macros here.
  19. //    DO NOT EDIT what you see in these blocks of generated code!
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CDemoView construction/destruction
  28. CDemoView::CDemoView()
  29. {
  30. SetScrollSizes(MM_TEXT, CSize(0, 0));
  31. }
  32. CDemoView::~CDemoView()
  33. {
  34. }
  35. BOOL CDemoView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. // TODO: Modify the Window class or styles here by modifying
  38. //  the CREATESTRUCT cs
  39. return CScrollView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDemoView drawing
  43. void CDemoView::OnDraw(CDC* pDC)
  44. {
  45. CDemoDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. CPoint pos(GetScrollPosition());
  48. CRect rect;
  49. GetClientRect(&rect);
  50. int width = rect.right - rect.left;
  51. int height = rect.bottom - rect.top;
  52. if (pDoc->GetImage())
  53. {
  54. int x = -pos.x;
  55. int y = -pos.y;
  56. if (width >= pDoc->GetImage()->GetWidth())
  57. x = (width - pDoc->GetImage()->GetWidth())/2;
  58. if (height >= pDoc->GetImage()->GetHeight())
  59. y = (height - pDoc->GetImage()->GetHeight())/2;
  60. CDC *dc = GetDC();
  61. CPalette *hOldPal = 0;
  62. if (pDoc->GetImage()->GetPalette())
  63. {
  64. hOldPal = dc->SelectPalette(pDoc->GetImage()->GetPalette(), TRUE);
  65. dc->RealizePalette();
  66. }
  67. if (pDoc->GetStretchMode())
  68. {
  69. SetScrollSizes(MM_TEXT,
  70. CSize(0,0));
  71. pDoc->GetImage()->Stretch(dc, 0, 0, width, height);
  72. }
  73. else
  74. {
  75. SetScrollSizes(MM_TEXT,
  76. CSize(pDoc->GetImage()->GetWidth(), pDoc->GetImage()->GetHeight()));
  77. pDoc->GetImage()->Draw(dc, x, y);
  78. }
  79. // dc->SelectPalette(hOldPal, TRUE);
  80. ReleaseDC(dc);
  81. }
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CDemoView printing
  85. BOOL CDemoView::OnPreparePrinting(CPrintInfo* pInfo)
  86. {
  87. // default preparation
  88. return DoPreparePrinting(pInfo);
  89. }
  90. void CDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  91. {
  92. // TODO: add extra initialization before printing
  93. }
  94. void CDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  95. {
  96. // TODO: add cleanup after printing
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CDemoView diagnostics
  100. #ifdef _DEBUG
  101. void CDemoView::AssertValid() const
  102. {
  103. CScrollView::AssertValid();
  104. }
  105. void CDemoView::Dump(CDumpContext& dc) const
  106. {
  107. CScrollView::Dump(dc);
  108. }
  109. CDemoDoc* CDemoView::GetDocument() // non-debug version is inline
  110. {
  111. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc)));
  112. return (CDemoDoc*)m_pDocument;
  113. }
  114. #endif //_DEBUG
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CDemoView message handlers
  117. void CDemoView::OnInitialUpdate() 
  118. {
  119. CScrollView::OnInitialUpdate();
  120. if (GetDocument()->GetImage())
  121. SetScrollSizes(MM_TEXT,
  122.   CSize(GetDocument()->GetImage()->GetWidth(), GetDocument()->GetImage()->GetHeight()));
  123. }