ChatPanelBar.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:34k
源码类别:

网格计算

开发平台:

Visual C++

  1. #include "stdAfx.h"
  2. #include "trfAgent.h"
  3. #include "variantex.h"
  4. #include "ChatPanelBar.h"
  5. CChatPanelBar::CChatPanelBar()
  6. {
  7. this->m_ncurmsgagent = -1;
  8. this->m_nchatingAgent = -1;
  9. this->m_hUserStateRefThread = NULL;
  10. }
  11. CChatPanelBar::~CChatPanelBar(){}
  12. BEGIN_MESSAGE_MAP(CChatPanelBar, CSizingControlBar)
  13. //{{AFX_MSG_MAP(CChatPanelBar)
  14. ON_WM_CREATE()
  15. ON_WM_SIZE()
  16. ON_WM_DESTROY()
  17. ON_MESSAGE(UWM_CHATINGMSG, OnChatingMsg)
  18. ON_MESSAGE(UWM_CHARINPUTOVER, OnInputChatMsgOver)
  19. ON_MESSAGE(UWM_CHATSTARTLOGON, OnChatStartLogon)
  20. ON_MESSAGE(UWM_STATICCLICKED, OnStaticClickedMsg)
  21. ON_MESSAGE(WM_TASKBARNOTIFIERCLICKED, OnTaskbarNotifierClicked)
  22. //}}AFX_MSG_MAP
  23. ON_MESSAGE(WM_OUTBAR_NOTIFY, OnChatUsersBarNotify)
  24. END_MESSAGE_MAP()
  25. int CChatPanelBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  26. {
  27. if(CSizingControlBar::OnCreate(lpCreateStruct) == -1) return -1;
  28. CString strLogfile;
  29. m_guifont.CreateFont(
  30. 12,                        // nHeight
  31. 0,                         // nWidth
  32. 0,                         // nEscapement
  33. 0,                         // nOrientation
  34. FW_NORMAL,                 // nWeight
  35. FALSE,                     // bItalic
  36. FALSE,                     // bUnderline
  37. 0,                         // cStrikeOut
  38. ANSI_CHARSET,              // nCharSet
  39. OUT_DEFAULT_PRECIS,        // nOutPrecision
  40. CLIP_DEFAULT_PRECIS,       // nClipPrecision
  41. DEFAULT_QUALITY,           // nQuality
  42. DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
  43. _T("宋体"));              // lpszFacename
  44. //-------------------------------------------------------------------
  45. if(!m_wndTipInfo.Create(_LoadString(IDS_CHATBARTITLE).GetBuffer(0), 
  46. WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 680))
  47. {
  48. TRACE0("Failed to create m_wndTipInfo(CChatPanelBar) n");
  49. return -1;
  50. }
  51. m_wndTipInfo.SetFont((HFONT)m_guifont);
  52. m_wndTipInfo.SetFontColor(RGB(0, 0, 0));
  53. m_wndTipInfo.SetBackColor(RGB(255, 255, 204));
  54. m_wndTipInfo.SetText(_LoadString(IDS_CHATBARTITLE).GetBuffer(0));
  55. if(!m_wndAddDelFriendBtn.Create(_LoadString(IDS_CHATADDFRIEND).GetBuffer(0), 
  56. WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 680))
  57. {
  58. TRACE0("Failed to create m_wndAddDelFriendBtn(CChatPanelBar) n");
  59. return -1;
  60. }
  61. m_wndAddDelFriendBtn.SetFont((HFONT)m_guifont);
  62. m_wndAddDelFriendBtn.SetFontColor(RGB(0, 0, 255));
  63. m_wndAddDelFriendBtn.SetBackColor(RGB(255, 255, 204));
  64. m_wndAddDelFriendBtn.SetText(_LoadString(IDS_CHATADDFRIEND).GetBuffer(0));
  65. if(!m_wndRefUsrsBtn.Create(_LoadString(IDS_CHATREFBTNTXT).GetBuffer(0), 
  66. WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 680))
  67. {
  68. TRACE0("Failed to create m_wndRefUsrsBtn(CChatPanelBar) n");
  69. return -1;
  70. }
  71. m_wndRefUsrsBtn.SetFont((HFONT)m_guifont);
  72. m_wndRefUsrsBtn.SetFontColor(RGB(0, 0, 255));
  73. m_wndRefUsrsBtn.SetBackColor(RGB(255, 255, 204));
  74. m_wndRefUsrsBtn.SetText(_LoadString(IDS_CHATREFBTNTXT).GetBuffer(0));
  75. if(!m_wndBroadcastBtn.Create(_LoadString(IDS_CHATBROADCASTOALLBTNTXT).GetBuffer(0), 
  76. WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 680))
  77. {
  78. TRACE0("Failed to create m_wndBroadcastBtn(CChatPanelBar) n");
  79. return -1;
  80. }
  81. m_wndBroadcastBtn.SetFont((HFONT)m_guifont);
  82. m_wndBroadcastBtn.SetFontColor(RGB(255, 0, 0));
  83. m_wndBroadcastBtn.SetBackColor(RGB(255, 255, 204));
  84. m_wndBroadcastBtn.SetText(_LoadString(IDS_CHATBROADCASTOALLBTNTXT).GetBuffer(0));
  85. //-------------------------------------------------------------------
  86. if(!m_wndREChatOutput.Create(WS_CHILD | WS_VISIBLE | WS_BORDER |
  87. ES_LEFT | ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_HSCROLL,
  88. CRect(0, 0, 0, 0), this, 681))
  89. {
  90. TRACE0("Failed to create m_wndREChatOutput(CChatPanelBar) n");
  91. return -1;
  92. }
  93. if(this->GetChatingLogfile(strLogfile))
  94. {
  95. if(strLogfile.IsEmpty()) {
  96. strLogfile.Format("%s\%s", ENV_SYSROOTDIR, ENV_DEFAULT_CHATINGLOGFILE);
  97. }
  98. if(!m_wndREChatOutput.Setlogfile(strLogfile.GetBuffer(0)))
  99. {
  100. TRACE0("Failed to open chating logfile(CChatPanelBar) n");
  101. return -1;
  102. }
  103. }
  104. //-------------------------------------------------------------------
  105. if(!m_wndEDChatInput.Create(WS_CHILD | WS_VISIBLE | WS_BORDER |
  106. ES_MULTILINE | WS_VSCROLL,
  107. CRect(0, 0, 0, 0), this, 682))
  108. {
  109. TRACE0("Failed to create m_wndEDChatInput(CChatPanelBar) n");
  110. return -1;
  111. }
  112. m_wndEDChatInput.SetLimitText(SIZE_BUFFER);
  113. //-------------------------------------------------------------------
  114. if(!this->m_wndTaskbar.Create(this))
  115. {
  116. TRACE0("Failed to create m_wndTaskbar(CChatPanelBar) n");
  117. return -1;
  118. }
  119. this->m_wndTaskbar.SetSkin(IDB_SKIN_BOARD, 255, 0, 255);
  120. this->m_wndTaskbar.SetTextFont("Arial", 90, TN_TEXT_NORMAL, TN_TEXT_UNDERLINE | TN_TEXT_BOLD);
  121. this->m_wndTaskbar.SetTextColor(RGB(255, 255, 255), RGB(0, 0, 255));
  122. this->m_wndTaskbar.SetTextRect(CRect(10, 20, m_wndTaskbar.m_nSkinWidth-10, m_wndTaskbar.m_nSkinHeight-20));
  123. //-------------------------------------------------------------------
  124. DWORD dwf = CGfxOutBarCtrl::fDragItems|
  125. CGfxOutBarCtrl::fEditGroups|
  126. CGfxOutBarCtrl::fEditItems|
  127. CGfxOutBarCtrl::fRemoveGroups|
  128. CGfxOutBarCtrl::fRemoveItems|
  129. CGfxOutBarCtrl::fAddGroups|
  130. CGfxOutBarCtrl::fAnimation;
  131. if(!m_wndUsersBar.Create(WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, 683, dwf))
  132. {
  133. TRACE0("Failed to create m_wndUsersBar(CChatPanelBar) n");
  134. return -1;
  135. }
  136. this->m_wndUsersBar.SetOwner(this);
  137. //-------------------------------------------------------------------
  138. this->InitMyFriendsFolder();
  139. //-------------------------------------------------------------------
  140. //create UDP socket.
  141. int dwUDPort = this->GetUDPPort();
  142. if(!m_udpclt.Create(dwUDPort, 10, 10)) return FALSE;
  143. //create the user states refreshing thread and killer event.
  144. DWORD dwthreadid = 0x0000;
  145. this->m_hUserStateRefThreadKillEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  146. this->m_hUserStateRefThread = ::CreateThread(NULL, 0, Routine_UserStateRef, this, 0, &dwthreadid);
  147. this->m_hBroadcastEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  148. this->m_hBroadcastWorkThreadKillEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  149. this->m_hBroadcastWorkThread = ::CreateThread(NULL, 0, Routine_BroadcastMsg, this, 0, &dwthreadid);
  150. return 0;
  151. }
  152. void CChatPanelBar::OnDestroy()
  153. {
  154. //deattach gdi object.
  155. m_guifont.DeleteObject();
  156. //kill all working threads.
  157. if(NULL != this->m_hBroadcastWorkThread)
  158. {
  159. ::SetEvent(this->m_hBroadcastWorkThreadKillEvent);
  160. ::WaitForSingleObject(this->m_hBroadcastWorkThread, INFINITE);
  161. ::CloseHandle(this->m_hBroadcastWorkThread);
  162. ::CloseHandle(this->m_hBroadcastWorkThreadKillEvent);
  163. ::CloseHandle(this->m_hBroadcastEvent);
  164. this->m_hBroadcastEvent = NULL;
  165. this->m_hBroadcastWorkThread = NULL;
  166. this->m_hBroadcastWorkThreadKillEvent = NULL;
  167. }
  168. if(NULL != this->m_hUserStateRefThread)
  169. {
  170. ::SetEvent(this->m_hUserStateRefThreadKillEvent);
  171. ::WaitForSingleObject(this->m_hUserStateRefThread, INFINITE);
  172. ::CloseHandle(this->m_hUserStateRefThread);
  173. ::CloseHandle(this->m_hUserStateRefThreadKillEvent);
  174. this->m_hUserStateRefThread = NULL;
  175. this->m_hUserStateRefThreadKillEvent = NULL;
  176. }
  177. //destroy sub-windows.
  178. this->m_wndTaskbar.DestroyWindow();
  179. this->m_wndTipInfo.DestroyWindow();
  180. this->m_wndRefUsrsBtn.DestroyWindow();
  181. this->m_wndBroadcastBtn.DestroyWindow();
  182. this->m_wndAddDelFriendBtn.DestroyWindow();
  183. }
  184. void CChatPanelBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  185. {
  186. CSizingControlBar::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
  187. UpdateDialogControls(pTarget, bDisableIfNoHndler);
  188. }
  189. void CChatPanelBar::OnSize(UINT nType, int cx, int cy) 
  190. {
  191.     CSizingControlBar::OnSize(nType, cx, cy);
  192. AdjustChildrenRegion();
  193. }
  194. void CChatPanelBar::AdjustChildrenRegion(void)
  195. {
  196. const int WIDTH_OUTLOOKBAR = 15;
  197. const int HEIGHT_TIPINFO = 15;
  198. const int HEIGHT_REOUTPUT = 70;
  199. const int HEIGHT_EDINPUT = 30;
  200. if( !m_wndTipInfo.GetSafeHwnd()  ||
  201. !m_wndAddDelFriendBtn.GetSafeHwnd() ||
  202. !m_wndRefUsrsBtn.GetSafeHwnd()   ||
  203. !m_wndBroadcastBtn.GetSafeHwnd() ||
  204. !m_wndREChatOutput.GetSafeHwnd() ||
  205. !m_wndEDChatInput.GetSafeHwnd()  ||
  206. !m_wndUsersBar.GetSafeHwnd())
  207. return ;
  208. int width = 0;
  209. CRect rcParent, rcChild;
  210. this->GetClientRect(&rcParent);
  211. //tip info static window.
  212. //1
  213. rcChild = rcParent;
  214. width = rcParent.Width() - ((rcParent.Width() * WIDTH_OUTLOOKBAR / 100) + 2);
  215. rcChild.bottom = rcChild.top + HEIGHT_TIPINFO;
  216. rcChild.right  = rcChild.left + width / 2;
  217. m_wndTipInfo.MoveWindow(&rcChild);
  218. //2
  219. rcChild.left = rcChild.right;
  220. rcChild.right= rcChild.left + width / 6;
  221. m_wndAddDelFriendBtn.MoveWindow(&rcChild);
  222. //3
  223. rcChild.left = rcChild.right;
  224. rcChild.right= rcChild.left + width / 6 - 10;
  225. m_wndRefUsrsBtn.MoveWindow(&rcChild);
  226. //4
  227. rcChild.left = rcChild.right;
  228. rcChild.right= rcChild.left + width / 6 + 10;
  229. m_wndBroadcastBtn.MoveWindow(&rcChild);
  230. //chat contents output richedit window.
  231. rcChild = rcParent;
  232. rcChild.top   += (HEIGHT_TIPINFO + 1);
  233. rcChild.right -= ((rcParent.Width() * WIDTH_OUTLOOKBAR / 100) - 2);
  234. rcChild.right -= GetSystemMetrics(SM_CXBORDER);
  235. rcChild.bottom= rcChild.top + ((rcParent.Height() - HEIGHT_TIPINFO)* HEIGHT_REOUTPUT / 100);
  236. m_wndREChatOutput.MoveWindow(&rcChild);
  237. //chat contents input window.
  238. rcChild.top = rcChild.bottom + 2;
  239. rcChild.bottom = rcChild.top + ((rcParent.Height() - HEIGHT_EDINPUT) * HEIGHT_EDINPUT / 100) - 2;
  240. rcChild.right -= GetSystemMetrics(SM_CXBORDER);
  241. m_wndEDChatInput.MoveWindow(&rcChild);
  242. //chating users outlook-bar window.
  243. rcChild = rcParent;
  244. rcChild.left = rcChild.right - (rcParent.Width() * WIDTH_OUTLOOKBAR / 100) + 2;
  245. rcChild.right -= 1;
  246. m_wndUsersBar.MoveWindow(&rcChild);
  247. return ;
  248. }
  249. void CChatPanelBar::OnInputChatMsgOver(WPARAM wparam, LPARAM lparam)
  250. {
  251. CString strContents;
  252. this->m_wndEDChatInput.GetWindowText(strContents);
  253. CHATINGPACKAGE cpg;
  254. memset(&cpg, 0x0, sizeof(cpg));
  255. sprintf(cpg.pktype, "%*d", SIZE_PKTYPE, CPT_MSGTXT);
  256. sprintf(cpg.agentid, "%*d", SIZE_AGENTID, theApp.m_oCSHelper.GetClientID());
  257. sprintf(cpg.headportrait, "%*d", SIZE_HADPTRT, this->GetUserHeadportrait());
  258. _snprintf(cpg.buf, sizeof(cpg.buf) - 1, "%s", strContents.GetBuffer(0));
  259. if(this->m_nchatingAgent != -1)
  260. {
  261. std::string strName, strIp;
  262. if(this->GetAgentNameIpInfo(m_nchatingAgent, strName, strIp))
  263. {
  264. SOCKADDR_IN from;
  265. CHATINGPACKAGE cpgResponse;
  266. this->m_udpclt.Write(strIp.c_str(), (char*)&cpg, sizeof(cpg));
  267. this->m_udpclt.Read(from, (char*)&cpgResponse, sizeof(cpgResponse));
  268. this->m_wndREChatOutput.AppendText(
  269. "to",
  270. strName.c_str(),
  271. strContents.GetBuffer(0));
  272. this->m_wndEDChatInput.SetWindowText("");
  273. this->m_wndEDChatInput.SetFocus();
  274. }
  275. }
  276. else
  277. {
  278. MSGBOX_INFO(_LoadString(IDS_CHATPLSELTOUSR).GetBuffer(0));
  279. this->m_wndEDChatInput.SetFocus();
  280. return ;
  281. }
  282. }
  283. //chating users outlook-bar notify message handler.
  284. long CChatPanelBar::OnChatUsersBarNotify(WPARAM wParam, LPARAM lParam)
  285. {
  286. switch (wParam)
  287. {
  288. case NM_FOLDERCHANGE:
  289. {
  290. PlaySound(MAKEINTRESOURCE(IDR_FOLDERSOUND), 
  291. AfxGetResourceHandle(), 
  292. SND_RESOURCE | SND_ASYNC | SND_NODEFAULT);
  293. if((int)lParam == 0)
  294. {
  295. this->m_wndBroadcastBtn.SetText(_LoadString(IDS_CHATBROADCASTOALLBTNTXT));
  296. this->m_wndBroadcastBtn.SetFontColor(RGB(255, 0, 0));
  297. }
  298. else if(int(lParam) == 1)
  299. {
  300. this->m_wndBroadcastBtn.SetText(_LoadString(IDS_CHATBROADCASTOGROUPBTNTXT));
  301. this->m_wndBroadcastBtn.SetFontColor(RGB(0, 0, 255));
  302. }
  303. this->m_wndBroadcastBtn.Invalidate();
  304. }
  305. return 1;
  306. case NM_OB_ITEMCLICK:
  307. {
  308. //cast the lParam to an integer to get the clicked item
  309. int index = (int)lParam;
  310. int nfolderindex = this->m_wndUsersBar.GetSelFolder();
  311. if(nfolderindex == 0 || nfolderindex == 1)
  312. {
  313. DWORD dwdata = this->m_wndUsersBar.GetFolderItemData(nfolderindex, index);
  314. this->m_nchatingAgent = HIWORD(dwdata);
  315. CString strtipinfo;
  316. strtipinfo.Format("%s :         %s", 
  317. _LoadString(IDS_CHATBARTITLE).GetBuffer(0),
  318. m_wndUsersBar.GetFolderItemText(nfolderindex, index));
  319. this->m_wndTipInfo.SetText(strtipinfo.GetBuffer(0));
  320. this->UpdateAddDelFriendBtnCaption();
  321. this->m_wndEDChatInput.SetFocus();
  322. }
  323. }
  324. return 0;
  325. case NM_OB_ONLABELENDEDIT:
  326. {
  327. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited item
  328. // return 1 to do the change and 0 to cancel it
  329. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  330. }
  331. return 1;
  332. case NM_OB_ONGROUPENDEDIT:
  333. {
  334. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited folder
  335. // return 1 to do the change and 0 to cancel it
  336. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  337. }
  338. return 1;
  339. case NM_OB_DRAGITEM:
  340. {
  341. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the dragged items
  342. // return 1 to do the change and 0 to cancel it
  343. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  344. }
  345. return 1;
  346. }
  347. return 0;
  348. }
  349. void CChatPanelBar::OnChatingMsg(WPARAM wparam, LPARAM lparam)
  350. {
  351. //get the chating package.
  352. char *pbuf = (char*)lparam;
  353. LPCHATINGPACKAGE pcp = (LPCHATINGPACKAGE)lparam;
  354. if(NULL == pbuf) return ;
  355. //get package type.
  356. int nPKType  = (pcp->pktype[0] - '0');
  357. switch(nPKType) {
  358. case CPT_LOGIN:
  359. case CPT_PROBE:
  360. ProcessClientLogon(pcp);
  361. break;
  362. case CPT_LOGOFF:
  363. ProcessClientLogoff(pcp);
  364. break;
  365. case CPT_MSGTXT:
  366. ProcessClientMsgtxt(pcp);
  367. break;
  368. }
  369. delete []pbuf;
  370. }
  371. //user states refreshing thread routine.
  372. DWORD CChatPanelBar::Routine_UserStateRef(LPVOID lpParameters)
  373. {
  374. ASSERT(lpParameters != NULL);
  375. CChatPanelBar *pthis = (CChatPanelBar*)lpParameters;
  376. for(; ::WaitForSingleObject(pthis->m_hUserStateRefThreadKillEvent, 0) == WAIT_TIMEOUT; )
  377. {
  378. for(int nFolder = 0; nFolder < pthis->m_wndUsersBar.GetFolderCount(); ++nFolder)
  379. {
  380. for(int nItem = 0; nItem < pthis->m_wndUsersBar.GetFolderItemCount(nFolder); ++nItem)
  381. {
  382. DWORD dwdata = pthis->m_wndUsersBar.GetFolderItemData(nFolder, nItem);
  383. int nAgentId = HIWORD(dwdata);
  384. WORD wHeadportraitIndex = LOWORD(dwdata);
  385. int nNormalImgIndex = 0, nDisableImgIndex = 0;
  386. pthis->m_wndUsersBar.GetImageIndex(wHeadportraitIndex, nNormalImgIndex, nDisableImgIndex);
  387. int nitemimgindex = pthis->m_wndUsersBar.GetFolderItemImage(nFolder, nItem);
  388. BOOL bIsMyFriend = pthis->InFriendsGroup(nAgentId);
  389. if(pthis->AgentIsOnline(nAgentId))
  390. {
  391. if(nitemimgindex != nNormalImgIndex)
  392. {
  393. if(bIsMyFriend)
  394. pthis->m_wndUsersBar.SetFolderItemImage(nFolder, nItem, nNormalImgIndex);
  395. else
  396. pthis->m_wndUsersBar.RemoveFolderItem(nFolder, nItem);
  397. }
  398. }
  399. else
  400. {
  401. if(nitemimgindex != nDisableImgIndex)
  402. {
  403. if(bIsMyFriend)
  404. pthis->m_wndUsersBar.SetFolderItemImage(nFolder, nItem, nDisableImgIndex);
  405. else
  406. pthis->m_wndUsersBar.RemoveFolderItem(nFolder, nItem);
  407. }
  408. }
  409. }
  410. }
  411. Sleep(6000);
  412. }
  413. return 0;
  414. }
  415. //broadcast working thread.
  416. DWORD CChatPanelBar::Routine_BroadcastMsg(LPVOID lpParameters)
  417. {
  418. ASSERT(lpParameters != NULL);
  419. int  nconlens = 0;
  420. char *pcontents = NULL;
  421. SOCKADDR_IN from;
  422. CHATINGPACKAGE cpg, cpgResponse;
  423. CChatPanelBar *pthis = (CChatPanelBar*)lpParameters;
  424. memset(&cpg, 0x0, sizeof(cpg));
  425. sprintf(cpg.pktype, "%*d", SIZE_PKTYPE, CPT_MSGTXT);
  426. sprintf(cpg.agentid, "%*d", SIZE_AGENTID, theApp.m_oCSHelper.GetClientID());
  427. sprintf(cpg.headportrait, "%*d", SIZE_HADPTRT, pthis->GetUserHeadportrait());
  428. for(; ::WaitForSingleObject(pthis->m_hBroadcastWorkThreadKillEvent, 0) == WAIT_TIMEOUT; )
  429. {
  430. if(::WaitForSingleObject(pthis->m_hBroadcastEvent, 10) == WAIT_TIMEOUT) continue;
  431. nconlens = pthis->m_wndEDChatInput.GetWindowTextLength();
  432. pcontents = new char[nconlens + 1];
  433. memset(pcontents, 0x0, nconlens + 1);
  434. pthis->m_wndEDChatInput.GetWindowText(pcontents, nconlens);
  435. memset(cpg.buf, 0x0, sizeof(cpg.buf));
  436. _snprintf(cpg.buf, sizeof(cpg.buf) - 1, "%s", pcontents);
  437. int nFolder = pthis->m_wndUsersBar.GetSelFolder();
  438. if(nFolder == 0)
  439. {
  440. for(nFolder = 0; nFolder < pthis->m_wndUsersBar.GetFolderCount(); ++nFolder)
  441. {
  442. for(int nItem = 0; nItem < pthis->m_wndUsersBar.GetFolderItemCount(nFolder); ++nItem)
  443. {
  444. DWORD dwdata = pthis->m_wndUsersBar.GetFolderItemData(nFolder, nItem);
  445. int nAgentId = HIWORD(dwdata);
  446. std::string strName, strIp;
  447. if(pthis->GetAgentNameIpInfo(nAgentId, strName, strIp))
  448. {
  449. pthis->m_udpclt.Write(strIp.c_str(), (char*)&cpg, sizeof(cpg));
  450. pthis->m_udpclt.Read(from, (char*)&cpgResponse, sizeof(cpgResponse));
  451. }
  452. }
  453. }
  454. }
  455. else if(nFolder == 1)
  456. {
  457. for(int nItem = 0; nItem < pthis->m_wndUsersBar.GetFolderItemCount(nFolder); ++nItem)
  458. {
  459. DWORD dwdata = pthis->m_wndUsersBar.GetFolderItemData(nFolder, nItem);
  460. int nAgentId = HIWORD(dwdata);
  461. std::string strName, strIp;
  462. if(pthis->GetAgentNameIpInfo(nAgentId, strName, strIp))
  463. {
  464. pthis->m_udpclt.Write(strIp.c_str(), (char*)&cpg, sizeof(cpg));
  465. pthis->m_udpclt.Read(from, (char*)&cpgResponse, sizeof(cpgResponse));
  466. }
  467. }
  468. }
  469. //free the memory space.
  470. delete []pcontents;
  471. pcontents = NULL;
  472. }
  473. return 0;
  474. }
  475. BOOL CChatPanelBar::GetAgentNameIpInfo(const int nAgentId, 
  476.    std::string &strName, 
  477.    std::string &strIp)
  478. {
  479. //get the user basic information.
  480. CGuiRecordSet rsu;
  481. CVariantEx varex;
  482. char sql[MAX_SQL_SIZE];
  483. strName.erase();
  484. strIp.erase();
  485. try
  486. {
  487. if(nAgentId < 1) return FALSE;
  488. //find all first level departs' info
  489. _snprintf(sql, MAX_SQL_SIZE - 1, SQL::SERVER_GET_AGENTINFO_FRMID, nAgentId);
  490. if(!rsu.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
  491. {
  492. //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
  493. return FALSE;
  494. }
  495. rsu.MoveFirst();
  496. if(!rsu.IsEof())
  497. {
  498. rsu.GetCollect("name", varex.get_variant_t());
  499. strName = varex.AsString();
  500. if(strName.empty())
  501. {
  502. rsu.GetCollect("hostname", varex.get_variant_t());
  503. strName = varex.AsString();
  504. if(strName.empty())
  505. {
  506. rsu.GetCollect("ipaddr", varex.get_variant_t());
  507. strName = varex.AsString();
  508. strIp = varex.AsString();
  509. if(strName.empty()) return FALSE;
  510. }
  511. }
  512. rsu.GetCollect("ipaddr", varex.get_variant_t());
  513. strIp = varex.AsString();
  514. if(strIp.empty()) return FALSE;
  515. return TRUE;
  516. }
  517. }
  518. catch(_com_error e) 
  519. {
  520. //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED));
  521. return FALSE;
  522. }
  523. return FALSE;
  524. }
  525. BOOL CChatPanelBar::AgentIsOnline(const int nAgentid)
  526. {
  527. std::string strName, strIp;
  528. if(!this->GetAgentNameIpInfo(nAgentid, strName, strIp)) return FALSE;
  529. SOCKADDR_IN from;
  530. CHATINGPACKAGE cpg;
  531. memset(&cpg, 0x0, sizeof(cpg));
  532. sprintf(cpg.pktype, "%*d", SIZE_PKTYPE, CPT_PROBE);
  533. sprintf(cpg.agentid, "%*d", SIZE_AGENTID, nAgentid);
  534. sprintf(cpg.headportrait, "%*d", SIZE_HADPTRT, 0);
  535. CHATINGPACKAGE cpgResponse;
  536. m_udpclt.Write(strIp.c_str(), NULL, 0);
  537. return (m_udpclt.Read(from, (char*)&cpgResponse, sizeof(cpgResponse)) > 0);
  538. }
  539. BOOL CChatPanelBar::GetAgentFolderItemIndex(const int nAgentId, int &nFolderIndex, int &nItemIndex)
  540. {
  541. for(int nFolder = 0; nFolder < this->m_wndUsersBar.GetFolderCount(); ++nFolder)
  542. {
  543. for(int nItem = 0; nItem < this->m_wndUsersBar.GetFolderItemCount(nFolder); ++nItem)
  544. {
  545. DWORD dwdata = this->m_wndUsersBar.GetFolderItemData(nFolder, nItem);
  546. if(HIWORD(dwdata) == nAgentId)
  547. {
  548. nFolderIndex = nFolder;
  549. nItemIndex = nItem;
  550. return TRUE;
  551. }
  552. }
  553. }
  554. return FALSE;
  555. }
  556. void CChatPanelBar::ProcessClientLogon(LPCHATINGPACKAGE pcp)
  557. {
  558. if(!pcp) return ;
  559. int nItemIndex = -1;
  560. int nAgentId = atoi(pcp->agentid);
  561. int nHeadportrait = atoi(pcp->headportrait);
  562. int nNormalImgIndex = 0, nDisableImgIndex = 0;
  563. bool bneedsoundnotify = false;
  564. std::string strname, strip;
  565. //filter self.
  566. if(theApp.m_oCSHelper.GetClientID() == nAgentId) return ;
  567. this->m_wndUsersBar.GetImageIndex(nHeadportrait, nNormalImgIndex, nDisableImgIndex);
  568. //update agent state that in all folder window.
  569. if(this->InFriendsGroup(nAgentId))
  570. {
  571. if(this->m_wndUsersBar.ExistsAgent(1, nAgentId, nItemIndex))
  572. {
  573. //if exists this user then change the user's state(hot image).
  574. this->m_wndUsersBar.SetItemImage(nItemIndex, nNormalImgIndex);
  575. bneedsoundnotify = true;
  576. }
  577. else
  578. {
  579. if(this->GetAgentNameIpInfo(nAgentId, strname, strip))
  580. {
  581. int index = this->m_wndUsersBar.GetFolderItemCount(1);
  582. this->m_wndUsersBar.InsertItem(1, index, strname.c_str(), 
  583. nNormalImgIndex, MAKELONG(nHeadportrait, nAgentId));
  584. bneedsoundnotify = true;
  585. }
  586. }
  587. }
  588. else
  589. {
  590. if(!this->m_wndUsersBar.ExistsAgent(0, nAgentId, nItemIndex))
  591. {
  592. if(this->GetAgentNameIpInfo(nAgentId, strname, strip))
  593. {
  594. int index = this->m_wndUsersBar.GetFolderItemCount(0);
  595. this->m_wndUsersBar.InsertItem(0, index, strname.c_str(), 
  596. nNormalImgIndex, MAKELONG(nHeadportrait, nAgentId));
  597. bneedsoundnotify = true;
  598. }
  599. }
  600. else
  601. {
  602. this->m_wndUsersBar.SetItemImage(nItemIndex, nNormalImgIndex);
  603. }
  604. }
  605. //sound notify.
  606. if(bneedsoundnotify)
  607. PlaySound(MAKEINTRESOURCE(IDR_GOLINESOUND), AfxGetResourceHandle(),
  608. SND_RESOURCE | SND_ASYNC | SND_NODEFAULT);
  609. }
  610. void CChatPanelBar::ProcessClientLogoff(LPCHATINGPACKAGE pcp)
  611. {
  612. if(!pcp) return ;
  613. int nItemIndex = -1;
  614. int nAgentId = atoi(pcp->agentid);
  615. int nHeadportrait = atoi(pcp->headportrait);
  616. int nNormalImgIndex = 0, nDisableImgIndex = 0;
  617. this->m_wndUsersBar.GetImageIndex(nHeadportrait, nNormalImgIndex, nDisableImgIndex);
  618. //update agent state that in all folder window.(disable)
  619. if(this->m_wndUsersBar.ExistsAgent(0, nAgentId, nItemIndex))
  620. {
  621. //if exists this user then delete the from 0 folder.
  622. this->m_wndUsersBar.RemoveFolderItem(0, nItemIndex);
  623. }
  624. //
  625. if(this->m_wndUsersBar.ExistsAgent(1, nAgentId, nItemIndex))
  626. {
  627. //if exists this user then change the user's state(hot image).
  628. this->m_wndUsersBar.SetFolderItemImage(1, nItemIndex, nDisableImgIndex);
  629. }
  630. }
  631. void CChatPanelBar::ProcessClientMsgtxt(LPCHATINGPACKAGE pcp)
  632. {
  633. if(!pcp) return ;
  634. int nAgentId = atoi(pcp->agentid);
  635. int nHeadportrait = atoi(pcp->headportrait);
  636. int nFolderIndex = -1, nItemIndex = -1;
  637. this->m_ncurmsgagent = nAgentId;
  638. //sound notify.
  639. PlaySound(MAKEINTRESOURCE(IDR_MSGSOUND), 
  640. AfxGetResourceHandle(),
  641. SND_RESOURCE | SND_ASYNC | SND_NODEFAULT);
  642. if(this->GetAgentFolderItemIndex(nAgentId, nFolderIndex, nItemIndex))
  643. {
  644. if(nFolderIndex != this->m_wndUsersBar.GetSelFolder())
  645. this->m_wndUsersBar.SetSelFolder(nFolderIndex);
  646. }
  647. //if "this" window is unactive then open sound or 
  648. //tip window notifying function.
  649. if(!this->IsWindowVisible())
  650. {
  651. //Load setting from registry
  652. CRegister regKey;
  653. if(regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
  654. {
  655. DWORD dwValue = regKey.Read_DWord_Value(REG_NMSGNOTIFYTYPE);
  656. regKey.Close();
  657. if(dwValue != 2)
  658. {
  659. this->m_wndTaskbar.Show((char*)pcp->buf);
  660. }
  661. }
  662. }
  663. //display message in message output window.(RE)
  664. std::string strName, strIp;
  665. if(this->GetAgentNameIpInfo(nAgentId, strName, strIp))
  666. {
  667. m_wndREChatOutput.AppendText("from", strName.c_str(), (char*)pcp->buf);
  668. }
  669. }
  670. BOOL CChatPanelBar::LogonChatingRoom(void)
  671. {
  672. //get the user basic information.
  673. CGuiRecordSet rsu;
  674. CVariantEx varex;
  675. std::string strIp;
  676. int nAgentId,
  677. nItemIndex;
  678. char sql[MAX_SQL_SIZE];
  679. CHATINGPACKAGE cpgResponse;
  680. try
  681. {
  682. //find all agents' info
  683. _snprintf(sql, MAX_SQL_SIZE - 1, SQL::SERVER_AGENT_GETALL, -1);
  684. if(!rsu.Open(theApp.m_oAppInstance.m_adoconn.GetConecction(), sql))
  685. {
  686. //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED).GetBuffer(0));
  687. return FALSE;
  688. }
  689. //make the package.
  690. SOCKADDR_IN from;
  691. CHATINGPACKAGE cpg;
  692. sprintf(cpg.pktype, "%*d", SIZE_PKTYPE, CPT_LOGIN);
  693. sprintf(cpg.agentid, "%*d", SIZE_AGENTID, theApp.m_oCSHelper.GetClientID());
  694. sprintf(cpg.headportrait, "%*d", SIZE_HADPTRT, this->GetUserHeadportrait());
  695. for(rsu.MoveFirst(); !rsu.IsEof(); rsu.MoveNext())
  696. {
  697. rsu.GetCollect("id", varex.get_variant_t());
  698. nAgentId = varex.AsInteger();
  699. if(theApp.m_oCSHelper.GetClientID() == nAgentId) continue;
  700. rsu.GetCollect("ipaddr", varex.get_variant_t());
  701. strIp = varex.AsString();
  702. if(strIp.empty()) continue;
  703. if(m_udpclt.Write(strIp.c_str(), (char*)&cpg, sizeof(cpg)) == sizeof(cpg))
  704. {
  705. memset(&cpgResponse, 0x0, sizeof(cpgResponse));
  706. if(m_udpclt.Read(from, (char*)&cpgResponse, sizeof(cpgResponse)) == sizeof(cpgResponse))
  707. {
  708. //update agent state that in all folder window.
  709. int nNormalImgIndex = 0, nDisableImgIndex = 0;
  710. int nHeadportrait = atoi((char*)cpgResponse.headportrait);
  711. this->m_wndUsersBar.GetImageIndex(nHeadportrait, nNormalImgIndex, nDisableImgIndex);
  712. if(this->InFriendsGroup(nAgentId))
  713. {
  714. if(this->m_wndUsersBar.ExistsAgent(1, nAgentId, nItemIndex))
  715. {
  716. //if exists this user then change the user's state(hot image).
  717. this->m_wndUsersBar.SetItemImage(nItemIndex, nNormalImgIndex);
  718. }
  719. }
  720. else
  721. {
  722. if(!this->m_wndUsersBar.ExistsAgent(0, nAgentId, nItemIndex))
  723. {
  724. int index = this->m_wndUsersBar.GetFolderItemCount(0);
  725. std::string strname, strip;
  726. if(this->GetAgentNameIpInfo(nAgentId, strname, strip))
  727. {
  728. this->m_wndUsersBar.InsertItem(0, index, strname.c_str(), 
  729. nNormalImgIndex, MAKELONG(nHeadportrait, nAgentId));
  730. }
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. catch(_com_error e) 
  738. {
  739. //MSGBOX_ERROR(_LoadString(IDS_DBOPERFAILED));
  740. return FALSE;
  741. }
  742. return TRUE;
  743. }
  744. int CChatPanelBar::GetUDPPort(void)
  745. {
  746. CRegister regkey;
  747. DWORD dwUDPort;
  748. //read the UDP server listening port.
  749. if(!regkey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY)) return false;
  750. dwUDPort = regkey.Read_DWord_Value(REG_NCHATUDPPORT);
  751. regkey.Close();
  752. //determine the UDP port whether is valid.
  753. if(dwUDPort < 1000 || dwUDPort > 65535) dwUDPort = 5558;
  754. return dwUDPort;
  755. }
  756. int CChatPanelBar::GetUserHeadportrait(void)
  757. {
  758. //Load setting from registry
  759. CRegister regKey;
  760. if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
  761. {
  762. TRACE0("Failed to open the registry keyn");
  763. return -1;
  764. }
  765. //Integer
  766. DWORD dwValue = regKey.Read_DWord_Value(REG_NHEADBMPINDEX);
  767. return dwValue;
  768. }
  769. BOOL CChatPanelBar::InFriendsGroup(const int nAgentId)
  770. {
  771. CArray<DWORD, DWORD> arrMyfriends;
  772. if(this->GetMyFriendsList(arrMyfriends))
  773. {
  774. DWORD dwdata = 0x0000;
  775. for(int index = 0; index < arrMyfriends.GetSize(); ++index)
  776. {
  777. dwdata = arrMyfriends[index];
  778. if(HIWORD(dwdata) == nAgentId) return TRUE;
  779. }
  780. }
  781. return FALSE;
  782. }
  783. void CChatPanelBar::OnChatStartLogon(WPARAM wparam, LPARAM lparam)
  784. {
  785. this->LogonChatingRoom();
  786. }
  787. LRESULT CChatPanelBar::OnTaskbarNotifierClicked(WPARAM wParam, LPARAM lParam)
  788. {
  789. if(this->m_ncurmsgagent != -1)
  790. {
  791. this->m_nchatingAgent = this->m_ncurmsgagent;
  792. this->UpdateAddDelFriendBtnCaption();
  793. }
  794. return 0;
  795. }
  796. void CChatPanelBar::OnStaticClickedMsg(WPARAM wparam, LPARAM lparam)
  797. {
  798. HWND hfromWnd = (HWND)wparam;
  799. if(hfromWnd == this->m_wndTipInfo.GetSafeHwnd())
  800. {
  801. std::string strName, strIp;
  802. if( this->m_nchatingAgent != -1 &&
  803. this->GetAgentNameIpInfo(this->m_nchatingAgent, strName, strIp))
  804. {
  805. CString strTipInfo;
  806. strTipInfo.Format("Current Chating Username : %s nHost Ip : %s", 
  807. strName.c_str(), strIp.c_str());
  808. MSGBOX_INFO(strTipInfo.GetBuffer(0));
  809. }
  810. }
  811. else if(hfromWnd == this->m_wndRefUsrsBtn.GetSafeHwnd())
  812. {
  813. CString strlogfile;
  814. if(this->GetChatingLogfile(strlogfile) && FileExists(strlogfile.GetBuffer(0)))
  815. {
  816. ShellExecute(this->GetSafeHwnd(), "open", 
  817. strlogfile.GetBuffer(0), NULL, NULL, SW_MAXIMIZE);
  818. }
  819. else
  820. {
  821. MSGBOX_ERROR(_LoadString(IDS_CHATOPENLOGFILEFAILED).GetBuffer(0));
  822. return ;
  823. }
  824. }
  825. else if(hfromWnd == this->m_wndAddDelFriendBtn.GetSafeHwnd())
  826. {
  827. DWORD exdata = this->m_wndAddDelFriendBtn.m_exData;
  828. int nfolderindex = this->m_wndUsersBar.GetSelFolder();
  829. if(this->m_nchatingAgent != -1)
  830. {
  831. int nitemindex = -1;
  832. std::string strName, strIp;
  833. //add friend.
  834. if(exdata == 0)
  835. {
  836. if( this->m_wndUsersBar.ExistsAgent(0, m_nchatingAgent, nitemindex) &&
  837. !this->m_wndUsersBar.ExistsAgent(1, m_nchatingAgent, nitemindex) &&
  838. this->GetAgentNameIpInfo(m_nchatingAgent, strName, strIp))
  839. {
  840. int nimgindex= this->m_wndUsersBar.GetFolderItemImage(0, nitemindex);
  841. DWORD dwdata = this->m_wndUsersBar.GetFolderItemData(0, nitemindex);
  842. this->m_wndUsersBar.RemoveFolderItem(0, nitemindex);
  843. this->m_wndUsersBar.InsertItem(1, 0, strName.c_str(), nimgindex, dwdata);
  844. this->AddMyFriend(dwdata);
  845. }
  846. else
  847. {
  848. MSGBOX_INFO(_LoadString(IDS_CHATUSRINFRIEND).GetBuffer(0));
  849. this->m_wndEDChatInput.SetFocus();
  850. return ;
  851. }
  852. }
  853. //delete friend.
  854. else if(exdata == 1)
  855. {
  856. if( this->m_wndUsersBar.ExistsAgent(1, m_nchatingAgent, nitemindex) &&
  857. !this->m_wndUsersBar.ExistsAgent(0, m_nchatingAgent, nitemindex) &&
  858. this->GetAgentNameIpInfo(m_nchatingAgent, strName, strIp))
  859. {
  860. int nimgindex= this->m_wndUsersBar.GetFolderItemImage(1, nitemindex);
  861. DWORD dwdata = this->m_wndUsersBar.GetFolderItemData(1, nitemindex);
  862. int   nNormalImgIndex, nDisableImgIndex;
  863. this->m_wndUsersBar.GetImageIndex(LOWORD(dwdata), 
  864. nNormalImgIndex, nDisableImgIndex);
  865. //if this user is online then add it into first folder.
  866. if(nNormalImgIndex == nimgindex)
  867. {
  868. this->m_wndUsersBar.InsertItem(0, 0, strName.c_str(), nimgindex, dwdata);
  869. }
  870. this->m_wndUsersBar.RemoveFolderItem(1, nitemindex);
  871. this->DeleteMyFriend(m_nchatingAgent);
  872. }
  873. else
  874. {
  875. MSGBOX_INFO(_LoadString(IDS_CHATUSRINFRIEND).GetBuffer(0));
  876. this->m_wndEDChatInput.SetFocus();
  877. return ;
  878. }
  879. }
  880. }
  881. }
  882. else if(hfromWnd == this->m_wndBroadcastBtn.GetSafeHwnd())
  883. {
  884. int nfolderindex = this->m_wndUsersBar.GetSelFolder();
  885. if(nfolderindex == 0)
  886. {
  887. if(!MSGBOX_CONFIRM(_LoadString(IDS_CHATBROADCASTOALLSURE).GetBuffer(0)))
  888. return ;
  889. }
  890. else if(nfolderindex == 1)
  891. {
  892. if(!MSGBOX_CONFIRM(_LoadString(IDS_CHATBROADCASTOFRDSURE).GetBuffer(0)))
  893. return ;
  894. }
  895. ::SetEvent(this->m_hBroadcastEvent);
  896. }
  897. }
  898. BOOL CChatPanelBar::AddMyFriend(DWORD dwItemData)
  899. {
  900. CRegister regKey;
  901. if(regKey.Open(HKEY_CURRENT_USER, REG_SCHATFRNDSKEY))
  902. {
  903. CString stridentity;
  904. stridentity.Format("%d", dwItemData);
  905. return regKey.Write_DWord_Value(stridentity.GetBuffer(0), dwItemData);
  906. }
  907. return FALSE;
  908. }
  909. BOOL CChatPanelBar::DeleteMyFriend(const int nAgentId)
  910. {
  911. CRegister regKey;
  912. if(regKey.Open(HKEY_CURRENT_USER, REG_SCHATFRNDSKEY))
  913. {
  914. DWORD cbValueName = 0, dwType = 0,
  915. dwData = 0, cbData = 0;
  916. const int VALUENAME_SIZE = 32;
  917. char *lpValueName = new char[VALUENAME_SIZE];
  918. for(int index = 0; index < 1000; ++index)
  919. {
  920. cbValueName = VALUENAME_SIZE;
  921. //if this value's type is REG_DWORD.
  922. LONG lRet = ::RegEnumValue(regKey.Get_CurrentKey(), index, 
  923. lpValueName, &cbValueName, NULL, &dwType, NULL, NULL);
  924. if(lRet != ERROR_SUCCESS)
  925. {
  926. delete []lpValueName;
  927. return (lRet == ERROR_NO_MORE_ITEMS);
  928. }
  929. if(dwType == REG_DWORD)
  930. {
  931. lRet = ::RegEnumValue(regKey.Get_CurrentKey(), index, 
  932. lpValueName, &cbValueName, NULL, &dwType, 
  933. (LPBYTE)&dwData, &cbData);
  934. if(lRet != ERROR_SUCCESS)
  935. {
  936. delete []lpValueName;
  937. return FALSE;
  938. }
  939. if(HIWORD(dwData) == nAgentId)
  940. {
  941. regKey.DeleteValue(lpValueName);
  942. break;
  943. }
  944. }
  945. }
  946. delete []lpValueName;
  947. return TRUE;
  948. }
  949. return FALSE;
  950. }
  951. BOOL CChatPanelBar::GetMyFriendsList(CArray<DWORD, DWORD> &arrMyfriends)
  952. {
  953. CRegister regKey;
  954. arrMyfriends.RemoveAll();
  955. if(regKey.Open(HKEY_CURRENT_USER, REG_SCHATFRNDSKEY))
  956. {
  957. const VALUENAME_SIZE = 32;
  958. DWORD cbValueName = 0, dwType = 0, 
  959. dwData = 0, cbData = 0;
  960. char *lpValueName = new char[VALUENAME_SIZE];
  961. for(int index = 0; index < 1000; ++index)
  962. {
  963. cbValueName = cbData = VALUENAME_SIZE;
  964. //if this value's type is REG_DWORD.
  965. LONG lRet = ::RegEnumValue(regKey.Get_CurrentKey(), index, 
  966. lpValueName, &cbValueName, NULL, &dwType, NULL, NULL);
  967. if(lRet != ERROR_SUCCESS)
  968. {
  969. delete []lpValueName;
  970. return (lRet == ERROR_NO_MORE_ITEMS);
  971. }
  972. if(dwType == REG_DWORD)
  973. {
  974. cbValueName = cbData = VALUENAME_SIZE;
  975. lRet = ::RegEnumValue(regKey.Get_CurrentKey(), index, 
  976. lpValueName, &cbValueName, NULL, &dwType, 
  977. (LPBYTE)&dwData, &cbData);
  978. if(lRet != ERROR_SUCCESS)
  979. {
  980. delete []lpValueName;
  981. return FALSE;
  982. }
  983. arrMyfriends.Add(dwData);
  984. }
  985. }
  986. delete []lpValueName;
  987. return TRUE;
  988. }
  989. return FALSE;
  990. }
  991. void CChatPanelBar::UpdateAddDelFriendBtnCaption(void)
  992. {
  993. if(!this->InFriendsGroup(this->m_nchatingAgent))
  994. this->m_wndAddDelFriendBtn.SetText(_LoadString(IDS_CHATADDFRIEND));
  995. else
  996. this->m_wndAddDelFriendBtn.SetText(_LoadString(IDS_CHATDELFRIEND));
  997. this->m_wndAddDelFriendBtn.m_exData ^= 1;
  998. }
  999. void CChatPanelBar::InitMyFriendsFolder(void)
  1000. {
  1001. CArray<DWORD, DWORD> arrMyfriends;
  1002. int nNormalImgIndex = 0, nDisableImgIndex = 0;
  1003. if(this->GetMyFriendsList(arrMyfriends))
  1004. {
  1005. DWORD dwdata = 0x0000;
  1006. WORD  wAgentId = 0, wHeadportraitIndex = 0;
  1007. std::string strName, strIp;
  1008. for(int index = 0; index < arrMyfriends.GetSize(); ++index)
  1009. {
  1010. dwdata = arrMyfriends[index];
  1011. wAgentId = HIWORD(dwdata);
  1012. wHeadportraitIndex = LOWORD(dwdata);
  1013. if( this->m_wndUsersBar.GetImageIndex(wHeadportraitIndex, nNormalImgIndex, nDisableImgIndex) &&
  1014. this->GetAgentNameIpInfo(wAgentId, strName, strIp))
  1015. this->m_wndUsersBar.InsertItem(1, index, strName.c_str(), nDisableImgIndex, dwdata);
  1016. }
  1017. }
  1018. }
  1019. //get chating logfile.
  1020. BOOL CChatPanelBar::GetChatingLogfile(CString &strLogfile)
  1021. {
  1022. //Load setting from registry
  1023. CRegister regKey;
  1024. strLogfile.Empty();
  1025. if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
  1026. {
  1027. TRACE0("Failed to open the registry keyn");
  1028. return FALSE;
  1029. }
  1030. strLogfile = regKey.Read_String_Value(REG_STRCHATLOGFILE);
  1031. strLogfile.TrimLeft();
  1032. strLogfile.TrimRight();
  1033. return TRUE;
  1034. }