textview.cpp

来自「《Visual C++.NET MFC类库应用详解》程序实例」· C++ 代码 · 共 71 行

CPP
71
字号
// TextView.cpp : implementation of the CTextView class
//

#include "stdafx.h"
#include "MThread.h"
#include "TextView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CTextView

CTextView::CTextView()
{
	m_ColorText=RGB(0,0,0);
}

CTextView::~CTextView()
{
}


BEGIN_MESSAGE_MAP(CTextView,CWnd )
	ON_WM_PAINT()
	ON_COMMAND(ID_VIEW_COLOR, OnViewColor)
END_MESSAGE_MAP()


// CTextView message handlers

BOOL CTextView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CTextView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect rect;
	dc.SetTextColor(m_ColorText);
	dc.SetBkColor(::GetSysColor(COLOR_WINDOW));
	GetClientRect(rect);
	dc.DrawText(_T("Hello, World!"),-1,rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
	
	// Do not call CWnd::OnPaint() for painting messages
}


void CTextView::OnViewColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlgColor(m_ColorText);
	if(dlgColor.DoModal()==IDOK)
	{
		m_ColorText=dlgColor.GetColor();
		Invalidate();
	}	
}

⌨️ 快捷键说明

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