NetMeetingClientDlg.cpp
上传用户:kelland5
上传日期:2016-01-23
资源大小:52k
文件大小:5k
源码类别:
Telnet客户端
开发平台:
Visual C++
- //文件名: NetMeetingClientDlg.cpp : CNetMeetingClientDlg 类的实现文件
- #include "stdafx.h"
- #include "NetMeetingClient.h"
- #include "NetMeetingClientDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CNetMeetingClientDlg 对话框
- CNetMeetingClientDlg::CNetMeetingClientDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CNetMeetingClientDlg::IDD, pParent)
- , m_bAutoMeeting(FALSE)
- , m_EName(_T(""))
- , m_pFile(NULL)
- , m_pSocket(NULL)
- , m_pArchiveIn(NULL)
- , m_pArchiveOut(NULL)
- , m_strMeetingCode(_T(""))
- , m_strEServerName(_T(""))
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CNetMeetingClientDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LISTCONTENT, m_ListContent);
- DDX_Control(pDX, IDC_ECONTENT, m_EContent);
- DDX_Text(pDX, IDC_EMEETINGCODE, m_strMeetingCode);
- DDX_Text(pDX, IDC_ESERVERNAME, m_strEServerName);
- DDX_Text(pDX,IDC_ENAME,m_EName);
- }
- BEGIN_MESSAGE_MAP(CNetMeetingClientDlg, CDialog)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BTNABOUT, OnBnClickedBtnabout)
- ON_BN_CLICKED(IDC_BTNCONNECT, OnBnClickedBtnconnect)
- ON_BN_CLICKED(IDC_BTNSENDMINE, OnBnClickedBtnsendmine)
- ON_BN_CLICKED(IDC_BTNCLOSE, OnBnClickedBtnclose)
- END_MESSAGE_MAP()
- // CNetMeetingClientDlg 消息处理程序
- BOOL CNetMeetingClientDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_strMeetingCode="700";
- DWORD iSize=256;
- char ComName[256+1];
- memset(ComName,0,sizeof(ComName));
- GetComputerName(ComName,&iSize);
- m_strEServerName.Format("%s",ComName);
- UpdateData(FALSE);
- return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
- }
- void CNetMeetingClientDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- HCURSOR CNetMeetingClientDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CNetMeetingClientDlg::OnOK(void)
- {
- TRACE("Entering CNetMeetingClientDlg::OnOK()n");
- }
- void CNetMeetingClientDlg::OnCancel(void)
- {
- TRACE("Entering CNetMeetingClientDlg::OnCancel()n");
- }
- //发送消息
- void CNetMeetingClientDlg::SendMsg(CString& str)
- {
- if (m_pArchiveOut != NULL)
- {
- CMsg msg;
- msg.m_strText = m_EName + _T(": ") + str;
- msg.Serialize(*m_pArchiveOut);
- m_pArchiveOut->Flush();
- }
- }
- //获取消息
- void CNetMeetingClientDlg::ReceiveMsg(void)
- {
- CMsg msg;
- msg.Serialize(*m_pArchiveIn);
- while(!msg.m_MsgList.IsEmpty())
- {
- CString temp = msg.m_MsgList.RemoveHead();
- //DisplayMsg(temp);
- m_ListContent.AddString(temp);
- SetDlgItemText(IDC_STEXT,temp);
- }
- m_ListContent.SetCurSel(m_ListContent.GetCount()-1);
- if (msg.m_bClose)
- {
- delete m_pArchiveIn;
- m_pArchiveIn = NULL;
- delete m_pArchiveOut;
- m_pArchiveOut = NULL;
- delete m_pFile;
- m_pFile = NULL;
- delete m_pSocket;
- m_pSocket = NULL;
- }
- }
- //接收信息
- void CNetMeetingClientDlg::ProcessPendingRead(void)
- {
- do
- {
- ReceiveMsg();
- if (m_pSocket == NULL)
- return;
- }
- while(!m_pArchiveIn->IsBufferEmpty());
- }
- void CNetMeetingClientDlg::OnBnClickedBtnabout()
- {
- CString str="1.本程序使用前应该设置服务器网络会议室编号,并且与本程序的网络会议室编号一致.n2.罗斌于2004年1月编写!";
- MessageBox(str,"信息提示",MB_OK);
- }
- //连接服务器
- void CNetMeetingClientDlg::OnBnClickedBtnconnect()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(TRUE);
- m_pSocket = new CNetMeetingSocket(this);
- if (!m_pSocket->Create())
- {
- delete m_pSocket;
- m_pSocket = NULL;
- MessageBox("创建连接失败","信息提示",MB_OK);
- return ;
- }
- if (!m_pSocket->Connect(m_strEServerName,atol(m_strMeetingCode)))
- {
- MessageBox("没有连接成功","信息提示",MB_OK);
- delete m_pSocket;
- m_pSocket = NULL;
- return ;
- }
- m_pFile = new CSocketFile(m_pSocket);
- m_pArchiveIn = new CArchive(m_pFile,CArchive::load);
- m_pArchiveOut = new CArchive(m_pFile,CArchive::store);
- CString str="进入会议室";
- SendMsg(str);
- }
- //向服务器发送消息
- void CNetMeetingClientDlg::OnBnClickedBtnsendmine()
- {
- if(m_pSocket==NULL)
- {
- MessageBox("您还没有进入会议室!","信息提示",MB_OK);
- return;
- }
- char Temp[1001]="";
- m_EContent.GetWindowText(Temp,999);
- CString str="";
- str.Format("%s",Temp);
- SendMsg(str);
- m_EContent.SetWindowText("");
- }
- //关闭程序
- void CNetMeetingClientDlg::OnBnClickedBtnclose()
- {
- m_bAutoMeeting = FALSE;
- if ((m_pSocket != NULL) && (m_pFile != NULL) && (m_pArchiveOut != NULL))
- {
- CMsg msg;
- CString strTemp="离开会议室";
- msg.m_bClose = TRUE;
- msg.m_strText =m_EName + strTemp;
- msg.Serialize(*m_pArchiveOut);
- m_pArchiveOut->Flush();
- }
- delete m_pArchiveOut;
- m_pArchiveOut = NULL;
- delete m_pArchiveIn;
- m_pArchiveIn = NULL;
- delete m_pFile;
- m_pFile = NULL;
- if (m_pSocket != NULL)
- {
- BYTE Buffer[50];
- m_pSocket->ShutDown();
- while(m_pSocket->Receive(Buffer,50) > 0);
- }
- delete m_pSocket;
- m_pSocket = NULL;
- TRACE("Entering CNetMeetingClientDlg::OnOK()n");
- CDialog::OnOK();
- }