home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / bitdemo / bitdevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-29  |  3.0 KB  |  110 lines

  1. // BitDeVw.cpp : implementation of the CBitDemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "BitDemo.h"
  6.  
  7. #include "BitDeDoc.h"
  8. #include "BitDeVw.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CBitDemoView
  18.  
  19. IMPLEMENT_DYNCREATE(CBitDemoView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CBitDemoView, CView)
  22.    //{{AFX_MSG_MAP(CBitDemoView)
  23.       // NOTE - the ClassWizard will add and remove mapping macros here.
  24.       //    DO NOT EDIT what you see in these blocks of generated code!
  25.    //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CBitDemoView construction/destruction
  30.  
  31. CBitDemoView::CBitDemoView()
  32. {
  33.    // TODO: add construction code here
  34.    BITMAP BM;
  35.    
  36.    m_Bitmap.LoadBitmap (IDB_BITMAP1);
  37.    m_Bitmap.GetObject (sizeof (BM), &BM);
  38.    m_BitmapWidth = BM.bmWidth;
  39.    m_BitmapHeight = BM.bmHeight;   
  40. }
  41.  
  42. CBitDemoView::~CBitDemoView()
  43. {
  44. }
  45.  
  46. BOOL CBitDemoView::PreCreateWindow(CREATESTRUCT& cs)
  47. {
  48.    // TODO: Modify the Window class or styles here by modifying
  49.    //  the CREATESTRUCT cs
  50.  
  51.    return CView::PreCreateWindow(cs);
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CBitDemoView drawing
  56.  
  57. void CBitDemoView::OnDraw(CDC* pDC)
  58. {
  59.    CBitDemoDoc* pDoc = GetDocument();
  60.    ASSERT_VALID(pDoc);
  61.  
  62.    // TODO: add draw code for native data here
  63.    CDC MemDC;
  64.    RECT ClientRect;
  65.    
  66.    // create memory device context object and select bitmap object into it:
  67.    MemDC.CreateCompatibleDC (NULL);
  68.    MemDC.SelectObject (&m_Bitmap);
  69.               
  70.    // get current dimensions of view window:                   
  71.    GetClientRect (&ClientRect);
  72.                   
  73.    // display bitmap, stretching it to fit view window:                      
  74.    pDC->StretchBlt
  75.       (0,                 // coordinates of u-l corner of destination rectangle
  76.       0,
  77.       ClientRect.right,   // width of destination rectangle
  78.       ClientRect.bottom,  // height of destination rectangle
  79.       &MemDC,             // source device context object
  80.       0,                  // coordinates of u-l corner of source rectangle
  81.       0,
  82.       m_BitmapWidth,      // width of source rectangle
  83.       m_BitmapHeight,     // height of source rectangle
  84.       SRCCOPY);           // raster-operation code
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CBitDemoView diagnostics
  89.  
  90. #ifdef _DEBUG
  91. void CBitDemoView::AssertValid() const
  92. {
  93.    CView::AssertValid();
  94. }
  95.  
  96. void CBitDemoView::Dump(CDumpContext& dc) const
  97. {
  98.    CView::Dump(dc);
  99. }
  100.  
  101. CBitDemoDoc* CBitDemoView::GetDocument() // non-debug version is inline
  102. {
  103.    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBitDemoDoc)));
  104.    return (CBitDemoDoc*)m_pDocument;
  105. }
  106. #endif //_DEBUG
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CBitDemoView message handlers
  110.