bitmapshowview.cpp
来自「MFC入门小程序源代码」· C++ 代码 · 共 118 行
CPP
118 行
// BitmapShowView.cpp : implementation of the CBitmapShowView class
//
#include "stdafx.h"
#include "BitmapShow.h"
#include "BitmapShowDoc.h"
#include "BitmapShowView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView
IMPLEMENT_DYNCREATE(CBitmapShowView, CView)
BEGIN_MESSAGE_MAP(CBitmapShowView, CView)
//{{AFX_MSG_MAP(CBitmapShowView)
// 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
// 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()
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView construction/destruction
CBitmapShowView::CBitmapShowView()
{
// TODO: add construction code here
}
CBitmapShowView::~CBitmapShowView()
{
}
BOOL CBitmapShowView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView drawing
void CBitmapShowView::OnDraw(CDC* pDC)
{
CBitmapShowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//added by yhm
CBitmap Bitmap;//创建CBitmap类的对象
Bitmap.LoadBitmap(IDB_BITMAP1);//调用CBitmap类的成员函数将位图载入内库
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap*poldBitmap=MemDC.SelectObject(&Bitmap);
BITMAP bm;//创建BITMAP结构变量
Bitmap.GetObject(sizeof(BITMAP),&bm);
pDC->BitBlt(130,0,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCCOPY);//显示位图
MemDC.SelectObject(poldBitmap);
//added by yhm
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView printing
BOOL CBitmapShowView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBitmapShowView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBitmapShowView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView diagnostics
#ifdef _DEBUG
void CBitmapShowView::AssertValid() const
{
CView::AssertValid();
}
void CBitmapShowView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBitmapShowDoc* CBitmapShowView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBitmapShowDoc)));
return (CBitmapShowDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBitmapShowView message handlers
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?