home *** CD-ROM | disk | FTP | other *** search
- // mfcview.cpp : implementation of the CMfcView class
- //
-
- #include "stdafx.h"
- #include "imview.h"
-
- #include "mfcdoc.h"
- #include "mfcview.h"
- #include "mainfrm.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcView
-
- IMPLEMENT_DYNCREATE(CMfcView, CScrollView)
-
- BEGIN_MESSAGE_MAP(CMfcView, CScrollView)
- //{{AFX_MSG_MAP(CMfcView)
- ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
- //}}AFX_MSG_MAP
-
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDibView construction/destruction
-
- CMfcView::CMfcView()
- {
- }
-
- CMfcView::~CMfcView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcView drawing
-
- void CMfcView::OnDraw(CDC* pDC)
- {
- CMfcDoc* pDoc = GetDocument();
- CPalette * OldPalette;
- CBitmap * OldBitmap;
- CDC * pMemoryDC;
- CBitmap* bitmap = pDoc->GetDocBitmap();
- CPalette* palette = pDoc->GetDocPalette();
- CSize Rsize;
-
- if (bitmap->GetSafeHandle() != NULL)
- {
- CRect rectddb;
- Rsize = pDoc->GetDocSize();
- rectddb.top = rectddb.left = 0;
- rectddb.right = Rsize.cx;
- rectddb.bottom = Rsize.cy;
- CRect rcDest;
- rcDest = rectddb;
- pMemoryDC = new CDC;
- pMemoryDC->CreateCompatibleDC(pDC);
-
- if (palette->GetSafeHandle() != NULL)
- OldPalette = pMemoryDC->SelectPalette(palette, 0);
-
- OldBitmap = (CBitmap *)pMemoryDC->SelectObject(bitmap);
-
- pDC->BitBlt(0, 0, rectddb.right, rectddb.bottom, pMemoryDC,
- 0, 0, SRCCOPY);
- pMemoryDC->SelectPalette(OldPalette, 0);
- pMemoryDC->SelectObject(OldBitmap);
- delete pMemoryDC;
- }
- }
-
- // CMfcView commands
-
-
- LRESULT CMfcView::OnDoRealize(WPARAM wParam, LPARAM)
- {
- ASSERT(wParam != NULL);
- CMfcDoc* pDoc = GetDocument();
-
- CPalette* pPal = pDoc->GetDocPalette();
- if (pPal != NULL)
- {
- CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
- ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
-
- CClientDC appDC(pAppFrame);
- // All views but one should be a background palette.
- // wParam contains a handle to the active view, so the SelectPalette
- // bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
- CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
-
- if (oldPalette != NULL)
- {
- UINT nColorsChanged = appDC.RealizePalette();
- if (nColorsChanged > 0)
- pDoc->UpdateAllViews(NULL);
- appDC.SelectPalette(oldPalette, TRUE);
- }
- else
- {
- TRACE0("\tSelectPalette failed in CMfcView::OnPaletteChanged\n");
- }
- }
-
- return 0L;
- }
-
- void CMfcView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- ASSERT(GetDocument() != NULL);
-
- SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
- }
-
-
- void CMfcView::OnActivateView(BOOL bActivate, CView* pActivateView,
- CView* pDeactiveView)
- {
- CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
-
- if (bActivate)
- {
- ASSERT(pActivateView == this);
- OnDoRealize((WPARAM)m_hWnd, 0); // same as SendMessage(WM_DOREALIZE);
- }
- }
-
-