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

📄 childview.cpp

📁 一个SGIP网关的程序源码.vc代码
💻 CPP
字号:
// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "SGIPGateWay.h"
#include "ChildView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView *gpView;

CChildView::CChildView()
{
	gpView = NULL;
	::InitializeCriticalSection(&mLock);
}

CChildView::~CChildView()
{
	::DeleteCriticalSection(&mLock);
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::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 CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CWnd::OnPaint() for painting messages
}

void CChildView::ShowMessage( char *strMsg, COLORREF clrColor, BOOL blnNewLine )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(cf));
	long nTextLen = mRich.GetTextLength();
	
	if( blnNewLine )
	{
		if( mRich.GetLineCount() >= 500 )
		{
			mRich.SetSel(0, nTextLen);
			mRich.ReplaceSel(TEXT(""));
		}
		mRich.SetSel(nTextLen, nTextLen);
		mRich.ReplaceSel(TEXT("\n"));
	}
	cf.dwMask = CFM_COLOR;
	cf.crTextColor = clrColor;
	nTextLen = mRich.GetTextLength();
	mRich.SetSel(nTextLen, nTextLen);
	mRich.SetWordCharFormat( cf );
		
	mRich.ReplaceSel(TEXT(strMsg));
	//richEdit.LineScroll(1);
	::SendMessage(mRich.m_hWnd, EM_SCROLLCARET, 0, 0 ); 
}
#include "helpfunc.h"
void CChildView::ShowTimeMsg(char *strMsg, COLORREF clrColor)
{
	Lock();
	ShowMessage((char*)(LPCTSTR)CHelpFunc::GetTimeString(time(NULL)), RGB(200,200,200));
	CString msg;
	msg.Format(" %s", strMsg);
	ShowMessage((char*)(LPCTSTR)msg, clrColor, FALSE);
	Unlock();
}
void CChildView::ShowLockMsg(char *strMsg, COLORREF clrColor)
{
	Lock();
	ShowMessage(strMsg, clrColor);
	Unlock();
}
void CChildView::ShowMsgNoLine(char *strMsg, COLORREF clrColor)
{
	Lock();
	ShowMessage(strMsg, clrColor, FALSE);
	Unlock();
}
LRESULT CChildView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	//CWnd ::WindowProc(message, wParam, lParam);
	CRect rect;
	
	CHARFORMAT2 cf;

	switch( message )
	{
	case WM_CREATE:
		mRich.Create(WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_READONLY|ES_MULTILINE, CRect(0,0,100,100), this, 1);
		// 设置类型
		mRich.SetBackgroundColor(FALSE, RGB(0,0,0));
		mRich.GetDefaultCharFormat(cf);
		memset(&cf, 0, sizeof(cf));
		cf.cbSize = sizeof(cf);
		cf.dwMask = CFM_COLOR|CFM_CHARSET|CFM_SIZE|CFM_FACE|CFM_WEIGHT|CFM_SPACING|CFM_KERNING;
		cf.crTextColor = RGB(255,255,255);
		mRich.SetDefaultCharFormat( cf );
		cf.bCharSet = 134;
		cf.yHeight = 20*10;
		strcpy(cf.szFaceName, "新宋体");
		cf.wWeight = 400;
		cf.sSpacing = 40;
		cf.wKerning = 40;
		mRich.SetDefaultCharFormat(cf);
		gpView = this;

		ShowWindow(SW_NORMAL);
		UpdateWindow();

		return 0;
	case WM_SIZE:
		GetClientRect(&rect);
		mRich.MoveWindow(&rect);
		return 0;
	case WM_ERASEBKGND:
		return 0;
	}
	return DefWindowProc(message, wParam, lParam);
}

⌨️ 快捷键说明

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