SysHistoryDlg.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // SysHistoryDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "SysHistoryDlg.h"
  16. #include "SysMsgDlg.h"
  17. #include "icqdb.h"
  18. #include "icqclient.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CSysHistoryDlg dialog
  26. CSysHistoryDlg::CSysHistoryDlg(CWnd* pParent /*=NULL*/)
  27. :CMyDlg(CSysHistoryDlg::IDD, pParent), IcqWindow(WIN_SYS_HISTORY)
  28. {
  29. //{{AFX_DATA_INIT(CSysHistoryDlg)
  30. //}}AFX_DATA_INIT
  31. }
  32. void CSysHistoryDlg::deleteAllItems()
  33. {
  34. for (int i = m_ctlHistory.GetItemCount() - 1; i >= 0; i--) {
  35. IcqMsg *msg = (IcqMsg *) m_ctlHistory.GetItemData(i);
  36. delete msg;
  37. }
  38. m_ctlHistory.DeleteAllItems();
  39. }
  40. void CSysHistoryDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CMyDlg::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CSysHistoryDlg)
  44. DDX_Control(pDX, IDC_HISTORY, m_ctlHistory);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CSysHistoryDlg, CMyDlg)
  48. //{{AFX_MSG_MAP(CSysHistoryDlg)
  49. ON_NOTIFY(NM_DBLCLK, IDC_HISTORY, OnDblclkHistory)
  50. ON_WM_SIZE()
  51. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  52. ON_BN_CLICKED(IDC_DELETE_ALL, OnDeleteAll)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CSysHistoryDlg message handlers
  57. void CSysHistoryDlg::OnCancel() 
  58. {
  59. deleteAllItems();
  60. DestroyWindow();
  61. }
  62. void CSysHistoryDlg::PostNcDestroy() 
  63. {
  64. delete this;
  65. }
  66. BOOL CSysHistoryDlg::OnInitDialog() 
  67. {
  68. CMyDlg::OnInitDialog();
  69. m_ctlHistory.SetFullRowSel(TRUE);
  70. CString str;
  71. str.LoadString(IDS_FROM_WHERE);
  72. m_ctlHistory.InsertColumn(0, str, LVCFMT_LEFT, 80);
  73. str.LoadString(IDS_DATE);
  74. m_ctlHistory.InsertColumn(1, str, LVCFMT_LEFT, 90);
  75. str.LoadString(IDS_TIME);
  76. m_ctlHistory.InsertColumn(2, str, LVCFMT_LEFT, 80);
  77. str.LoadString(IDS_CONTENT);
  78. m_ctlHistory.InsertColumn(3, str, LVCFMT_LEFT, 140);
  79. PtrList l;
  80. IcqDB::loadMsg(0, l);
  81. for (int i = 0; !l.empty(); i++) {
  82. IcqMsg *msg = (IcqMsg *) l.back();
  83. l.pop_back();
  84. str.Format("%lu", msg->uin);
  85. m_ctlHistory.InsertItem(i, str);
  86. m_ctlHistory.SetItemData(i, (DWORD) msg);
  87. CTime t(msg->when);
  88. m_ctlHistory.SetItemText(i, 1, t.Format("%Y-%m-%d"));
  89. m_ctlHistory.SetItemText(i, 2, t.Format("%H:%M:%S"));
  90. getMsgText(msg, str);
  91. m_ctlHistory.SetItemText(i, 3, str);
  92. }
  93. return TRUE;  // return TRUE unless you set the focus to a control
  94.               // EXCEPTION: OCX Property Pages should return FALSE
  95. }
  96. void CSysHistoryDlg::OnDblclkHistory(NMHDR* pNMHDR, LRESULT* pResult) 
  97. {
  98. *pResult = 0;
  99. POSITION pos = m_ctlHistory.GetFirstSelectedItemPosition();
  100. if (pos == NULL)
  101. return;
  102. int i = m_ctlHistory.GetNextSelectedItem(pos);
  103. IcqMsg *msg = (IcqMsg *) m_ctlHistory.GetItemData(i);
  104. CSysMsgDlg *win = new CSysMsgDlg(msg, FALSE);
  105. win->Create(IDD_SYS_MESSAGE);
  106. }
  107. void CSysHistoryDlg::OnSize(UINT nType, int cx, int cy) 
  108. {
  109. CMyDlg::OnSize(nType, cx, cy);
  110. if (!m_ctlHistory)
  111. return;
  112. int y = cy - 30;
  113. m_ctlHistory.MoveWindow(0, 0, cx, y);
  114. y += 5;
  115. CRect rc;
  116. CWnd *pWnd = GetDlgItem(IDC_DELETE);
  117. pWnd->GetWindowRect(rc);
  118. ScreenToClient(rc);
  119. rc.bottom = y + rc.Height();
  120. rc.top = y;
  121. pWnd->MoveWindow(rc);
  122. pWnd = GetDlgItem(IDC_DELETE_ALL);
  123. pWnd->GetWindowRect(rc);
  124. ScreenToClient(rc);
  125. rc.bottom = y + rc.Height();
  126. rc.top = y;
  127. pWnd->MoveWindow(rc);
  128. pWnd = GetDlgItem(IDCANCEL);
  129. pWnd->GetWindowRect(rc);
  130. rc.bottom = y + rc.Height();
  131. rc.top = y;
  132. rc.left = cx - 5 - rc.Width();
  133. rc.right = cx - 5;
  134. pWnd->MoveWindow(rc);
  135. }
  136. void CSysHistoryDlg::OnDelete() 
  137. {
  138. POSITION pos = m_ctlHistory.GetFirstSelectedItemPosition();
  139. if (pos == NULL) {
  140. myMessageBox(IDS_SELECT_RECORD, IDS_ERROR, this);
  141. return;
  142. }
  143. int i = m_ctlHistory.GetNextSelectedItem(pos);
  144. IcqMsg *msg = (IcqMsg *) m_ctlHistory.GetItemData(i);
  145. delete msg;
  146. m_ctlHistory.DeleteItem(i);
  147. IcqDB::delMsg(0, m_ctlHistory.GetItemCount() - i);
  148. }
  149. void CSysHistoryDlg::OnDeleteAll() 
  150. {
  151. CString strText, strCaption;
  152. strText.LoadString(IDS_PROMPT_DEL_SYSMSG);
  153. strCaption.LoadString(IDS_WARNING);
  154. if (myMessageBox(IDS_PROMPT_DEL_SYSMSG, IDS_WARNING, this,
  155. MB_YESNO | MB_ICONQUESTION) != IDYES)
  156. return;
  157. deleteAllItems();
  158. IcqDB::delMsg(0);
  159. }