AddFriendDlg.cpp
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:4k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. // AddFriendDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "AddFriendDlg.h"
  6. #include "Mainfrm.h"
  7. #include "frienddetail.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAddFriendDlg dialog
  15. CAddFriendDlg::CAddFriendDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CAddFriendDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CAddFriendDlg)
  19. m_strID = _T("");
  20. m_strName = _T("");
  21. //}}AFX_DATA_INIT
  22. pDetailDlg=NULL;
  23. pWnd=NULL;
  24. bStartAdd=FALSE;
  25. }
  26. void CAddFriendDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CAddFriendDlg)
  30. DDX_Control(pDX, IDC_FRIEND_DETAIL, m_headbmp);
  31. DDX_Control(pDX, IDC_RECT, m_Rect);
  32. DDX_Text(pDX, IDC_ID, m_strID);
  33. DDX_Text(pDX, IDC_NAME, m_strName);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CAddFriendDlg, CDialog)
  37. //{{AFX_MSG_MAP(CAddFriendDlg)
  38. ON_WM_TIMER()
  39. ON_BN_CLICKED(IDC_FRIEND_DETAIL, OnFriendDetail)
  40. //}}AFX_MSG_MAP
  41. ON_MESSAGE(WM_RECIEVE_MSG,OnRecvAddFriendRes)
  42. ON_MESSAGE(WM_NOTICE_ADDFRIEND,OnNoticeAddFriend)
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CAddFriendDlg message handlers
  46. void CAddFriendDlg::OnTimer(UINT nIDEvent) 
  47. {
  48. if(nIDEvent==1)
  49. {
  50. EndWaitCursor();
  51. KillTimer(1);
  52. CString str;
  53. str.LoadString(IDS_SERVER_NOT_RES);
  54. MessageBox(str);
  55. CDialog::OnOK();
  56. }
  57. }
  58. LRESULT CAddFriendDlg::OnRecvAddFriendRes(WPARAM wParam,LPARAM lParam)
  59. {
  60. if(!bStartAdd)return 0;
  61. bStartAdd=FALSE;
  62. CData *pData=(CData*)wParam;
  63. if(pData->index==RE_ADD_AS_FRIEND)
  64. {
  65. KillTimer(1);
  66. CMsg3 msg;
  67. CopyDataBuf(&msg,pData);
  68. delete pData;
  69. if(!msg.LoadFromBuf())return 0;
  70. //(0,1,2,3 别人拒绝,成功加入,要求验证人份,此人已经为好友)
  71. EndWaitCursor();
  72. if(msg.Value==0)
  73. {
  74. MessageBox("服务器拒绝请求!");
  75. CDialog::OnOK();
  76. }
  77. else if(msg.Value==1)
  78. {
  79. CDialog::OnOK();
  80. CMainFrame * pFrame=(CMainFrame*)GetApp()->m_pMainWnd;
  81. pFrame->PostMessage(WM_ADDFRIEND_REFRESH,uID,0);
  82. }
  83. else if(msg.Value=2)
  84. {
  85. CRect r1,r2;
  86. GetWindowRect(&r1);
  87. m_Rect.GetWindowRect(&r2);
  88. r1.SetRect(r1.left,r1.top,r1.right,r2.bottom+4);
  89. MoveWindow(r1);
  90. MessageBox("对方需要身份验证!");
  91. ShowWindow(SW_NORMAL);
  92. }
  93. else
  94. {
  95. MessageBox("此人已经在好友列表中!","错误");
  96. CDialog::OnOK();
  97. }
  98. return 1;
  99. }
  100. return 0;
  101. }
  102. LRESULT CAddFriendDlg::OnNoticeAddFriend(WPARAM wParam,LPARAM lParam)
  103. {
  104. if(uID==0)return 0;
  105. m_strID.Format("%d",uID);
  106. m_headbmp.SetBitmap(GetApp()->m_paBitmap[0]);
  107. if(!GetApp()->m_bOnlineState)
  108. {
  109. CString str;
  110. str.LoadString(IDS_NOT_LOGIN_SERVER);
  111. MessageBox(str);
  112. CDialog::OnCancel();
  113. return 0;
  114. }
  115. if(FindInArray(GetApp()->m_aUserInfo,uID)!=-1)
  116. {
  117. MessageBox("此人已经在好友列表中!","错误");
  118. CDialog::OnCancel();
  119. return 0;
  120. }
  121. BeginWaitCursor();
  122. CMsg1 msg;
  123. msg.index=ADD_AS_FRIEND;
  124. msg.MyId=GetApp()->m_uCurrentUserID;
  125. msg.FriendId=uID;
  126. msg.tarIP=GetApp()->m_uServerIP;
  127. msg.nPort=GetApp()->m_uServerPort;
  128. msg.Time=CTime::GetCurrentTime();
  129. BOOL bCancel=FALSE;
  130. if(GetApp()->m_Socket.SendData(&msg,bCancel,this))
  131. {
  132. bStartAdd=TRUE;
  133. SetTimer(1,TimeWaitForAddFriend,NULL);
  134. }
  135. else
  136. {
  137. CString str;
  138. str.LoadString(IDS_SERVER_NOT_RES);
  139. MessageBox(str);
  140. CDialog::OnCancel();
  141. }
  142. return 1;
  143. }
  144. void CAddFriendDlg::OnFriendDetail() 
  145. {
  146. memset(&Info,0,sizeof(Info));
  147. Info.Id=uID;
  148. Info.HaveDetail=0;
  149. if(pDetailDlg==NULL)
  150. {
  151. pDetailDlg=new CFriendDetailDlg;
  152. pDetailDlg->Create(CFriendDetailDlg::IDD,GetDesktopWindow());
  153. }
  154. pDetailDlg->SendMessage(WM_SHOW_FRIEND_DETAIL,(WPARAM)&Info,0);
  155. pDetailDlg->OnRefresh();
  156. }