www.gusucode.com > VC++三子棋游戏源码(类似五子棋)-源码程序 > VC++三子棋游戏源码(类似五子棋)-源码程序\code\richeditctrlex.cpp
//Download by http://www.NewXing.com // richeditctrlex.cpp : implementation file // #include "stdafx.h" #include "richeditctrlex.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRichEditCtrlEx CRichEditCtrlEx::CRichEditCtrlEx() { } CRichEditCtrlEx::~CRichEditCtrlEx() { } BEGIN_MESSAGE_MAP(CRichEditCtrlEx, CRichEditCtrl) //{{AFX_MSG_MAP(CRichEditCtrlEx) ON_WM_KILLFOCUS() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRichEditCtrlEx message handlers int CRichEditCtrlEx::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here this->SetScrollRange(SB_VERT, 0, 20000); return 0; } BOOL CRichEditCtrlEx::AppendText(LPCTSTR lpszText, COLORREF clrText) { ASSERT(lpszText); if(NULL == lpszText || 0 == strlen(lpszText)) { return FALSE; } SAFE_CHECKWND(this) { CHARFORMAT CharFormat; memset(&CharFormat,0,sizeof(CHARFORMAT)); CharFormat.cbSize=sizeof(CHARFORMAT); CharFormat.dwMask=CFM_COLOR; CharFormat.crTextColor=clrText; this->SetWordCharFormat(CharFormat); this->SetSel(-1,-1); this->ReplaceSel(lpszText, FALSE); this->LineScroll(2); } return TRUE; } BOOL CRichEditCtrlEx::AppendText(LPCTSTR lpszText, int nHeight, COLORREF clrText) { ASSERT(lpszText); if(NULL == lpszText || 0 == strlen(lpszText)) { return FALSE; } SAFE_CHECKWND(this) { CHARFORMAT CharFormat; memset(&CharFormat,0,sizeof(CHARFORMAT)); CharFormat.cbSize =sizeof(CHARFORMAT); CharFormat.dwMask =CFM_COLOR | CFM_SIZE; CharFormat.crTextColor =clrText; CharFormat.yHeight =nHeight; this->SetWordCharFormat(CharFormat); this->SetSel(-1,-1); this->ReplaceSel(lpszText, FALSE); } return TRUE; } void CRichEditCtrlEx::OnKillFocus(CWnd* pNewWnd) { CRichEditCtrl::OnKillFocus(pNewWnd); SAFE_CHECKWND(this) { this->SetSel(-1,-1); } }