⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadview.cpp

📁 利用embedded c++开发的.bmp格式的图像数据的显示
💻 CPP
字号:
// LoadView.cpp : implementation of the CLoadView class
//

#include "stdafx.h"
#include "Load.h"

#include "LoadDoc.h"
#include "LoadView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoadView

IMPLEMENT_DYNCREATE(CLoadView, CView)

BEGIN_MESSAGE_MAP(CLoadView, CView)
	//{{AFX_MSG_MAP(CLoadView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoadView construction/destruction

CLoadView::CLoadView()
{
	// TODO: add construction code here

}

CLoadView::~CLoadView()
{
}

BOOL CLoadView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	Filename=_T("");
	
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLoadView drawing

void CLoadView::OnDraw(CDC* pDC)
{
	CLoadDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
	if(Filename!="")
	{
		CBitmap bitmap;
		
		bitmap.Attach(SHLoadImageFile(Filename));
		BITMAP bmpInfo;
		
		bitmap.GetBitmap(&bmpInfo);
		CDC bitmapDC;
		
		bitmapDC.CreateCompatibleDC(pDC);
		CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);
		
		pDC->BitBlt(0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,&bitmapDC,0,0,SRCCOPY);	
		bitmapDC.SelectObject(pOldBitmap);
		bitmap.DeleteObject();
	}
		
}

/////////////////////////////////////////////////////////////////////////////
// CLoadView diagnostics

#ifdef _DEBUG
void CLoadView::AssertValid() const
{
	CView::AssertValid();
}

void CLoadView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CLoadDoc* CLoadView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLoadDoc)));
	return (CLoadDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLoadView message handlers


void CLoadView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	//得到文档指针
	CLoadDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//是否已打开某个BMP文件
	if(pDoc->flag==1)
	{
		//指定是显示的颜色
		SetDIBitsToDevice(dc.m_hDC,0,0,pDoc->pbi->bmiHeader.biWidth,
			pDoc->pbi->bmiHeader.biHeight,0,0,0,
			pDoc->pbi->bmiHeader.biHeight,pDoc->lpshowbuf, 
			pDoc->pbi,DIB_RGB_COLORS);   
	}
	// Do not call CView::OnPaint() for painting messages
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -