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

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. // MsgMgrWnd.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "MsgMgrWnd.h"
  16. #include "MsgView.h"
  17. #include "MsgTreeView.h"
  18. #include "MsgListView.h"
  19. #include "MsgSearchDlg.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. #define MESSAGE_CFG "message.cfg"
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMsgMgrWnd
  28. CMsgMgrWnd::CMsgMgrWnd()
  29. {
  30. treeView = NULL;
  31. listView = NULL;
  32. msgView = NULL;
  33. }
  34. CMsgMgrWnd::~CMsgMgrWnd()
  35. {
  36. }
  37. void CMsgMgrWnd::save(DBOutStream &out)
  38. {
  39. treeView->save(out);
  40. listView->save(out);
  41. msgView->save(out);
  42. }
  43. void CMsgMgrWnd::load(DBInStream &in)
  44. {
  45. treeView->load(in);
  46. listView->load(in);
  47. msgView->load(in);
  48. }
  49. BEGIN_MESSAGE_MAP(CMsgMgrWnd, CFrameWnd)
  50. //{{AFX_MSG_MAP(CMsgMgrWnd)
  51. ON_WM_CREATE()
  52. ON_COMMAND(ID_EDIT_DEL, OnEditDel)
  53. ON_COMMAND(ID_FILE_EXIT, OnFileExit)
  54. ON_COMMAND(ID_EXPORT_TXT, OnExportTxt)
  55. ON_COMMAND(ID_VIEW_BGCOLOR, OnViewBgcolor)
  56. ON_COMMAND(ID_VIEW_FONT, OnViewFont)
  57. ON_UPDATE_COMMAND_UI(ID_EXPORT_CONTACT, OnUpdateExportContact)
  58. ON_COMMAND(ID_EXPORT_CONTACT, OnExportContact)
  59. ON_UPDATE_COMMAND_UI(ID_EDIT_DEL, OnUpdateEditDel)
  60. ON_UPDATE_COMMAND_UI(ID_VIEW_FONT, OnUpdateViewFont)
  61. ON_UPDATE_COMMAND_UI(ID_EXPORT_BAK, OnUpdateExportBak)
  62. ON_WM_DESTROY()
  63. ON_COMMAND(ID_EDIT_SEARCH, OnEditSearch)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMsgMgrWnd message handlers
  68. int CMsgMgrWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  69. {
  70. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  71. return -1;
  72. /*
  73. if (!toolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  74. | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  75. !toolBar.LoadToolBar(IDR_MSGMGR))
  76. return -1;
  77. */
  78. treeView = (CMsgTreeView *) splitter.GetPane(0, 0);
  79. listView = (CMsgListView *) splitterRight.GetPane(0, 0);
  80. msgView = (CMsgView *) splitterRight.GetPane(1, 0);
  81. treeView->setListView(listView);
  82. listView->setMsgView(msgView);
  83. IcqDB::loadConfig(MESSAGE_CFG, *this);
  84. SetActiveView(treeView);
  85. return 0;
  86. }
  87. BOOL CMsgMgrWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  88. {
  89. if (!splitter.CreateStatic(this, 1, 2))
  90. return FALSE;
  91. if (!splitter.CreateView(0, 0, RUNTIME_CLASS(CMsgTreeView), CSize(200, 0), pContext))
  92. return FALSE;
  93. if (!splitterRight.CreateStatic(&splitter, 2, 1, WS_CHILD | WS_VISIBLE,
  94. splitter.IdFromRowCol(0, 1)))
  95. return FALSE;
  96. if (!splitterRight.CreateView(0, 0, RUNTIME_CLASS(CMsgListView), CSize(0, 400), pContext))
  97. return FALSE;
  98. if (!splitterRight.CreateView(1, 0, RUNTIME_CLASS(CMsgView), CSize(0, 0), pContext))
  99. return FALSE;
  100. return TRUE;
  101. }
  102. void CMsgMgrWnd::ActivateFrame(DWORD uin, int nCmdShow)
  103. {
  104. treeView->expand(uin);
  105. CFrameWnd::ActivateFrame(SW_MAXIMIZE);
  106. }
  107. void CMsgMgrWnd::OnEditDel() 
  108. {
  109. if (AfxMessageBox(IDS_PROMPT_DEL_MSG, MB_YESNO) != IDYES)
  110. return;
  111. if (GetFocus() == listView)
  112. listView->delSelectedMsg();
  113. else
  114. treeView->delSelectedMsg();
  115. }
  116. void CMsgMgrWnd::OnFileExit() 
  117. {
  118. DestroyWindow();
  119. }
  120. void CMsgMgrWnd::OnExportTxt() 
  121. {
  122. CString fileName;
  123. DWORD uin = treeView->getUIN();
  124. if (uin > 0 && uin <= 0xfffffff0)
  125. fileName.Format("%lu", uin);
  126. CString filter;
  127. filter.LoadString(IDS_FILTER_TXT);
  128. CFileDialog dlg(FALSE, "txt", fileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter);
  129. if (dlg.DoModal() != IDOK)
  130. return;
  131. CStdioFile file(dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite);
  132. CWnd *focus = GetFocus();
  133. if (focus == treeView)
  134. treeView->exportTxt(file);
  135. else if (focus == listView)
  136. listView->exportTxt(file);
  137. }
  138. void CMsgMgrWnd::OnViewBgcolor() 
  139. {
  140. CColorDialog dlg;
  141. if (dlg.DoModal() != IDOK)
  142. return;
  143. COLORREF color = dlg.GetColor();
  144. CWnd *focus = GetFocus();
  145. if (focus == treeView)
  146. treeView->GetTreeCtrl().SetBkColor(color);
  147. else if (focus == listView) {
  148. listView->GetListCtrl().SetBkColor(color);
  149. listView->GetListCtrl().SetTextBkColor(color);
  150. listView->Invalidate();
  151. } else if (focus == &msgView->m_msgEdit)
  152. msgView->m_msgEdit.SetBackgroundColor(FALSE, color);
  153. }
  154. void CMsgMgrWnd::OnViewFont() 
  155. {
  156. CWnd *focus = GetFocus();
  157. if (focus == treeView || focus == listView) {
  158. CColorDialog dlg;
  159. if (dlg.DoModal() != IDOK)
  160. return;
  161. COLORREF color = dlg.GetColor();
  162. if (focus == treeView)
  163. treeView->GetTreeCtrl().SetTextColor(color);
  164. else if (focus == listView) {
  165. listView->GetListCtrl().SetTextColor(color);
  166. listView->Invalidate();
  167. }
  168. } else if (focus == &msgView->m_msgEdit) {
  169. CHARFORMAT cf;
  170. cf.cbSize = sizeof(cf);
  171. cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
  172. msgView->m_msgEdit.GetDefaultCharFormat(cf);
  173. LOGFONT lf;
  174. ZeroMemory(&lf, sizeof(lf));
  175. lstrcpy(lf.lfFaceName, cf.szFaceName);
  176. lf.lfCharSet = cf.bCharSet;
  177. CDC *pDC = GetDC();
  178. lf.lfHeight = -MulDiv(cf.yHeight, pDC->GetDeviceCaps(LOGPIXELSY), 72) / 20;
  179. ReleaseDC(pDC);
  180. CFontDialog dlg(&lf);
  181. dlg.m_cf.rgbColors = cf.crTextColor;
  182. if (dlg.DoModal() != IDOK)
  183. return;
  184. cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE;
  185. lstrcpy(cf.szFaceName, dlg.GetFaceName());
  186. cf.yHeight = dlg.GetSize() * 2;
  187. cf.crTextColor = dlg.GetColor();
  188. cf.dwEffects = 0;
  189. msgView->m_msgEdit.SetDefaultCharFormat(cf);
  190. msgView->Invalidate();
  191. }
  192. }
  193. void CMsgMgrWnd::OnUpdateExportContact(CCmdUI* pCmdUI) 
  194. {
  195. pCmdUI->Enable(FALSE);
  196. }
  197. void CMsgMgrWnd::OnExportContact() 
  198. {
  199. CString fileName;
  200. DWORD uin = treeView->getUIN();
  201. if (uin > 0 && uin <= 0xfffffff0)
  202. fileName.Format("%lu", uin);
  203. CString filter;
  204. filter.LoadString(IDS_FILTER_TXT);
  205. CFileDialog dlg(FALSE, "txt", fileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter);
  206. if (dlg.DoModal() != IDOK)
  207. return;
  208. CStdioFile file(dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite);
  209. if (GetActiveView() == treeView)
  210. treeView->exportContact(file);
  211. }
  212. void CMsgMgrWnd::OnUpdateEditDel(CCmdUI* pCmdUI) 
  213. {
  214. pCmdUI->Enable(FALSE);
  215. }
  216. void CMsgMgrWnd::OnUpdateViewFont(CCmdUI* pCmdUI) 
  217. {
  218. CMenu *menu = pCmdUI->m_pMenu;
  219. if (menu) {
  220. CString str;
  221. str.LoadString(IDS_VIEW_FONTCOLOR);
  222. menu->ModifyMenu(pCmdUI->m_nID, 0, pCmdUI->m_nID, str);
  223. }
  224. }
  225. void CMsgMgrWnd::OnUpdateExportBak(CCmdUI* pCmdUI) 
  226. {
  227. pCmdUI->Enable(FALSE);
  228. }
  229. void CMsgMgrWnd::OnDestroy() 
  230. {
  231. IcqDB::saveConfig(MESSAGE_CFG, *this);
  232. CFrameWnd::OnDestroy();
  233. }
  234. void CMsgMgrWnd::OnEditSearch() 
  235. {
  236. CMsgSearchDlg *dlg = new CMsgSearchDlg;
  237. dlg->Create(IDD_MSG_SEARCH, this);
  238. }