home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / mdibind / maskview.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  134 lines

  1. // MaskView.cpp : implementation of the CMaskView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "MDIBind.h"
  15.  
  16. #include "MDIDoc.h"
  17. #include "MaskView.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMaskView
  27.  
  28. IMPLEMENT_DYNCREATE(CMaskView, CView)
  29.  
  30. BEGIN_MESSAGE_MAP(CMaskView, CView)
  31.     //{{AFX_MSG_MAP(CMaskView)
  32.     ON_WM_CREATE()
  33.     ON_WM_SIZE()
  34.     ON_WM_DESTROY()
  35.     //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMaskView construction/destruction
  40.  
  41. CMaskView::CMaskView()
  42. {
  43.     m_pMaskCtl = new CMSMask;
  44. }
  45.  
  46. CMaskView::~CMaskView()
  47. {
  48.     delete m_pMaskCtl;
  49. }
  50.  
  51. BOOL CMaskView::PreCreateWindow(CREATESTRUCT& cs)
  52. {
  53.     // TODO: Modify the Window class or styles here by modifying
  54.     // the CREATESTRUCT cs
  55.  
  56.     return CView::PreCreateWindow(cs);
  57. }
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMaskView drawing
  61.  
  62. void CMaskView::OnDraw(CDC* pDC)
  63. {
  64.     CMDIBindDoc* pDoc = GetDocument();
  65.     ASSERT_VALID(pDoc);
  66.  
  67.     // TODO: add draw code for native data here
  68. }
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CMaskView diagnostics
  72.  
  73. #ifdef _DEBUG
  74. void CMaskView::AssertValid() const
  75. {
  76.     CView::AssertValid();
  77. }
  78.  
  79. void CMaskView::Dump(CDumpContext& dc) const
  80. {
  81.     CView::Dump(dc);
  82. }
  83.  
  84. CMDIBindDoc* CMaskView::GetDocument() // non-debug version is inline
  85. {
  86.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMDIBindDoc)));
  87.     return (CMDIBindDoc*) m_pDocument;
  88. }
  89. #endif //_DEBUG
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMaskView message handlers
  93.  
  94. int CMaskView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  95. {
  96.     if (CView::OnCreate(lpCreateStruct) == -1)
  97.         return -1;
  98.  
  99.     RECT r=  { 2,2,400,300 };
  100.  
  101.     m_pMaskCtl->Create(NULL,NULL,
  102.                        WS_VISIBLE | WS_CHILD, r, this, 1);
  103.  
  104.     return 0;
  105. }
  106.  
  107. void CMaskView::OnSize(UINT nType, int cx, int cy)
  108. {
  109.     CView::OnSize(nType, cx, cy);
  110.  
  111.     if (::IsWindow(m_pMaskCtl->m_hWnd) )
  112.         m_pMaskCtl->MoveWindow(2,2,cx-4,cy-4,FALSE);  // do not repaint
  113.  
  114.  
  115. }
  116.  
  117. // binds the grid control to the RDC control
  118. void CMaskView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint )
  119. {
  120.     CMDIBindDoc* pDoc=GetDocument();
  121.     m_pMaskCtl->BindDefaultProperty(0x16,VT_BSTR,
  122.         pDoc->m_boundCol,
  123.         pDoc->m_pRDC); // rebind the control to new RDC & column
  124. }
  125.  
  126.  
  127.  
  128. // simple DataBound control must be unbound when destroyed
  129. void CMaskView::OnDestroy()
  130. {
  131.     m_pMaskCtl->BindDefaultProperty(0x16,VT_BSTR,NULL,NULL); // unbind from RDC
  132.     CView::OnDestroy();
  133. }
  134.