📄 chatview.cpp
字号:
// ChatView.cpp : implementation of the CChatView class
//
#include "stdafx.h"
#include "Chat.h"
#include "ChatDoc.h"
#include "ChatView.h"
#include "Global.h"
#include "CreateFed.h"
#include "Communication_inter.h"
#include "PersonalSetting.h"
#include "Information.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFederate Fed;
extern RTI::RTIambassador RtiAmb;
/////////////////////////////////////////////////////////////////////////////
// CChatView
IMPLEMENT_DYNCREATE(CChatView, CFormView)
BEGIN_MESSAGE_MAP(CChatView, CFormView)
//{{AFX_MSG_MAP(CChatView)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_INFORMATION, OnInformation)
ON_COMMAND(ID_JOINFED, OnJoinfed)
ON_COMMAND(ID_RESIGNFED, OnResignfed)
ON_UPDATE_COMMAND_UI(ID_JOINFED, OnUpdateJoinfed)
ON_COMMAND(ID_SET, OnSet)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChatView construction/destruction
CChatView::CChatView()
: CFormView(CChatView::IDD)
{
//{{AFX_DATA_INIT(CChatView)
m_SpeakStr = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
SimFlag = false;
name = "";
age = "";
}
CChatView::~CChatView()
{
}
void CChatView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChatView)
DDX_Control(pDX, IDC_MESSAGELIST, m_MessageList);
DDX_Control(pDX, IDC_SEND, m_Send);
DDX_Control(pDX, IDC_INFORMATION, m_Information);
DDX_Text(pDX, IDC_SPEAKSTR, m_SpeakStr);
//}}AFX_DATA_MAP
}
BOOL CChatView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CChatView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CChatView printing
BOOL CChatView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChatView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChatView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CChatView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CChatView diagnostics
#ifdef _DEBUG
void CChatView::AssertValid() const
{
CFormView::AssertValid();
}
void CChatView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CChatDoc* CChatView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChatDoc)));
return (CChatDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChatView message handlers
void CChatView::OnSend()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_SpeakStr.IsEmpty())
MessageBox("发言内容不能为空!","注意");
else
{
//发送发言交互
Communication_inter inter;
inter.m_message = m_SpeakStr;
inter.m_name = Fed.m_FederateName;
inter.Send();
}
m_SpeakStr.Empty();
UpdateData(FALSE);
}
void CChatView::OnInformation()
{
// TODO: Add your control notification handler code here
CInformation InfDlg;
InfDlg.DoModal();
}
void CChatView::OnJoinfed()
{
// TODO: Add your command handler code here
CCreateFed dlg;
if(dlg.DoModal()==IDOK)
{
//读取成员名和联邦名
Fed.m_FederateName = dlg.m_FederateName;
Fed.m_FederationName = dlg.m_FederationName;
//启动仿真线程
AfxBeginThread(simulation,this);
SimFlag = true;
}
}
void CChatView::OnResignfed()
{
// TODO: Add your command handler code here
}
void CChatView::OnUpdateJoinfed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!SimFlag);
}
void CChatView::OnSet()
{
// TODO: Add your command handler code here
CPersonalSetting SetDlg;
//读取上次设置的姓名和年龄
SetDlg.m_name = name;
SetDlg.m_age = age;
if(SetDlg.DoModal()==IDOK)
{
//保存聊天者姓名和年龄
name = SetDlg.m_name;
age = SetDlg.m_age;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -