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

📄 chapter5_1view.cpp

📁 用来显示文本特殊的方式
💻 CPP
字号:
// chapter5_1View.cpp : implementation of the CChapter5_1View class
//

#include "stdafx.h"
#include "chapter5_1.h"

#include "chapter5_1Doc.h"
#include "chapter5_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChapter5_1View

IMPLEMENT_DYNCREATE(CChapter5_1View, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CChapter5_1View construction/destruction

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

}

CChapter5_1View::~CChapter5_1View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CChapter5_1View drawing

void CChapter5_1View::OnDraw(CDC* pDC)
{
	CChapter5_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

/**********************************************************/
/*                用DrawText显示文本                      */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*	
	CString str;
	str=L"ABCDEFGHIJKLMOPQRSTUVWXYZ";
	CRect rect(10,100,200,200);
	pDC->DrawText(str,rect,DT_CENTER|DT_NOCLIP);
*/
/**********************************************************/
/*                用ExtTextOut显示文本                    */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*	
	CString str;
	str=L"ABCDEFGHIJKLMOPQRSTUVWXYZ";
	int nWidths[9]={10,20,30,40,50,60,70,80,90};
	CRect rect(10,100,200,200);
	pDC->ExtTextOut(10,120,ETO_CLIPPED,rect,str,nWidths);
*/	
/**********************************************************/
/*                设置文本颜色显示文本                    */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*
	CString str;
	str=L"ABCDEFGHIJKLMOPQRSTUVWXYZ";
	int nWidths[9]={10,20,30,40,50,60,70,80,90};
	CRect rect(10,100,200,200);
	
	COLORREF rColor,oColor;
	rColor=RGB(255,0,0);
	oColor=pDC->SetTextColor(rColor);
	pDC->ExtTextOut(100,120,ETO_CLIPPED,rect,str,nWidths);
*/
/**********************************************************/
/*                设置文本背景显示文本                    */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*
	CString str;
	str=L"ABCDEFGHIJKLMOPQRSTUVWXYZ";
	int nBkColor;
	int nWidths[9]={10,20,30,40,50,60,70,80,90};
	CRect rect(10,100,200,200);

	COLORREF rColor,oColor;
	rColor=RGB(255,0,0);
	oColor=pDC->SetTextColor(rColor);

	nBkColor=pDC->SetBkColor(OPAQUE);
	pDC->SetBkColor(RGB(0,0,255));
	pDC->ExtTextOut(100,120,ETO_CLIPPED,rect,str,nWidths);
	pDC->SetBkMode(nBkColor);
*/
/**********************************************************/
/*                显示自定义字体文本                      */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*
	CFont MyFont;
	CString str;
	str=L"ABCDEFGHIJKLMOPQRSTUVWXYZ";
	//int nBkColor;
	int nWidths[9]={50,50,50,50,50};
	pDC->SetTextColor(RGB(0,255,0));
	MyFont.CreateFont(100,
					30,
					10,
					45,
					FW_HEAVY,
					TRUE,
					TRUE,
					0,
					DEFAULT_CHARSET,
					OUT_DEFAULT_PRECIS,
					CLIP_DEFAULT_PRECIS,
					DRAFT_QUALITY,
					FIXED_PITCH|FF_SWISS,
					L"myfont");
	pDC->SelectObject(&MyFont);
	
	CRect rect(0,100,200,200);

	pDC->SetBkColor(RGB(0,0,255));
	pDC->ExtTextOut(0,120,ETO_CLIPPED,rect,str,nWidths);
	
*/
/**********************************************************/
/*                更新翻转背景颜色的文本                  */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*
//获得视大小
 CRect rcView;
 GetClientRect (rcView);
 //Create sample string to display.
 CString str (_T ("Awesome Shadow Text..."));
 //Set the background mode to transparent.
 pDC->SetBkMode(TRANSPARENT);

 //画黑色阴影文本
 rcView.OffsetRect (1, 1);
 pDC->SetTextColor (RGB (0, 0, 0));
 pDC->DrawText (str, str.GetLength (), rcView, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

 //画红色文本
 rcView.OffsetRect (-1,-1);
 pDC->SetTextColor (RGB (255, 0, 0));
 pDC->DrawText (str, str.GetLength (), rcView, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
 */


/**********************************************************/
/*                       显示旋转文本                     */
/*         看本例效果请将注释删除并编译后执行即可		  */
/**********************************************************/
/*
	//获得视大小
	CRect rcClient;
	GetClientRect (rcClient);
	
	
	//创建字符串
	CString str2(_T("Wheeee...I am rotating!"));
	
	//设置为TRANSPARENT模式,红色字体
	pDC->SetBkMode (TRANSPARENT);
	pDC->SetTextColor (RGB (255,0,0));
	
	//字体
	CFont font;
	LOGFONT stFont;
	
	//字体属性
	memset(&stFont, 0, sizeof (LOGFONT));
	
	stFont.lfWeight=FW_NORMAL;
	stFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	
	wchar_t str1[15];
	wsprintf( str1, _T("Arial"));
	
	wcscpy(stFont.lfFaceName, str1);
	
	//每15度画一次
	for (int nAngle=0; nAngle<3600;nAngle+=150)
	{
		//新的角度
		stFont.lfEscapement=nAngle;
		
		//创建和选中字体
		font.CreateFontIndirect(&stFont);
		CFont* pOldFont=pDC ->SelectObject(&font);
		
		//绘制文本
		pDC->DrawText (str2, str2.GetLength (), rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
		
		//恢复现场
		pDC->SelectObject(pOldFont);
		font.DeleteObject();
	}
*/


}

/////////////////////////////////////////////////////////////////////////////
// CChapter5_1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CChapter5_1View message handlers

⌨️ 快捷键说明

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