PareMessage.cpp
资源名称:QQ示例源码.rar [点击查看]
上传用户:power_led
上传日期:2013-04-11
资源大小:373k
文件大小:3k
源码类别:
ICQ/即时通讯
开发平台:
Visual C++
- #include "Stdafx.h"
- #include "ParseMessage.h"
- #include "ChatClient.h"
- #include "ClientFormView.h"
- #include "ConnectServerDlg.h"
- #include "MainFrm.h"
- CParseMessage::~CParseMessage()
- {
- }
- CParseMessage::CParseMessage(const CMyTreeView * pWnd,const Message & Value)
- {
- pView = const_cast < CMyTreeView *>(pWnd);
- Msg = Value;
- }
- extern CChatClientApp theApp;
- BOOL CParseMessage::SWitchMessage()
- {
- ASSERT(pView != NULL);
- ASSERT_VALID(pView);
- CClientFormView * m_pFormView =(CClientFormView *) ((CMainFrame * )AfxGetMainWnd())->GetFormView();
- int iTryTimes = 0;
- switch(Msg.iType)
- {
- case USERLOG:
- switch(Msg.iSubType)
- {
- case ROOMLIST:
- // pView ->PostMessage(WM_ADDNEWROOM,WPARAM(&Msg),0);
- pView ->AddNewRoom(Msg,0);
- break;
- case USERLIST:
- case USERLOGIN:
- //pView ->PostMessage(WM_NEWCLIENTCOMEIN,WPARAM(&Msg),0);
- pView ->OnNewClientIn(Msg,0);
- break;
- case USERLOGOUT:
- // pView ->PostMessage(WM_USERLOGOUT,WPARAM(&Msg),0);
- pView ->OnClientOut(Msg,0);
- break;
- default:
- break;
- }
- break;
- case USERSESSION:
- switch( Msg.iSubType)
- {
- case SAYINPRIVATE:
- // pView ->PostMessage(WM_SAYINPRIVATE,WPARAM(&Msg),0);
- pView ->OnSayInPrivate(Msg,0);
- break;
- default:
- break;
- }
- break;
- case SYSERROR :
- switch(Msg.iSubType)
- {
- case SERVERQUIT:
- AfxMessageBox("服务器关闭");
- AfxGetMainWnd()->PostMessage(WM_QUIT,0);
- break;
- case USEREXSIT:
- {
- AfxMessageBox("用户名已经存在");
- theApp.m_skMainSocket.SetState(NOTLOGIN);
- CString strServerIp;
- int iServerPort;
- if(!theApp.IniFile.GetVarStr("SERVERIP","DEFUALTSERVERIP",strServerIp))
- {
- strServerIp = _T("127.0.0.1");
- }
- if(!theApp.IniFile.GetVarInt("SERVERPORT","DEFAULTSERVERPORT",iServerPort))
- {
- iServerPort = 1080;
- }
- CConnectServerDlg Dlg(theApp.m_skMainSocket.GetUserName(),strServerIp,iServerPort);
- if(Dlg.DoModal() == IDCANCEL)
- {
- AfxGetMainWnd()->PostMessage(WM_QUIT);
- break;
- }
- Message msObj;
- msObj.iType = FIRSTLOG;
- msObj.iSubType = NOTFIRSTTIME;
- CString strTemp = Dlg.m_strUserName;
- int iLen = strTemp.GetLength();
- lstrcpy(msObj.strName,_T(strTemp.GetBuffer(iLen)));
- strTemp.ReleaseBuffer();
- theApp.m_skMainSocket.Send(&msObj,sizeof(Message));
- theApp.m_skMainSocket.SetUserName(strTemp);
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- return TRUE;
- }