chatserverview.cpp
来自「基于winsock的聊天程序」· C++ 代码 · 共 118 行
CPP
118 行
// ChatServerView.cpp : implementation of the CChatServerView class
//
#include "stdafx.h"
#include "ChatServer.h"
#include "ChatServerDoc.h"
#include "CntrItem.h"
#include "ChatServerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChatServerView
IMPLEMENT_DYNCREATE(CChatServerView, CRichEditView)
BEGIN_MESSAGE_MAP(CChatServerView, CRichEditView)
//{{AFX_MSG_MAP(CChatServerView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChatServerView construction/destruction
CChatServerView::CChatServerView()
{
// TODO: add construction code here
}
CChatServerView::~CChatServerView()
{
}
BOOL CChatServerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRichEditView::PreCreateWindow(cs);
}
void CChatServerView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
//初始RichEditView的文字显示格式
cfm.cbSize=sizeof(cfm);
cfm.bCharSet=GB2312_CHARSET;
cfm.crTextColor=RGB(0,0,0);
cfm.dwMask=CFM_CHARSET | CFM_COLOR ;
cfm.dwEffects=0;
GetRichEditCtrl().SetDefaultCharFormat(cfm);
// Set the printing margins (720 twips = 1/2 inch).
SetMargins(CRect(720, 720, 720, 720));
}
void CChatServerView::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
CRichEditView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CChatServerView diagnostics
#ifdef _DEBUG
void CChatServerView::AssertValid() const
{
CRichEditView::AssertValid();
}
void CChatServerView::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
CChatServerDoc* CChatServerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChatServerDoc)));
return (CChatServerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChatServerView message handlers
void CChatServerView::Message(LPCTSTR lpszMessage,COLORREF clr)
{
//在窗口中显示聊天信息
cfm.cbSize=sizeof(cfm);
cfm.crTextColor=clr;
cfm.dwMask=CFM_COLOR;
CString strTemp = lpszMessage;
int len = GetWindowTextLength();
GetRichEditCtrl().SetSel(len,len);
GetRichEditCtrl().SetSelectionCharFormat(cfm);
GetRichEditCtrl().ReplaceSel(strTemp);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?