📄 chatview.cpp
字号:
// ChatView.cpp : implementation file
//
#include "stdafx.h"
#include "ChatServer.h"
#include "ChatView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChatView
IMPLEMENT_DYNCREATE(CChatView, CView)
CChatView::CChatView()
{
}
CChatView::~CChatView()
{
}
BEGIN_MESSAGE_MAP(CChatView, CView)
//{{AFX_MSG_MAP(CChatView)
ON_WM_CHAR()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChatView drawing
void CChatView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CChatView diagnostics
#ifdef _DEBUG
void CChatView::AssertValid() const
{
CView::AssertValid();
}
void CChatView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChatView message handlers
void CChatView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CRect rect;
GetClientRect(&rect);
AfxInitRichEdit();
static const TCHAR szClassRE[] = TEXT(RICHEDIT_CLASS);
// m_EditBox.Create(WS_VISIBLE |
// WS_BORDER |
// WS_CHILD |
// ES_MULTILINE |
// WS_VSCROLL,
// rect, this , 0);
m_EditBox.CreateEx(WS_EX_OVERLAPPEDWINDOW,
szClassRE,
"",
WS_CHILD |
WS_VISIBLE |
ES_MULTILINE |
WS_BORDER |
ES_AUTOHSCROLL |
ES_AUTOVSCROLL |
WS_HSCROLL |
WS_HSCROLL,
rect.left,rect.top,rect.right,rect.bottom,
this->m_hWnd,
0,
NULL);
SetEditCtrlFormat();
// LOGFONT lf; // Used to create the CFont.
// memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
// lf.lfHeight = 16; // Request a 20-pixel-high font
// strcpy(lf.lfFaceName, "Verdana"); // with face name "Arial".
// m_font.CreateFontIndirect(&lf); // Create the font.
// m_EditBox.SetFont(&m_font);
}
void CChatView::message(LPCTSTR lpszMessage, CHARFORMAT cf )
{
CString strTemp = lpszMessage;
strTemp += _T("\r\n");
int len = m_EditBox.GetWindowTextLength();
m_EditBox.SetSel(len,len);
m_EditBox.SetSelectionCharFormat(cf);
m_EditBox.ReplaceSel(strTemp);
}
void CChatView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CChatView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(m_EditBox.GetSafeHwnd())
m_EditBox.MoveWindow(0 , 0 , cx , cy , FALSE);
}
void CChatView::SetEditCtrlFormat()
{
CHARFORMAT2 cf;
cf.cbSize = sizeof(CHARFORMAT2);
cf.dwMask =
CFM_BOLD|
// CFM_ITALIC|
// CFM_UNDERLINE|
// CFM_STRIKEOUT|
CFM_SIZE|
CFM_COLOR;
// CFM_OFFSET|
// CFM_PROTECTED;
cf.dwEffects = CFE_AUTOCOLOR | FW_NORMAL;
cf.yHeight = 200; //10pt
cf.wWeight = FW_NORMAL;
cf.yOffset = 0;
cf.crTextColor = RGB(0, 0, 0);
cf.bCharSet = 0;
cf.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
strcpy(cf.szFaceName, "Arial");
cf.dwMask |= CFM_FACE;
m_EditBox.SetDefaultCharFormat(cf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -