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

ICQ/即时通讯

开发平台:

Visual C++

  1. // LookDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "LookDlg.h"
  6. #include "mainfrm.h"
  7. #include "talkdlg.h"
  8. #include "frienddetail.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CLookDlg dialog
  16. CLookDlg::CLookDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(CLookDlg::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CLookDlg)
  20. m_strTime = _T("");
  21. m_strTalk = _T("");
  22. m_strID = _T("");
  23. m_strName = _T("");
  24. m_strEmail = _T("");
  25. m_strDate = _T("");
  26. //}}AFX_DATA_INIT
  27. pInfo=NULL;
  28. pState=NULL;
  29. m_bClose=TRUE;
  30. hIcon=AfxGetApp()->LoadIcon(IDR_MESSAGE1);
  31. }
  32. void CLookDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CLookDlg)
  36. DDX_Control(pDX, ID_SHOW_DETAIL, m_headBmp);
  37. DDX_Control(pDX, IDC_TALK_RECORD, m_TalkRecord);
  38. DDX_Text(pDX, IDC_TIME, m_strTime);
  39. DDX_Text(pDX, IDC_TALK, m_strTalk);
  40. DDX_Text(pDX, IDC_ID, m_strID);
  41. DDX_Text(pDX, IDC_NAME, m_strName);
  42. DDX_Text(pDX, IDC_EMAIL, m_strEmail);
  43. DDX_Text(pDX, IDC_DATE, m_strDate);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CLookDlg, CDialog)
  47. //{{AFX_MSG_MAP(CLookDlg)
  48. ON_BN_CLICKED(ID_SHOW_TALK, OnShowTalk)
  49. ON_BN_CLICKED(ID_NEXT, OnNext)
  50. ON_WM_CLOSE()
  51. ON_BN_CLICKED(ID_SHOW_DETAIL, OnShowDetail)
  52. //}}AFX_MSG_MAP
  53. ON_MESSAGE(WM_RECVMSG,OnRecvMsg)
  54. ON_MESSAGE(WM_REFRESH_DATA,OnRefreshData)
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CLookDlg message handlers
  58. BOOL CLookDlg::OnInitDialog() 
  59. {
  60. CDialog::OnInitDialog();
  61. SetIcon(hIcon,TRUE);
  62. SetIcon(hIcon,FALSE);
  63. CMenu* pMenu=GetSystemMenu(FALSE);
  64. pMenu->EnableMenuItem(SC_RESTORE,MF_GRAYED|MF_DISABLED);
  65. pMenu->EnableMenuItem(SC_SIZE,MF_GRAYED|MF_DISABLED);
  66. pMenu->EnableMenuItem(SC_MAXIMIZE,MF_GRAYED|MF_DISABLED);
  67. CRect r1,r2;
  68. GetWindowRect(&r1);
  69. m_TalkRecord.GetWindowRect(&r2);
  70. r1.SetRect(r1.left,r1.top,r1.right,r2.top);
  71. MoveWindow(r1);
  72. return TRUE;  
  73. }
  74. void CLookDlg::OnShowTalk() 
  75. {
  76. static BOOL bShowRecord=TRUE;
  77. CRect r1,r2;
  78. GetWindowRect(&r1);
  79. m_TalkRecord.GetWindowRect(&r2);
  80. if(bShowRecord)
  81. r1.SetRect(r1.left,r1.top,r1.right,r2.bottom+4);
  82. else
  83. r1.SetRect(r1.left,r1.top,r1.right,r2.top);
  84. bShowRecord=!bShowRecord;
  85. MoveWindow(r1);
  86. }
  87. LRESULT CLookDlg::OnRecvMsg(WPARAM wParam,LPARAM lParam) 
  88. {
  89. pInfo=(UserInfo*)wParam;
  90. pState=(FriendState*)lParam;
  91. int & iCurMsg=pState->nCurrentMsg;
  92. CString str;
  93. int i=pState->aMsg.GetSize()-1;
  94. str.Format("(%s)%srn%srnrn",pState->aMsg.GetAt(i)->Time.Format("%Y-%m-%d %H:%M:%S"),pInfo->Name,pState->aMsg.GetAt(i)->Msg);
  95. m_TalkRecord.SetSel(0,0);
  96. m_TalkRecord.ReplaceSel(str);
  97. if(pState->pTalk==NULL)
  98. {
  99. pState->pTalk=new CTalkDlg;
  100. pState->pTalk->Create(CTalkDlg::IDD,GetDesktopWindow());
  101. }
  102. pState->pTalk->m_TalkRecord.SetSel(0,0);
  103. pState->pTalk->m_TalkRecord.ReplaceSel(str);
  104. if(m_bClose)
  105. {
  106. m_strID.Format("%d",pInfo->Id);
  107. int photoid=0;
  108. if(pInfo->HaveDetail)
  109. {
  110. m_strEmail=pInfo->Email;
  111. m_strName=pInfo->Name;
  112. if(pInfo->PhotoId>=0&&pInfo->PhotoId<UINT(GetApp()->m_nNumberHeadBmp))
  113. photoid=pInfo->PhotoId;
  114. }
  115. CBitmap* pBmp=NULL;
  116. pBmp=GetApp()->m_paBitmap[2*photoid];
  117. m_headBmp.SetBitmap(pBmp);
  118. m_strDate=pState->aMsg.GetAt(iCurMsg)->Time.Format(" %Y-%m-%d");
  119. m_strTime=pState->aMsg.GetAt(iCurMsg)->Time.Format(" %H:%M:%S");
  120. m_strTalk=pState->aMsg.GetAt(iCurMsg)->Msg;
  121. iCurMsg++;
  122. if(pState->aMsg.GetSize()>iCurMsg)
  123. GetDlgItem(ID_NEXT)->EnableWindow();
  124. else
  125. GetDlgItem(ID_NEXT)->EnableWindow(FALSE);
  126. UpdateData(FALSE);
  127. m_bClose=FALSE;
  128. }
  129. else
  130. {
  131. if(pState->aMsg.GetSize()>iCurMsg)
  132. GetDlgItem(ID_NEXT)->EnableWindow();
  133. }
  134. ShowWindow(SW_SHOWNORMAL);
  135. return 0;
  136. }
  137. void CLookDlg::OnNext() 
  138. {
  139. if(pState==NULL)return;
  140. int& iCurMsg=pState->nCurrentMsg;
  141. if(pState->aMsg.GetSize()>iCurMsg)
  142. {
  143. m_strDate=pState->aMsg.GetAt(iCurMsg)->Time.Format(" %Y-%m-%d");
  144. m_strTime=pState->aMsg.GetAt(iCurMsg)->Time.Format(" %H:%M:%S");
  145. m_strTalk=pState->aMsg.GetAt(iCurMsg)->Msg;
  146. iCurMsg++;
  147. if(pState->aMsg.GetSize()>iCurMsg)
  148. GetDlgItem(ID_NEXT)->EnableWindow();
  149. else
  150. GetDlgItem(ID_NEXT)->EnableWindow(FALSE);
  151. UpdateData(FALSE);
  152. }
  153. }
  154. void CLookDlg::OnOK() 
  155. {
  156. m_bClose=TRUE;
  157. if(pState->pTalk==NULL)
  158. {
  159. pState->pTalk=new CTalkDlg;
  160. pState->pTalk->Create(CTalkDlg::IDD,GetDesktopWindow());
  161. }
  162. CRect r1,r2,r3;
  163. GetWindowRect(&r1);
  164. pState->pTalk->GetWindowRect(&r2);
  165. r3.left=r1.left;
  166. r3.top=r1.top;
  167. r3.right=r1.left+r2.Width();
  168. r3.bottom=r1.top+r2.Height();
  169. pState->pTalk->MoveWindow(&r3,FALSE);
  170. pState->pTalk->PostMessage(WM_SEND_MSG,(WPARAM)pInfo,(LPARAM)pState);
  171. CDialog::OnOK();
  172. }
  173. void CLookDlg::OnCancel() 
  174. {
  175. m_bClose=TRUE;
  176. CDialog::OnCancel();
  177. }
  178. void CLookDlg::OnClose() 
  179. {
  180. m_bClose=TRUE;
  181. CDialog::OnClose();
  182. }
  183. void CLookDlg::OnShowDetail() 
  184. {
  185. if(pState->pFInfo==NULL)
  186. {
  187. pState->pFInfo=new CFriendDetailDlg;
  188. pState->pFInfo->Create(CFriendDetailDlg::IDD,GetDesktopWindow());
  189. }
  190. pState->pFInfo->SetOwnerWnd(this);
  191. pState->pFInfo->SendMessage(WM_SHOW_FRIEND_DETAIL,(WPARAM)pInfo,(LPARAM)pState);
  192. pState->pFInfo->OnRefresh();
  193. }
  194. LRESULT CLookDlg::OnRefreshData(WPARAM wParam,LPARAM lParam)
  195. {
  196. m_strEmail=pInfo->Email;
  197. m_strName=pInfo->Name;
  198. if(pInfo->PhotoId>=0&&pInfo->PhotoId<UINT(GetApp()->m_nNumberHeadBmp))
  199. m_headBmp.SetBitmap(GetApp()->m_paBitmap[2*pInfo->PhotoId]);
  200. UpdateData(FALSE);
  201. return 1;
  202. }