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

📄 sendvw.cpp

📁 WinCE上的聊天程序
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// sendvw.cpp : implementation file
//
// This is a part of the Microsoft Foundation Classes C++ library.
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "chatter.h"

#include "chatdoc.h"
#include "sendvw.h"

#include <stdlib.h>

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

static CString RandomString();

/////////////////////////////////////////////////////////////////////////////
// CSendView

IMPLEMENT_DYNCREATE(CSendView, CEditView)

BEGIN_MESSAGE_MAP(CSendView, CEditView)
	//{{AFX_MSG_MAP(CSendView)
	ON_WM_CHAR()
	ON_WM_TIMER()
	ON_COMMAND(ID_AUTOCHATTER, OnAutochatter)
	ON_UPDATE_COMMAND_UI(ID_AUTOCHATTER, OnUpdateAutochatter)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSendView construction/destruction

CSendView::CSendView()
{
	m_TimerID = 0;
}

CSendView::~CSendView()
{
}


/////////////////////////////////////////////////////////////////////////////
// CSendView drawing

void CSendView::OnDraw(CDC* pDC)
{
}

/////////////////////////////////////////////////////////////////////////////
// CSendView diagnostics

#ifdef _DEBUG
void CSendView::AssertValid() const
{
	CEditView::AssertValid();
}

void CSendView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CChatDoc* CSendView::GetDocument() // non-debug version is inline
{
	return STATIC_DOWNCAST(CChatDoc, m_pDocument);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSendView message handlers

BOOL CSendView::PreCreateWindow(CREATESTRUCT& cs) 
{
	BOOL ret = CEditView::PreCreateWindow(cs);
	cs.style = AFX_WS_DEFAULT_VIEW | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL |
		ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL;
	return ret;
}

void CSendView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
#if (_WIN32_WCE == 211) && defined(_WIN32_WCE_PSPC)
	if ((nChar != VK_RETURN))
#else
	if ((nChar != VK_RETURN) || (nRepCnt!=1))
#endif
	{
		CEditView::OnChar(nChar, nRepCnt, nFlags);
		return;
	}
	else
	{
		CChatDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		CString strText;
		GetEditCtrl().GetWindowText(strText);

		pDoc->SendMsg(strText);

		strText=_T("");
		GetEditCtrl().SetWindowText(strText);
	}
}

BOOL CSendView::DestroyWindow() 
{
	if (m_TimerID != 0)
		KillTimer(m_TimerID);
		
	return CEditView::DestroyWindow();
}

void CSendView::OnTimer(UINT nIDEvent) 
{
	CChatDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	if (pDoc->m_bAutoChat)
	{
		CString temp = RandomString();

		if (!temp.IsEmpty())
			pDoc->SendMsg(temp);
	}
	else
	{
		KillTimer(m_TimerID);
		m_TimerID = 0;
	}
	
	CEditView::OnTimer(nIDEvent);
}

void CSendView::OnAutochatter() 
{
	CChatDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	if (!pDoc->m_bAutoChat)
	{
		pDoc->m_bAutoChat = TRUE;
		m_TimerID = SetTimer(1, 1000, NULL);
	}
	else
	{
		pDoc->m_bAutoChat = FALSE;
		KillTimer(m_TimerID);
	}
}

void CSendView::OnUpdateAutochatter(CCmdUI* pCmdUI) 
{		
	CChatDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	pCmdUI->SetCheck(pDoc->m_bAutoChat);
}

static CString RandomString()
{
	CString strResult;

	UINT val1 = (rand()%36) + IDS_STATEMENT01;
	UINT val2 = (rand()%6) + IDS_ADJECTIVE01;

	CString strStatement, strAdjective;

	if(!strStatement.LoadString(val1))
		return strResult;

	if(!strAdjective.LoadString(val2))
		return strResult;

	wsprintf(strResult.GetBuffer(strStatement.GetLength()+strAdjective.GetLength()),
		(LPCTSTR)strStatement,(LPCTSTR)strAdjective);
	strResult.ReleaseBuffer();

	return strResult;
}

⌨️ 快捷键说明

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