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

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. // myicq.cpp : Defines the class behaviors for the application.
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "myicqDlg.h"
  16. #include "icqconfig.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. int myMessageBox(UINT text, UINT title, CWnd *parent, UINT type)
  23. {
  24. CString strText, strTitle;
  25. strText.LoadString(text);
  26. strTitle.LoadString(title);
  27. return parent->MessageBox(strText, strTitle, type);
  28. }
  29. void getMsgText(IcqMsg *msg, CString &str)
  30. {
  31. switch (msg->type) {
  32. case MSG_AUTH_REQUEST:
  33. {
  34. TextInStream in(msg->text.c_str());
  35. uint8 face;
  36. string nick, text;
  37. in >> face >> nick >> text;
  38. str.Format(IDS_AUTH_REQUEST, text.c_str());
  39. }
  40. break;
  41. case MSG_AUTH_ACCEPTED:
  42. str.LoadString(IDS_AUTH_ACCEPTED);
  43. break;
  44. case MSG_AUTH_REJECTED:
  45. str.Format(IDS_AUTH_REJECTED, msg->text.c_str());
  46. break;
  47. case MSG_ADDED:
  48. str.LoadString(IDS_MSG_ADDED);
  49. break;
  50. default:
  51. str = msg->text.c_str();
  52. if (msg->flags & MF_RELAY) {
  53. CString tmp;
  54. tmp.LoadString(IDS_SERVER_RELAY);
  55. str += "rn";
  56. str += tmp;
  57. }
  58. }
  59. }
  60. CIcqApp *myicq;
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CIcqApp
  63. BEGIN_MESSAGE_MAP(CIcqApp, CWinApp)
  64. //{{AFX_MSG_MAP(CIcqApp)
  65. // NOTE - the ClassWizard will add and remove mapping macros here.
  66. //    DO NOT EDIT what you see in these blocks of generated code!
  67. //}}AFX_MSG
  68. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  69. END_MESSAGE_MAP()
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CIcqApp construction
  72. CIcqApp::CIcqApp()
  73. {
  74. // TODO: add construction code here,
  75. // Place all significant initialization in InitInstance
  76. m_hIcon = NULL;
  77. myicq = this;
  78. }
  79. void CIcqApp::setDBDir(uint32 uin)
  80. {
  81. CString dir;
  82. dir.Format("%s%lu\", rootDir, uin);
  83. CreateDirectory(dir, NULL);
  84. IcqDB::setDir(dir);
  85. profile.fileName = dir + "plugins.cfg";
  86. }
  87. IcqProfile *CIcqApp::getProfile(LPCTSTR name)
  88. {
  89. profile.sectionName = name;
  90. return &profile;
  91. }
  92. void CIcqApp::initData()
  93. {
  94. CString str;
  95. genderNames.Add("-");
  96. str.LoadString(IDS_MALE);
  97. genderNames.Add(str);
  98. str.LoadString(IDS_FEMALE);
  99. genderNames.Add(str);
  100. bloodNames.Add("-");
  101. bloodNames.Add("A");
  102. bloodNames.Add("B");
  103. bloodNames.Add("O");
  104. bloodNames.Add("AB");
  105. str.LoadString(IDS_OTHERS);
  106. bloodNames.Add(str);
  107. }
  108. /////////////////////////////////////////////////////////////////////////////
  109. // The one and only CIcqApp object
  110. CIcqApp theApp;
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CIcqApp initialization
  113. BOOL CIcqApp::InitInstance()
  114. {
  115. if (!AfxInitRichEdit())
  116. return FALSE;
  117. if (!AfxSocketInit())
  118. {
  119. AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  120. return FALSE;
  121. }
  122. // Standard initialization
  123. // If you are not using these features and wish to reduce the size
  124. //  of your final executable, you should remove from the following
  125. //  the specific initialization routines you do not need.
  126. #ifdef _AFXDLL
  127. Enable3dControls(); // Call this when using MFC in a shared DLL
  128. #else
  129. Enable3dControlsStatic(); // Call this when linking to MFC statically
  130. #endif
  131. initData();
  132. char fileName[MAX_PATH];
  133. if (!GetModuleFileName(NULL, fileName, sizeof(fileName)))
  134. return FALSE;
  135. char *p = strrchr(fileName, '\');
  136. if (p)
  137. *(p + 1) = '';
  138. rootDir = fileName;
  139. CString dir = rootDir + "config\";
  140. CreateDirectory(dir, NULL);
  141. IcqConfig::setDir(dir);
  142. m_hIcon = LoadIcon(IDR_MAINFRAME);
  143. #ifdef _DEBUG
  144. nrFaces = 5;
  145. #else
  146. nrFaces = 85;
  147. #endif
  148. int n = nrFaces * NUM_PICS_PER_FACE;
  149. largeImageList.Create(32, 32, ILC_COLOR16 | ILC_MASK, n, 0);
  150. smallImageList.Create(16, 16, ILC_COLOR16 | ILC_MASK, n, 0);
  151. COLORREF crMask = RGB(0, 128, 128);
  152. for (int i = 1; i <= NUM_PICS_PER_FACE; i++) {
  153. for (int j = 1; j <= nrFaces; j++) {
  154. CString strFile;
  155. strFile.Format(rootDir + "face\%d-%d.bmp", j, i);
  156. HBITMAP hbmLarge = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), strFile,
  157. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  158. HBITMAP hbmSmall = (HBITMAP) ::CopyImage(hbmLarge, IMAGE_BITMAP, 16, 16, 0);
  159. largeImageList.Add(CBitmap::FromHandle(hbmLarge), crMask);
  160. smallImageList.Add(CBitmap::FromHandle(hbmSmall), crMask);
  161. DeleteObject(hbmLarge);
  162. DeleteObject(hbmSmall);
  163. }
  164. }
  165. smallImageList.Add(LoadIcon(IDI_SYSMSG));
  166. smallImageList.Add(LoadIcon(IDI_FOLDER));
  167. CIcqDlg dlg;
  168. m_pMainWnd = &dlg;
  169. int nResponse = dlg.DoModal();
  170. if (nResponse == IDOK)
  171. {
  172. // TODO: Place code here to handle when the dialog is
  173. //  dismissed with OK
  174. }
  175. else if (nResponse == IDCANCEL)
  176. {
  177. // TODO: Place code here to handle when the dialog is
  178. //  dismissed with Cancel
  179. }
  180. // Since the dialog has been closed, return FALSE so that we exit the
  181. //  application, rather than start the application's message pump.
  182. return FALSE;
  183. }