home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / ilib_vb / mfcview.cp_ / mfcview.cp
Encoding:
Text File  |  1996-11-20  |  3.2 KB  |  134 lines

  1. // mfcview.cpp : implementation of the CMfcView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "imview.h"
  6.  
  7. #include "mfcdoc.h"
  8. #include "mfcview.h"
  9. #include "mainfrm.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMfcView
  18.  
  19. IMPLEMENT_DYNCREATE(CMfcView, CScrollView)
  20.  
  21. BEGIN_MESSAGE_MAP(CMfcView, CScrollView)
  22.     //{{AFX_MSG_MAP(CMfcView)
  23.     ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
  24.     //}}AFX_MSG_MAP
  25.  
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CDibView construction/destruction
  30.  
  31. CMfcView::CMfcView()
  32. {
  33. }
  34.  
  35. CMfcView::~CMfcView()
  36. {
  37. }
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CMfcView drawing
  41.  
  42. void CMfcView::OnDraw(CDC* pDC)
  43. {   
  44.     CMfcDoc* pDoc = GetDocument();
  45.     CPalette * OldPalette;               
  46.     CBitmap * OldBitmap;
  47.     CDC * pMemoryDC;
  48.     CBitmap* bitmap = pDoc->GetDocBitmap();
  49.     CPalette* palette = pDoc->GetDocPalette();    
  50.     CSize Rsize;
  51.     
  52.     if (bitmap->GetSafeHandle() != NULL)
  53.      {
  54.       CRect rectddb;
  55.       Rsize = pDoc->GetDocSize();
  56.       rectddb.top = rectddb.left = 0;
  57.       rectddb.right = Rsize.cx;
  58.       rectddb.bottom = Rsize.cy;
  59.       CRect rcDest;
  60.       rcDest = rectddb;
  61.       pMemoryDC = new CDC;
  62.       pMemoryDC->CreateCompatibleDC(pDC);    
  63.       
  64.       if (palette->GetSafeHandle() != NULL)
  65.         OldPalette = pMemoryDC->SelectPalette(palette, 0);
  66.       
  67.       OldBitmap = (CBitmap *)pMemoryDC->SelectObject(bitmap);
  68.       
  69.       pDC->BitBlt(0, 0, rectddb.right, rectddb.bottom, pMemoryDC,
  70.                   0, 0, SRCCOPY);
  71.       pMemoryDC->SelectPalette(OldPalette, 0);
  72.       pMemoryDC->SelectObject(OldBitmap);
  73.       delete pMemoryDC;
  74.      }      
  75. }
  76.  
  77. // CMfcView commands
  78.  
  79.  
  80. LRESULT CMfcView::OnDoRealize(WPARAM wParam, LPARAM)
  81. {
  82.     ASSERT(wParam != NULL);
  83.     CMfcDoc* pDoc = GetDocument();
  84.  
  85.     CPalette* pPal = pDoc->GetDocPalette();
  86.     if (pPal != NULL)
  87.     {
  88.         CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
  89.         ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
  90.  
  91.         CClientDC appDC(pAppFrame);
  92.         // All views but one should be a background palette.
  93.         // wParam contains a handle to the active view, so the SelectPalette
  94.         // bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
  95.         CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
  96.  
  97.         if (oldPalette != NULL)
  98.         {
  99.             UINT nColorsChanged = appDC.RealizePalette();
  100.             if (nColorsChanged > 0)
  101.                 pDoc->UpdateAllViews(NULL);
  102.             appDC.SelectPalette(oldPalette, TRUE);
  103.         }
  104.         else
  105.         {
  106.             TRACE0("\tSelectPalette failed in CMfcView::OnPaletteChanged\n");
  107.         }
  108.     }
  109.  
  110.     return 0L;
  111. }
  112.  
  113. void CMfcView::OnInitialUpdate()
  114. {
  115.     CScrollView::OnInitialUpdate();
  116.     ASSERT(GetDocument() != NULL);
  117.  
  118.     SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
  119. }
  120.  
  121.  
  122. void CMfcView::OnActivateView(BOOL bActivate, CView* pActivateView,
  123.                     CView* pDeactiveView)
  124. {
  125.     CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  126.  
  127.     if (bActivate)
  128.     {
  129.         ASSERT(pActivateView == this);
  130.         OnDoRealize((WPARAM)m_hWnd, 0);   // same as SendMessage(WM_DOREALIZE);
  131.     }
  132. }
  133.  
  134.