Talk.cpp
资源名称:(vc).rar [点击查看]
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:4k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // Talk.cpp : implementation file
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "Talk.h"
- #include "thread1.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTalk
- IMPLEMENT_DYNCREATE(CTalk, CFormView)
- CTalk::CTalk()
- : CFormView(CTalk::IDD)
- {
- //{{AFX_DATA_INIT(CTalk)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CTalk::~CTalk()
- {
- }
- void CTalk::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTalk)
- DDX_Control(pDX, IDC_SEND, m_send);
- DDX_Control(pDX, IDC_RECV, m_recv);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CTalk, CFormView)
- //{{AFX_MSG_MAP(CTalk)
- ON_WM_SIZE()
- ON_COMMAND(ID_CHAT_CONNECT, OnChatConnect)
- ON_UPDATE_COMMAND_UI(ID_CHAT_CONNECT, OnUpdateChatConnect)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTalk diagnostics
- #ifdef _DEBUG
- void CTalk::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CTalk::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTalk message handlers
- void CTalk::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- if (m_recv.GetSafeHwnd())
- m_recv.MoveWindow(0,0,cx,cy/2,TRUE);
- if (m_send.GetSafeHwnd())
- m_send.MoveWindow(0,cy/2,cx,cy/2,TRUE);
- }
- void CTalk::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- m_send.LimitText(4096);
- m_send.init(this);
- pSocket= new CChater(this);
- pSocket->Create();
- pSocket->init();
- m_send.EnableWindow(linkrc.bChat);
- }
- void CTalk::OnChatConnect()
- {
- if (!linkrc.bConnected) {
- CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_ERROR_RECEIVE);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- return;}
- if (pSocket->Connect(linkrc.ip,9999)) {
- linkrc.bChat=TRUE;
- m_send.EnableWindow(TRUE);
- }
- }
- void CTalk::Send(CString msg)
- {
- try {
- if (pSocket!=NULL) pSocket->Send(msg);
- }
- catch (CFileException *e)
- {
- CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_SERVER_FAILED);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- pSocket->Close();
- //delete pSocket;
- //pSocket->~CChater();
- //pSocket= new CChater(this);
- //pSocket->Create();
- //pSocket->init();
- //linkrc.bChat=FALSE;
- e->Delete();
- }
- }
- void CTalk::Recv(CString msg)
- {
- m_recv.SetWindowText(msg);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSend
- CSend::CSend()
- {
- }
- CSend::~CSend()
- {
- }
- BEGIN_MESSAGE_MAP(CSend, CEdit)
- //{{AFX_MSG_MAP(CSend)
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSend message handlers
- /////////////////////////////////////////////////////////////////////////////
- // CRecv
- CRecv::CRecv()
- {
- }
- CRecv::~CRecv()
- {
- }
- BEGIN_MESSAGE_MAP(CRecv, CEdit)
- //{{AFX_MSG_MAP(CRecv)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRecv message handlers
- void CSend::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if (nChar==VK_RETURN) {
- CString text;
- GetWindowText(text);
- m_ptalk->Send(text);
- }
- CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CSend::init(CTalk *ptalk)
- {
- m_ptalk=ptalk;
- }
- void CTalk::OnUpdateChatConnect(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!linkrc.bChat);
- }