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

📄 viewmodeview.cpp

📁 最新visualC++编程200例书籍源码包括对数据库的操作
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////////////
//类名:CViewModeView
//功能:视图操作类
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.8.1
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ViewMode.h"

#include "ViewModeDoc.h"
#include "ViewModeView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CViewModeView

IMPLEMENT_DYNCREATE(CViewModeView, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CViewModeView construction/destruction

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

}

CViewModeView::~CViewModeView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CViewModeView drawing
// ---------------------------------------------------------------------------
// 涵数名:OnDraw
// 功能:  填充背景色及绘制3D文字LOGO
// 作者:  徐景周(jingzhou xu)
// 组织:  未来工作室(Future Studio)
// ---------------------------------------------------------------------------
void CViewModeView::OnDraw(CDC* pDC)
{
	CViewModeDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//新建图件时,填充默认底色
	CRect rcClient;
	pDC->GetClipBox(rcClient);			//获取需刷新的逻辑坐标区域
	rcClient.NormalizeRect();
	if (rcClient.IsRectEmpty())			//不需刷新时直接返回
		return;

	//绘制客户区的底色
	CBrush	brush;
	brush.CreateSolidBrush(0x808080);
	pDC->FillRect(rcClient, &brush);
	brush.DeleteObject();

	//绘制3D文字Logo
	CFont m_LogoFont;
	CString sLogoString;
		
	m_LogoFont.CreateFont(36, 0, 0, 0, FW_BOLD, 1, FALSE, FALSE,
			DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			FIXED_PITCH | FF_ROMAN, "楷体_GB2312");
		
	sLogoString = "2003";
		
	RECT rect,m_rDataBox;
	GetClientRect(&rect);
	CopyRect(&m_rDataBox,&rect);
		
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	CFont* oldFont = pDC->SelectObject(&m_LogoFont);
	CSize sz = pDC->GetTextExtent(sLogoString, sLogoString.GetLength());
	// 用GetTextExtent来计算字体logo大小,依靠于设备环境,使用logo位于右下角
	m_rDataBox.left = m_rDataBox.right  - sz.cx - tm.tmAveCharWidth/2;
	m_rDataBox.top  = m_rDataBox.bottom - sz.cy - tm.tmHeight/5;
	pDC->SetBkMode(TRANSPARENT);
	// 用3D字体显示,先黑后白,最后再用默认色
	COLORREF oldColor = pDC->SetTextColor(RGB(0,0,0));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
	m_rDataBox.left -= 3*tm.tmAveCharWidth/5;
	pDC->SetTextColor(RGB(255,255,255));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
	m_rDataBox.left += tm.tmAveCharWidth/5;
	pDC->SetTextColor(GetSysColor(COLOR_BTNFACE));
	pDC->DrawText(sLogoString, sLogoString.GetLength(), &m_rDataBox, DT_VCENTER | DT_SINGLELINE | DT_CENTER);
		
	//释放资源
	pDC->SelectObject(oldFont);
	pDC->SetTextColor(oldColor);   
	m_LogoFont.DeleteObject();
}

/////////////////////////////////////////////////////////////////////////////
// CViewModeView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CViewModeView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CViewModeView message handlers
// ---------------------------------------------------------------------------
// 涵数名:OnEraseBkgnd
// 功能:  绘制3D文字LOGO
// 作者:  徐景周(jingzhou xu)
// 组织:  未来工作室(Future Studio)
// ---------------------------------------------------------------------------
BOOL CViewModeView::OnEraseBkgnd(CDC* pDC) 
{
	
	return CView::OnEraseBkgnd(pDC);
}

⌨️ 快捷键说明

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