www.pudn.com > TestBitmap.rar > TestBitmapView.cpp
// TestBitmapView.cpp : implementation of the CTestBitmapView class
//
#include "stdafx.h"
#include "TestBitmap.h"
#include "TestBitmapDoc.h"
#include "TestBitmapView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView
IMPLEMENT_DYNCREATE(CTestBitmapView, CView)
BEGIN_MESSAGE_MAP(CTestBitmapView, CView)
//{{AFX_MSG_MAP(CTestBitmapView)
ON_COMMAND(ID_DisplayBitmap, OnDisplayBitmap)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView construction/destruction
CTestBitmapView::CTestBitmapView()
{
// TODO: add construction code here
}
CTestBitmapView::~CTestBitmapView()
{
}
BOOL CTestBitmapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView drawing
void CTestBitmapView::OnDraw(CDC* pDC)
{
CTestBitmapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPoint size(m_Bm.bmWidth,m_Bm.bmHeight);
pDC->DPtoLP(&size);
CPoint org(0,0);
pDC->DPtoLP(&org);
pDC->BitBlt(0,0,size.x,size.y,
&m_DC, org.x, org.y,SRCCOPY);
/*RECT Rect;
Rect.left = Rect.top = 10;
Rect.right = Rect.bottom = 100;
CBrush Brush(RGB(255,0,0));
pDC->FillRect(&Rect,&Brush);
*/
}
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView printing
BOOL CTestBitmapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestBitmapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestBitmapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView diagnostics
#ifdef _DEBUG
void CTestBitmapView::AssertValid() const
{
CView::AssertValid();
}
void CTestBitmapView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestBitmapDoc* CTestBitmapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestBitmapDoc)));
return (CTestBitmapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestBitmapView message handlers
void CTestBitmapView::OnDisplayBitmap()
{
CString str;
CDC *pDC = this->GetDC();
m_DC.CreateCompatibleDC(pDC);
CFileDialog dlg(TRUE,"bmp","*.bmp");
if(dlg.DoModal()==IDOK)
{
str = dlg.GetPathName();
}
m_hNewBitmap = (HBITMAP) LoadImage(
AfxGetInstanceHandle(), // handle to instance
str, // name or identifier of the image (root is where project is)
IMAGE_BITMAP, // image types
0, // desired width
0, // desired height
LR_LOADFROMFILE);
GetObject( m_hNewBitmap , sizeof(BITMAP), &m_Bm );
VERIFY(m_hOldBitmap = (HBITMAP)SelectObject(m_DC, m_hNewBitmap ));
m_DC.SetMapMode(pDC->GetMapMode());
Invalidate();
}