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

ICQ/即时通讯

开发平台:

Visual C++

  1. // FriendDetail.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "FriendDetail.h"
  6. #include "Mainfrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CFriendDetailDlg dialog
  14. CFriendDetailDlg::CFriendDetailDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CFriendDetailDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CFriendDetailDlg)
  18. m_strAddress = _T("");
  19. m_strAge = _T("");
  20. m_strDepartment = _T("");
  21. m_strDescription = _T("");
  22. m_strEmail = _T("");
  23. m_strFax = _T("");
  24. m_strHomepage = _T("");
  25. m_strID = _T("");
  26. m_strName = _T("");
  27. m_strPhone = _T("");
  28. m_canbeadd = -1;
  29. //}}AFX_DATA_INIT
  30. pInfo=NULL;
  31. pWnd=NULL;
  32. hIcon=AfxGetApp()->LoadIcon(IDR_NOTIFY);
  33. }
  34. void CFriendDetailDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CFriendDetailDlg)
  38. DDX_Control(pDX, IDC_SEX, m_ComboSex);
  39. DDX_Control(pDX, IDC_HEADBMP, m_ComboFace);
  40. DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
  41. DDX_Text(pDX, IDC_AGE, m_strAge);
  42. DDX_Text(pDX, IDC_DEPARTMENT, m_strDepartment);
  43. DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
  44. DDX_Text(pDX, IDC_EMAIL, m_strEmail);
  45. DDX_Text(pDX, IDC_FAX, m_strFax);
  46. DDX_Text(pDX, IDC_HOMEPAGE, m_strHomepage);
  47. DDX_Text(pDX, IDC_ID, m_strID);
  48. DDX_Text(pDX, IDC_NAME, m_strName);
  49. DDX_Text(pDX, IDC_PHONE, m_strPhone);
  50. DDX_Radio(pDX, IDC_ALLOW_ALL, m_canbeadd);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CFriendDetailDlg, CDialog)
  54. //{{AFX_MSG_MAP(CFriendDetailDlg)
  55. ON_BN_CLICKED(ID_REFRESH, OnRefresh)
  56. ON_WM_TIMER()
  57. ON_WM_CLOSE()
  58. //}}AFX_MSG_MAP
  59. ON_MESSAGE(WM_SHOW_FRIEND_DETAIL,OnShowFriendDetail)
  60. ON_MESSAGE(WM_RECIEVE_MSG,OnRecvFriendDetail)
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CFriendDetailDlg message handlers
  64. void CFriendDetailDlg::OnRefresh() 
  65. {
  66. if(!GetApp()->m_bOnlineState)
  67. return;
  68. CMsg1 msg;
  69. msg.index=FRIEND_DETAIL;
  70. msg.MyId=GetApp()->m_uCurrentUserID;
  71. msg.tarIP=GetApp()->m_uServerIP;
  72. msg.nPort=GetApp()->m_uServerPort;
  73. msg.FriendId=pInfo->Id;
  74. BOOL bCancel=FALSE;
  75. if(!GetApp()->m_Socket.SendData(&msg,bCancel,this))
  76. {
  77. CString str;
  78. str.LoadString(IDS_SERVER_NOT_RES);
  79. MessageBox(str);
  80. OnOK();
  81. return;
  82. }
  83. BeginWaitCursor();
  84. SetTimer(2,TimeWaitForFriendDetail,NULL);
  85. }
  86. LRESULT CFriendDetailDlg::OnShowFriendDetail(WPARAM wParam,LPARAM lParam)
  87. {
  88. pInfo=(UserInfo*)wParam;
  89. ASSERT(pInfo!=NULL);
  90. m_strID.Format("%d",pInfo->Id);
  91. int photoid=0;
  92. if(pInfo->HaveDetail)
  93. {
  94. if(pInfo->CanbeAdd==0)m_canbeadd=2;
  95. else if(pInfo->CanbeAdd==1)m_canbeadd=0;
  96. else m_canbeadd=1;
  97. m_strAddress=pInfo->Address;
  98. m_strAge=pInfo->Age;
  99. m_strDepartment=pInfo->Department;
  100. m_strDescription=pInfo->Description;
  101. m_strEmail=pInfo->Email;
  102. m_strFax=pInfo->Fax;
  103. m_strHomepage=pInfo->Homepage;
  104. m_strName=pInfo->Name;
  105. m_strPhone=pInfo->Phone;
  106. if(pInfo->PhotoId>=0&&pInfo->PhotoId<UINT(GetApp()->m_nNumberHeadBmp))
  107. photoid=pInfo->PhotoId;
  108. if(pInfo->Sex==0)m_ComboSex.SetCurSel(0);
  109. else if(pInfo->Sex==1)m_ComboSex.SetCurSel(1);
  110. }
  111. m_ComboFace.SetCurSel(photoid);
  112. UpdateData(FALSE);
  113. ShowWindow(SW_NORMAL);
  114. return 0;
  115. }
  116. BOOL CFriendDetailDlg::OnInitDialog() 
  117. {
  118. CDialog::OnInitDialog();
  119. SetIcon(hIcon,TRUE);
  120. SetIcon(hIcon,FALSE);
  121. CMenu* pMenu=GetSystemMenu(FALSE);
  122. pMenu->EnableMenuItem(SC_RESTORE,MF_GRAYED|MF_DISABLED);
  123. pMenu->EnableMenuItem(SC_SIZE,MF_GRAYED|MF_DISABLED);
  124. pMenu->EnableMenuItem(SC_MAXIMIZE,MF_GRAYED|MF_DISABLED);
  125.  
  126. m_ComboFace.SetImageList(&GetApp()->m_imaHead);
  127. return TRUE;
  128. }
  129. void CFriendDetailDlg::OnTimer(UINT nIDEvent) 
  130. {
  131. if(nIDEvent==2)
  132. {
  133. EndWaitCursor();
  134. KillTimer(2);
  135. CString str;
  136. str.LoadString(IDS_SERVER_NOT_RES);
  137. MessageBox(str);
  138. OnOK();
  139. }
  140. }
  141. LRESULT CFriendDetailDlg::OnRecvFriendDetail(WPARAM wParam,LPARAM lParam)
  142. {
  143. if(!GetApp()->m_bOnlineState)return 0;
  144. CData* pData=(CData*)wParam;
  145. if(pData->index==RE_FRIEND_DETAIL)
  146. {
  147. if(pInfo==NULL)return 0;
  148. CMsgPerson msg;
  149. CopyDataBuf(&msg,pData);
  150. if(!msg.LoadFromBuf())return 0;
  151. pInfo->HaveDetail=1;
  152. pInfo->CanbeAdd=msg.Canbeadd;
  153. pInfo->Sex=msg.Sex;
  154. pInfo->PhotoId=msg.PhotoId;
  155. lstrcpy(pInfo->Address,msg.Address);
  156. lstrcpy(pInfo->Age,msg.Age);
  157. lstrcpy(pInfo->Department,msg.Department);
  158. lstrcpy(pInfo->Description,msg.Description);
  159. lstrcpy(pInfo->Email,msg.Email);
  160. lstrcpy(pInfo->Fax,msg.Fax);
  161. lstrcpy(pInfo->Homepage,msg.Homepage);
  162. lstrcpy(pInfo->Phone,msg.Phone);
  163. lstrcpy(pInfo->Name,msg.Name);
  164. UserInfo *pInfo2=NULL;
  165. if(FindInArray(GetApp()->m_aUserInfo,msg.MyId,pInfo2)||FindInArray(GetApp()->m_aStranger,msg.MyId,pInfo2))
  166. {
  167. if(pInfo!=pInfo2)
  168. {
  169. pInfo2->HaveDetail=1;
  170. pInfo2->CanbeAdd=msg.Canbeadd;
  171. pInfo2->Sex=msg.Sex;
  172. pInfo2->PhotoId=msg.PhotoId;
  173. lstrcpy(pInfo2->Address,msg.Address);
  174. lstrcpy(pInfo2->Age,msg.Age);
  175. lstrcpy(pInfo2->Department,msg.Department);
  176. lstrcpy(pInfo2->Description,msg.Description);
  177. lstrcpy(pInfo2->Email,msg.Email);
  178. lstrcpy(pInfo2->Fax,msg.Fax);
  179. lstrcpy(pInfo2->Homepage,msg.Homepage);
  180. lstrcpy(pInfo2->Phone,msg.Phone);
  181. lstrcpy(pInfo2->Name,msg.Name);
  182. }
  183. CMainFrame *pFrame=(CMainFrame*)GetApp()->m_pMainWnd;
  184. pFrame->m_wndBar.ModifyItem(pInfo->Id,pInfo->PhotoId,pInfo->Name);
  185. pFrame->m_wndBar.Invalidate();
  186. }
  187. m_strID.Format("%d",pInfo->Id);
  188. if(pInfo->CanbeAdd==0)m_canbeadd=2;
  189. else if(pInfo->CanbeAdd==1)m_canbeadd=0;
  190. else m_canbeadd=1;
  191. m_strAddress=pInfo->Address;
  192. m_strAge=pInfo->Age;
  193. m_strDepartment=pInfo->Department;
  194. m_strDescription=pInfo->Description;
  195. m_strEmail=pInfo->Email;
  196. m_strFax=pInfo->Fax;
  197. m_strHomepage=pInfo->Homepage;
  198. m_strName=pInfo->Name;
  199. m_strPhone=pInfo->Phone;
  200. if(pInfo->Sex==0)m_ComboSex.SetCurSel(0);
  201. else if(pInfo->Sex==1)m_ComboSex.SetCurSel(1);
  202. int photoid=0;
  203. if(pInfo->PhotoId>=0&&pInfo->PhotoId<UINT(GetApp()->m_nNumberHeadBmp))
  204. photoid=pInfo->PhotoId;
  205. m_ComboFace.SetCurSel(photoid);
  206. UpdateData(FALSE);
  207. EndWaitCursor();
  208. KillTimer(2);
  209. if(pWnd!=NULL)pWnd->PostMessage(WM_REFRESH_DATA);
  210. return 1;
  211. }
  212. else
  213. {
  214. return 0;
  215. }
  216. }
  217. void CFriendDetailDlg::OnCancel() 
  218. {
  219. if(pWnd!=NULL)pWnd->PostMessage(WM_REFRESH_DATA);
  220. CDialog::OnCancel();
  221. }
  222. void CFriendDetailDlg::OnClose() 
  223. OnCancel();
  224. }