📄 sendvw.cpp
字号:
// sendvw.cpp : implementation file
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1997 Microsoft Corporation
// 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, CFormView)
BEGIN_MESSAGE_MAP(CSendView, CFormView)
//{{AFX_MSG_MAP(CSendView)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_CBN_SELCHANGE(IDC_TO, OnSelchangeTo)
ON_WM_ERASEBKGND()
ON_BN_CLICKED(IDC_CLR, OnClr)
ON_BN_CLICKED(IDC_GUOLU, OnGuolu)
ON_WM_CHAR()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSendView construction/destruction
void CSendView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendView)
DDX_Control(pDX, IDC_GUOLU, m_guolu);
DDX_Control(pDX, IDC_TYPE, m_typecom);
DDX_Control(pDX, IDC_TO, m_list);
DDX_CBString(pDX, IDC_TO, to);
DDX_Check(pDX, IDC_SEC, sec);
DDX_Text(pDX, IDC_TEXT, say);
DDX_CBString(pDX, IDC_TYPE, m_type);
//}}AFX_DATA_MAP
}
CSendView::CSendView()
: CFormView(CSendView::IDD)
{
//{{AFX_DATA_INIT(CSendView)
sec = FALSE;
say = _T("");
m_type = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_TimerID = 0;
mHollowBrush.CreateStockObject(HOLLOW_BRUSH);
}
CSendView::~CSendView()
{
}
/////////////////////////////////////////////////////////////////////////////
// CSendView drawing
void CSendView::OnDraw(CDC* pDC)
{
}
/////////////////////////////////////////////////////////////////////////////
// CSendView diagnostics
#ifdef _DEBUG
void CSendView::AssertValid() const
{
CFormView::AssertValid();
}
void CSendView::Dump(CDumpContext& dc) const
{
CFormView::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 = CFormView::PreCreateWindow(cs);
cs.style = AFX_WS_DEFAULT_VIEW | WS_VSCROLL | ES_AUTOHSCROLL |
ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL;
return ret;
}
/*void CSendView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ((nChar != VK_RETURN) || (nRepCnt!=1))
{
CFormView::OnChar(nChar, nRepCnt, nFlags);
return;
}
else
{
CChatDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strText;
GetDlgItem(IDC_TEXT)->GetWindowText(strText);
pDoc->SendMsg(strText);
strText=_T("");
GetDlgItem(IDC_TEXT)->SetWindowText(strText);
}
}
*/
BOOL CSendView::DestroyWindow()
{
return CFormView::DestroyWindow();
}
void CSendView::OnSend()
{
// TODO: Add your control notification handler code here
CChatDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strText;
GetDlgItem(IDC_TEXT)->GetWindowText(strText);
UpdateData(TRUE);
if(strText=="") return;
CString ll;
int j=m_typecom.GetCurSel();
if(j>=0)
ll.Format("%d",j);
pDoc->msg.type=ll;
pDoc->msg.from=pDoc->m_strHandle;
pDoc->msg.to=to;
if(sec)
pDoc->msg.sec="TRUE";
else
pDoc->msg.sec="FALSE";
pDoc->msg.m_strText=strText;
BYTE i1=GetRValue(pDoc->clr);
BYTE i2=GetGValue(pDoc->clr);
BYTE i3=GetBValue(pDoc->clr);
(pDoc->msg.clr).Format("%d,%d,%d",i1,i2,i3);
pDoc->SendMsg();
strText=_T("");
GetDlgItem(IDC_TEXT)->SetWindowText(strText);
}
void CSendView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ball.Create(this);
ball.SetBkColor(RGB(255,255,255));
ball.AddTool(GetDlgItem(IDC_SEC),"发送信息只有你和对方知道",RGB(0,0,0));
ball.AddTool(GetDlgItem(IDC_GUOLU),"只接收发给自己的信息",RGB(0,0,0));
ball.AddTool(GetDlgItem(IDC_TO),"请选择聊天的对象",RGB(0,0,0));
ball.AddTool(GetDlgItem(IDC_TYPE),"请选择动作",RGB(0,0,0));
ball.AddTool(GetDlgItem(IDC_CLR),"请选择发送信息的字体颜色",RGB(0,0,0));
// TODO: Add your specialized code here and/or call the base class
m_list.ResetContent();
m_list.AddString("所有人");
to="所有人";
m_list.SelectString(-1,to);
m_typecom.ResetContent();
CString temp;
for(int i=0;i<=32;i++)
{
temp.LoadString(IDS_S0+i);
m_typecom.AddString(temp);
}
m_typecom.SetCurSel(0);
}
void CSendView::OnSelchangeTo()
{
// TODO: Add your control notification handler code here
m_list.GetLBText(m_list.GetCurSel(),to);
UpdateData(FALSE);
}
BOOL CSendView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// CBrush back(RGB(239,245,254));
CBrush back(RGB(220,215,254));
CBrush* pold=pDC->SelectObject(&back);
CRect rect;
pDC->GetClipBox (&rect);
pDC->PatBlt (rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
pDC->SelectObject(pold);
// return CFormView::OnEraseBkgnd(pDC);
return TRUE;
}
void CSendView::OnClr()
{
// TODO: Add your control notification handler code here
CChatDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CColorDialog clr(pDoc->clr,0,NULL);
if(clr.DoModal()==IDOK)
{
if(clr.GetColor() ==RGB(255,255,255))
AfxMessageBox("不能把字体设为白色!");
else
pDoc->clr=clr.GetColor();
}
}
void CSendView::OnGuolu()
{
// TODO: Add your control notification handler code here
if(m_guolu.GetCheck()==1)
GetDocument()->m_guolu=true;
else
GetDocument()->m_guolu=false;
}
BOOL CSendView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(ball)
ball.RelayEvent(pMsg);
return CFormView::PreTranslateMessage(pMsg);
}
HBRUSH CSendView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
switch(nCtlColor)
{
case CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)mHollowBrush.m_hObject;
break;
default:
HBRUSH hbr =CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -