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

📄 bmptestview.cpp

📁 《VC++ 编程技巧与示例 .rar》各个示例代码绝对可用
💻 CPP
字号:
// BmpTestView.cpp : implementation of the CBmpTestView class
//

#include "stdafx.h"
#include "BmpTest.h"

#include "BmpTestDoc.h"
#include "BmpTestView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView

IMPLEMENT_DYNCREATE(CBmpTestView, CScrollView)

BEGIN_MESSAGE_MAP(CBmpTestView, CScrollView)
	//{{AFX_MSG_MAP(CBmpTestView)
	ON_COMMAND(ID_BT_BLACKNESS, OnBtBlackness)
	ON_COMMAND(ID_BT_DSTINVERT, OnBtDstinvert)
	ON_COMMAND(ID_BT_MERGECOPY, OnBtMergecopy)
	ON_COMMAND(ID_BT_MERGEPAINT, OnBtMergepaint)
	ON_COMMAND(ID_BT_NOTSRCCOPY, OnBtNotsrccopy)
	ON_COMMAND(ID_BT_NOTSRCERASE, OnBtNotsrcerase)
	ON_COMMAND(ID_BT_PATCOPY, OnBtPatcopy)
	ON_COMMAND(ID_BT_PATINVERT, OnBtPatinvert)
	ON_COMMAND(ID_BT_PATPAINT, OnBtPatpaint)
	ON_COMMAND(ID_BT_SRCAND, OnBtSrcand)
	ON_COMMAND(ID_BT_SRCCOPY, OnBtSrccopy)
	ON_COMMAND(ID_BT_SRCERASE, OnBtSrcerase)
	ON_COMMAND(ID_BT_SRCINVERT, OnBtSrcinvert)
	ON_COMMAND(ID_BT_SRCPAINT, OnBtSrcpaint)
	ON_COMMAND(ID_BT_WHITENESS, OnBtWhiteness)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView construction/destruction

CBmpTestView::CBmpTestView()
{
	// TODO: add construction code here
	m_Rop=SRCCOPY;
}

CBmpTestView::~CBmpTestView()
{
}

BOOL CBmpTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView drawing

void CBmpTestView::OnDraw(CDC* pDC)
{
	CBmpTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
//设置滚动视图大小,使之与Dib大小一致:
	CSize sizeTotal;
	sizeTotal.cx = pDoc->m_Dib.Width;
	sizeTotal.cy = pDoc->m_Dib.Height;
	SetScrollSizes(MM_TEXT, sizeTotal);

//在滚动视图中绘制背景:
	CBitmap pat;
	CBrush br,* obr;
	CRect rc;
	GetClientRect(&rc);
	pat.LoadBitmap(IDB_BITMAP2);
	br.CreatePatternBrush(&pat);
	obr=pDC->SelectObject(&br);
	pDC->FillRect(&rc,&br);
	pDC->SelectObject(obr);
	br.DeleteObject();

//绘制Dib:
	CRect dibrect;
	dibrect.top=0;
	dibrect.left=0;
	dibrect.right=sizeTotal.cx;
	dibrect.bottom=sizeTotal.cy;

	pDoc->m_Dib.Draw(pDC->GetSafeHdc(),dibrect,dibrect);

//绘制DDB:
	CBitmap ddb;
	ddb.LoadBitmap( IDB_BITMAP1 );
    // Calculate bitmap size using a BITMAP structure.
    BITMAP bm;
    ddb.GetObject( sizeof(BITMAP), &bm );
    // Create a memory DC, select the bitmap into the
    // memory DC, and BitBlt it into the view.
    CDC dcMem;
    dcMem.CreateCompatibleDC( pDC );
    CBitmap* pbmpOld = dcMem.SelectObject( &ddb );
    pDC->BitBlt( dibrect.Width()/2,dibrect.Height()/2,
				 dibrect.Width()/2+bm.bmWidth,dibrect.Height()/2+bm.bmHeight,
                 &dcMem,
				 0,0,
				 m_Rop 
				 );
    // Reselect the original bitmap into the memory DC.
    dcMem.SelectObject( pbmpOld );
}

void CBmpTestView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView printing

BOOL CBmpTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBmpTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CBmpTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView diagnostics

#ifdef _DEBUG
void CBmpTestView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CBmpTestView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CBmpTestView message handlers

void CBmpTestView::OnBtBlackness() 
{
	// TODO: Add your command handler code here
	m_Rop=BLACKNESS;
	Invalidate();
}

void CBmpTestView::OnBtDstinvert() 
{
	// TODO: Add your command handler code here
	m_Rop=DSTINVERT;
	Invalidate();
}

void CBmpTestView::OnBtMergecopy() 
{
	// TODO: Add your command handler code here
	m_Rop=MERGECOPY;
	Invalidate();
}

void CBmpTestView::OnBtMergepaint() 
{
	// TODO: Add your command handler code here
	m_Rop=MERGEPAINT;
	Invalidate();
}

void CBmpTestView::OnBtNotsrccopy() 
{
	// TODO: Add your command handler code here
	m_Rop=NOTSRCCOPY;
	Invalidate();
}

void CBmpTestView::OnBtNotsrcerase() 
{
	// TODO: Add your command handler code here
	m_Rop=NOTSRCERASE;
	Invalidate();
}

void CBmpTestView::OnBtPatcopy() 
{
	// TODO: Add your command handler code here
	m_Rop=PATCOPY;
	Invalidate();
}

void CBmpTestView::OnBtPatinvert() 
{
	// TODO: Add your command handler code here
	m_Rop=PATINVERT;
	Invalidate();
}

void CBmpTestView::OnBtPatpaint() 
{
	// TODO: Add your command handler code here
	m_Rop=PATPAINT;
	Invalidate();
}

void CBmpTestView::OnBtSrcand() 
{
	// TODO: Add your command handler code here
	m_Rop=SRCAND;
	Invalidate();
}

void CBmpTestView::OnBtSrccopy() 
{
	// TODO: Add your command handler code here
	m_Rop=SRCCOPY;
	Invalidate();
}

void CBmpTestView::OnBtSrcerase() 
{
	// TODO: Add your command handler code here
	m_Rop=SRCERASE;
	Invalidate();
}

void CBmpTestView::OnBtSrcinvert() 
{
	// TODO: Add your command handler code here
	m_Rop=SRCINVERT;
	Invalidate();
}

void CBmpTestView::OnBtSrcpaint() 
{
	// TODO: Add your command handler code here
	m_Rop=SRCPAINT;
	Invalidate();
}

void CBmpTestView::OnBtWhiteness() 
{
	// TODO: Add your command handler code here
	m_Rop=WHITENESS;
	Invalidate();
}

⌨️ 快捷键说明

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