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

📄 mytoolbarview.cpp

📁 一系列的c++例子 一步一步由浅入深 有 聊天室
💻 CPP
字号:
// MyToolBarView.cpp : implementation of the CMyToolBarView class
//

#include "stdafx.h"
#include "MyToolBar.h"

#include "MyToolBarDoc.h"
#include "MyToolBarView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView

IMPLEMENT_DYNCREATE(CMyToolBarView, CView)

BEGIN_MESSAGE_MAP(CMyToolBarView, CView)
	//{{AFX_MSG_MAP(CMyToolBarView)
	ON_COMMAND(ID_WORDSTYLE_BOLD, OnWordstyleBold)
	ON_COMMAND(ID_WORDSTYLE_ITALY, OnWordstyleItaly)
	ON_COMMAND(ID_WORDSTYLE_UNDERLINE, OnWordstyleUnderline)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView construction/destruction

CMyToolBarView::CMyToolBarView()
{
	// TODO: add construction code here
    m_bold=false;
	m_italy=false;
	m_underline=false;
}

CMyToolBarView::~CMyToolBarView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView drawing

void CMyToolBarView::OnDraw(CDC* pDC)
{
	CMyToolBarDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	Newdraw(pDC);
}

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyToolBarView message handlers

void CMyToolBarView::OnWordstyleBold() 
{
	// TODO: Add your command handler code here
	m_bold=!m_bold;
	CDC*pDC=GetDC();
	Newdraw(pDC);
}

void CMyToolBarView::OnWordstyleItaly() 
{
	// TODO: Add your command handler code here
	m_italy=!m_italy;
	CDC*pDC=GetDC();
	Newdraw(pDC);
}

void CMyToolBarView::OnWordstyleUnderline() 
{
	// TODO: Add your command handler code here
	m_underline=!m_underline;
	CDC*pDC=GetDC();
	Newdraw(pDC);
}

void CMyToolBarView::Newdraw(CDC *pDC)
{
    CRect rect;
	GetClientRect(&rect);
	CBrush*pOldBrush=(CBrush*)pDC->SelectStockObject(WHITE_BRUSH);
	pDC->Rectangle(rect);
    pDC->SelectObject(pOldBrush);
	CFont*pOldFont;
	CFont*pNewFont=new CFont;
	pNewFont->CreateFont(60,0,0,0,
		                  (m_bold==true? FW_BOLD:FW_NORMAL),
		                  m_italy,m_underline,0,
						  ANSI_CHARSET,OUT_DEFAULT_PRECIS,
						  CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
						  DEFAULT_PITCH&FF_SWISS,
						  "Aerial");
	pOldFont=(CFont*)pDC->SelectObject(pNewFont);
	pDC->TextOut(190,190,"欢迎使用工具栏!");
    pDC->SelectObject(pOldFont);
	delete pNewFont;
	return;
}

⌨️ 快捷键说明

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