www.pudn.com > phase_relation.rar > phase_relationView.cpp, change:2006-04-21,size:4382b


// phase_relationView.cpp : implementation of the CPhase_relationView class 
// 
 
#include "stdafx.h" 
#include "phase_relation.h" 
 
#include "phase_relationDoc.h" 
#include "phase_relationView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPhase_relationView 
 
IMPLEMENT_DYNCREATE(CPhase_relationView, CView) 
 
BEGIN_MESSAGE_MAP(CPhase_relationView, CView) 
	//{{AFX_MSG_MAP(CPhase_relationView) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPhase_relationView construction/destruction 
 
CPhase_relationView::CPhase_relationView() 
{ 
	// TODO: add construction code here 
 
} 
 
CPhase_relationView::~CPhase_relationView() 
{ 
} 
 
BOOL CPhase_relationView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPhase_relationView drawing 
 
void CPhase_relationView::OnDraw(CDC* pDC) 
{ 
	CPhase_relationDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
 
	CDib* pBitmap = pDoc->m_pBitmap; 
		HPALETTE hPalette; 
		HPALETTE hOldPalette; 
     
    if (pBitmap) 
    { 
        BYTE* pBitmapData = pBitmap->GetData(); 
        LPBITMAPINFO pBitmapInfo = pBitmap->GetInfo(); 
 
		//int widbits,heightbits; 
		int mapbitswidth=pBitmap->GetNumberOfColors()*pBitmap->GetHeight(); 
		 
        DWORD bitmapHeight = pBitmap->GetHeight(); 
        DWORD bitmapWidth = (mapbitswidth*8+31)/32*4; 
        hPalette=CreateBitmapPalette(pBitmap); 
		hOldPalette = 
				::SelectPalette(pDC->m_hDC, hPalette, FALSE); 
                ::RealizePalette(pDC->m_hDC); 
		 
 
	/*	if (pBitmap->GetRGB()) // Has a color table 
		{ 
           hPalette = 
				CreateBitmapPalette(pBitmap); 
           hOldPalette = 
				::SelectPalette(pDC->m_hDC, hPalette, FALSE); 
                ::RealizePalette(pDC->m_hDC); 
	*/ 
 
            StretchDIBits(pDC->m_hDC, 
                200, 100, bitmapWidth, bitmapHeight, 
                0, 0, bitmapWidth, bitmapHeight, 
				pBitmapData, pBitmapInfo, 
				DIB_RGB_COLORS, SRCCOPY); 
 
            ::SelectPalette(pDC->m_hDC, pDoc->hOldPalette, FALSE); 
            ::DeleteObject(pDoc->hPalette); 
	/*	} 
		else 
            StretchDIBits(pDC->m_hDC, 
                200, 200, bitmapWidth, bitmapHeight, 
                0, 0, bitmapWidth, bitmapHeight, 
				pBitmapData, pBitmapInfo, 
				DIB_RGB_COLORS, SRCCOPY); 
 */ 
} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPhase_relationView diagnostics 
 
#ifdef _DEBUG 
void CPhase_relationView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CPhase_relationView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CPhase_relationDoc* CPhase_relationView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPhase_relationDoc))); 
	return (CPhase_relationDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CPhase_relationView message handlers 
 
HPALETTE CPhase_relationView::CreateBitmapPalette(CDib *pBitmap) 
{ 
 
	struct 
    { 
        WORD Version; 
        WORD NumberOfEntries; 
        PALETTEENTRY aEntries[256]; 
    } palette = { 0x300, 256 }; 
     
    LPRGBQUAD pRGBTable = pBitmap->GetRGB(); 
    UINT numberOfColors = pBitmap->GetNumberOfColors(); 
 
    for(UINT x=0; x<numberOfColors; ++x) 
    { 
        palette.aEntries[x].peRed = 
            pRGBTable[x].rgbRed; 
        palette.aEntries[x].peGreen = 
            pRGBTable[x].rgbGreen; 
        palette.aEntries[x].peBlue = 
            pRGBTable[x].rgbBlue; 
		 
        /*palette.aEntries[x].peRed =palette.aEntries[x].peGreen= 
			palette.aEntries[x].peBlue=pRGBTable[x].rgbRed; 
		*/ 
        palette.aEntries[x].peFlags = 0; 
    } 
 
     HPALETTE hPalette = 
         ::CreatePalette((LPLOGPALETTE)&palette); 
  
     return hPalette; 
}