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

📄 gdidemoview.cpp

📁 vc++程序设计与技巧中第8章“图形图像编程”部分的VC++原代码
💻 CPP
字号:
// GDIDemoView.cpp : implementation of the CGDIDemoView class
//

#include "stdafx.h"
#include "GDIDemo.h"

#include "GDIDemoDoc.h"
#include "GDIDemoView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView

IMPLEMENT_DYNCREATE(CGDIDemoView, CView)

BEGIN_MESSAGE_MAP(CGDIDemoView, CView)
	//{{AFX_MSG_MAP(CGDIDemoView)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView construction/destruction

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

}

CGDIDemoView::~CGDIDemoView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView drawing

void CGDIDemoView::OnDraw(CDC* pDC)
{
	CGDIDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	//调用CDC:: SelectStockObject访问库存的GDI对象
	//将库存对象选进设备环境中 
	pDC->SelectStockObject (BLACK_PEN); 
	pDC->SelectStockObject (GRAY_BRUSH); 
	//绘制矩形 
	pDC->Rectangle(50,20,130,220);

	//调用新的SDK函数GetSysColorBrush访问系统的GDI对象
	//使用颜色为背景色的系统GDI对象 
	CBrush * pOrgBrush=pDC->SelectObject ( 
	CBrush::FromHandle (::GetSysColorBrush (COLOR_INFOBK))); 
	//绘制矩形 
	pDC->Rectangle(160,20,240,220);
	pDC->SelectObject (pOrgBrush);

	//使用CGdiObject类的派生类创建GDI对象并访问
	//创建GDI对象
	CBrush NewBrush1((COLORREF)0x0000FF00);
	CBrush *pOldBrush1 = pDC->SelectObject(&NewBrush1);
	//绘制矩形
	pDC->Rectangle(270,20,350,220);
	pDC->SelectObject(pOldBrush1);

	CBrush NewBrush2(HS_BDIAGONAL,(COLORREF)0x000000FF);
	CBrush *pOldBrush2 = pDC->SelectObject(&NewBrush2);
	pDC->Rectangle(380,20,460,220);
	pDC->SelectObject(pOldBrush2);

}

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGDIDemoView message handlers

⌨️ 快捷键说明

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