PareMessage.cpp
上传用户:power_led
上传日期:2013-04-11
资源大小:373k
文件大小:3k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. #include "Stdafx.h"
  2. #include "ParseMessage.h"
  3. #include "ChatClient.h"
  4. #include "ClientFormView.h"
  5. #include "ConnectServerDlg.h"
  6. #include "MainFrm.h"
  7. CParseMessage::~CParseMessage()
  8. {
  9. }
  10. CParseMessage::CParseMessage(const CMyTreeView * pWnd,const Message & Value)
  11. {
  12. pView = const_cast < CMyTreeView *>(pWnd);
  13. Msg = Value;
  14. }
  15. extern CChatClientApp theApp;
  16. BOOL CParseMessage::SWitchMessage()
  17. {
  18. ASSERT(pView != NULL);
  19. ASSERT_VALID(pView);
  20. CClientFormView * m_pFormView =(CClientFormView *) ((CMainFrame * )AfxGetMainWnd())->GetFormView();
  21. int iTryTimes = 0;
  22. switch(Msg.iType)
  23. {
  24. case USERLOG:
  25. switch(Msg.iSubType)
  26. {
  27. case ROOMLIST:
  28. // pView ->PostMessage(WM_ADDNEWROOM,WPARAM(&Msg),0);
  29. pView ->AddNewRoom(Msg,0);
  30. break;
  31. case  USERLIST:
  32. case USERLOGIN:
  33. //pView ->PostMessage(WM_NEWCLIENTCOMEIN,WPARAM(&Msg),0);
  34. pView ->OnNewClientIn(Msg,0);
  35. break;
  36. case  USERLOGOUT:
  37. // pView ->PostMessage(WM_USERLOGOUT,WPARAM(&Msg),0);
  38. pView ->OnClientOut(Msg,0);
  39. break;
  40. default:
  41. break;
  42. }
  43. break;
  44. case USERSESSION:
  45. switch( Msg.iSubType)
  46. {
  47. case SAYINPRIVATE:
  48. // pView ->PostMessage(WM_SAYINPRIVATE,WPARAM(&Msg),0);
  49. pView ->OnSayInPrivate(Msg,0);
  50. break;
  51. default:
  52. break;
  53. }
  54. break;
  55. case SYSERROR :
  56. switch(Msg.iSubType)
  57. {
  58. case  SERVERQUIT:
  59. AfxMessageBox("服务器关闭");
  60. AfxGetMainWnd()->PostMessage(WM_QUIT,0);
  61. break;
  62. case USEREXSIT:
  63. {
  64. AfxMessageBox("用户名已经存在");
  65. theApp.m_skMainSocket.SetState(NOTLOGIN);
  66. CString strServerIp;
  67. int iServerPort;
  68. if(!theApp.IniFile.GetVarStr("SERVERIP","DEFUALTSERVERIP",strServerIp))
  69. {
  70. strServerIp = _T("127.0.0.1");
  71. }
  72. if(!theApp.IniFile.GetVarInt("SERVERPORT","DEFAULTSERVERPORT",iServerPort))
  73. {
  74. iServerPort = 1080;
  75. }
  76. CConnectServerDlg Dlg(theApp.m_skMainSocket.GetUserName(),strServerIp,iServerPort);
  77. if(Dlg.DoModal() == IDCANCEL)
  78. {
  79. AfxGetMainWnd()->PostMessage(WM_QUIT);
  80. break;
  81. }
  82. Message msObj;
  83. msObj.iType = FIRSTLOG;
  84. msObj.iSubType = NOTFIRSTTIME;
  85. CString strTemp = Dlg.m_strUserName;
  86. int iLen = strTemp.GetLength();
  87. lstrcpy(msObj.strName,_T(strTemp.GetBuffer(iLen)));
  88. strTemp.ReleaseBuffer();
  89. theApp.m_skMainSocket.Send(&msObj,sizeof(Message));
  90. theApp.m_skMainSocket.SetUserName(strTemp);
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. break;
  97. default:
  98. break;
  99. }
  100. return TRUE;
  101. }