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

ICQ/即时通讯

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "msg.h"
  5. #include "Client.h"
  6. #include "lookdlg.h"
  7. #include "talkdlg.h"
  8. #include "frienddetail.h"
  9. #include "modifypidlg.h"
  10. #include "searchdlg.h"
  11. #include "SendToalldlg.h"
  12. #include "multisenddlg.h"
  13. #include "ShowOnlinedlg.h"
  14. #include "SendBroadcastDlg.h"
  15. #include "ShowAddMsgDlg.h"
  16. #include "ShowBroadcastDlg.h"
  17. #include "addfrienddlg.h"
  18. #include "MainFrm.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMainFrame
  26. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  27. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  28. //{{AFX_MSG_MAP(CMainFrame)
  29. ON_WM_CREATE()
  30. ON_WM_SETFOCUS()
  31. ON_WM_GETMINMAXINFO()
  32. ON_WM_CLOSE()
  33. ON_WM_TIMER()
  34. ON_COMMAND(ID_SEND_MESSAGE, OnSendMessage)
  35. ON_UPDATE_COMMAND_UI(ID_SEND_MESSAGE, OnUpdateSendMessage)
  36. ON_COMMAND(ID_SEND_EMAIL, OnSendEmail)
  37. ON_UPDATE_COMMAND_UI(ID_SEND_EMAIL, OnUpdateSendEmail)
  38. ON_COMMAND(ID_FRIEND_DETAIL, OnFriendDetail)
  39. ON_COMMAND(ID_PERSON_HOMEPAGE, OnPersonHomepage)
  40. ON_UPDATE_COMMAND_UI(ID_PERSON_HOMEPAGE, OnUpdatePersonHomepage)
  41. ON_COMMAND(ID_OFFLINE, OnOffline)
  42. ON_COMMAND(ID_ONHIDE, OnOnhide)
  43. ON_COMMAND(ID_ONLINE, OnOnline)
  44. ON_COMMAND(ID_SEARCH, OnSearch)
  45. ON_COMMAND(ID_PERSONINFO_SETUP, OnPersoninfoSetup)
  46. ON_COMMAND(ID_MULTISEND, OnMultisend)
  47. ON_COMMAND(ID_SENDTO_ALL, OnSendtoAll)
  48. ON_COMMAND(ID_MESSAGE_MANAGE, OnMessageManage)
  49. ON_COMMAND(ID_SHOW_ONLINE, OnShowOnline)
  50. ON_COMMAND(ID_SEND_BROADCAST, OnSendBroadcast)
  51. ON_COMMAND(ID_ADD_FRIEND, OnAddFriend)
  52. //}}AFX_MSG_MAP
  53. ON_MESSAGE(WM_MY_TRAY_NOTIFICATION,OnTrayNotification)
  54. ON_MESSAGE(WM_HOTKEY,OnHotKey)
  55. ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify)
  56. ON_MESSAGE(WM_RECIEVE_MSG,ProcRecv)
  57. ON_MESSAGE(WM_ADDFRIEND_REFRESH,OnAddFriendRefresh)
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMainFrame construction/destruction
  61. CMainFrame::CMainFrame()
  62. {
  63. m_pSearch=NULL;
  64. m_pModifyPI=NULL;
  65. m_pMultiSend=NULL;
  66. m_pSendToAll=NULL;
  67. m_pShowOnline=NULL;
  68. m_pSendBroad=NULL;
  69. m_pShowNotice=NULL;
  70. m_pAddFriendDlg=NULL;
  71. m_bRecvTotal=FALSE;
  72. }
  73. CMainFrame::~CMainFrame()
  74. {
  75. }
  76. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  77. {
  78. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  79. return -1;
  80. DWORD dwf = CGfxOutBarCtrl::fDragItems|CGfxOutBarCtrl::fEditGroups|CGfxOutBarCtrl::fEditItems|CGfxOutBarCtrl::fRemoveGroups|
  81. CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fAnimation;
  82. m_wndBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this,AFX_IDW_PANE_FIRST, dwf);
  83. m_wndBar.SetOwner(this);
  84. m_wndBar.SetImageList(&GetApp()->m_imaLarge, CGfxOutBarCtrl::fLargeIcon);
  85. m_wndBar.SetImageList(&GetApp()->m_imaSmall, CGfxOutBarCtrl::fSmallIcon);
  86. m_wndBar.AddFolder("我的好友", 0);
  87. m_wndBar.AddFolder("陌生人", 1);
  88. m_wndBar.AddFolder("黑名单", 2);
  89. UserInfo* pInfo;
  90. CString str;
  91. for(int i=1;i<GetApp()->m_aUserInfo.GetSize();i++)
  92. {
  93. pInfo=GetApp()->m_aUserInfo.GetAt(i);
  94. if(pInfo->HaveDetail)
  95. m_wndBar.AddItem(0,pInfo->Name,pInfo->PhotoId,pInfo->Id);
  96. else
  97. {
  98. str.Format("%d",pInfo->Id);
  99. m_wndBar.AddItem(0,str,0,pInfo->Id);
  100. }
  101. }
  102. m_wndBar.SetSelFolder(0);
  103. BOOL result1=::RegisterHotKey(m_hWnd,1001,MOD_CONTROL|MOD_ALT,'X');
  104. BOOL result2=::RegisterHotKey(m_hWnd,1002,MOD_CONTROL|MOD_ALT,'x');
  105. BOOL result3=::RegisterHotKey(m_hWnd,1003,MOD_CONTROL|MOD_ALT,'m');
  106. BOOL result4=::RegisterHotKey(m_hWnd,1004,MOD_CONTROL|MOD_ALT,'M');
  107. if(!result1&&!result2&&!result3&&!result4)
  108. {
  109. //AfxMessageBox(IDS_HOTKEY_REG_FAIL);
  110. }
  111. m_TrayIcon.SetNotificationWnd(this,WM_MY_TRAY_NOTIFICATION);
  112. str=GetApp()->m_strCurUserDir;
  113. str=str.Left(str.GetLength()-1);
  114. m_TrayIcon.SetIcon(IDR_OFFLINE,str);
  115. str.Format("ID:%d",GetApp()->m_uCurrentUserID);
  116. SetWindowText(str);
  117. CMenu* pMenu=GetMenu();
  118. menu1.Attach(pMenu->GetSubMenu(0)->GetSafeHmenu());
  119. menu2.Attach(pMenu->GetSubMenu(1)->GetSafeHmenu());
  120. menu1.LoadToolBarResource(IDR_TOOLBAR1);
  121. menu2.LoadToolBarResource(IDR_TOOLBAR2);
  122. menu1.RemapMenu(&menu1);
  123. menu2.RemapMenu(&menu2);
  124. return 0;
  125. }
  126. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  127. {
  128. if( !CFrameWnd::PreCreateWindow(cs) )
  129. return FALSE;
  130. cs.dwExStyle|=WS_EX_TOOLWINDOW|WS_EX_TOPMOST;
  131. cs.lpszClass = AfxRegisterWndClass(0);
  132. cs.x=650;
  133. cs.y=50;
  134. cs.cx=90;
  135. cs.cy=500;
  136. return TRUE;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CMainFrame diagnostics
  140. #ifdef _DEBUG
  141. void CMainFrame::AssertValid() const
  142. {
  143. CFrameWnd::AssertValid();
  144. }
  145. void CMainFrame::Dump(CDumpContext& dc) const
  146. {
  147. CFrameWnd::Dump(dc);
  148. }
  149. #endif //_DEBUG
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CMainFrame message handlers
  152. void CMainFrame::OnSetFocus(CWnd* pOldWnd)
  153. {
  154. // forward focus to the view window
  155. m_wndBar.SetFocus();
  156. }
  157. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  158. {
  159. // let the view have first crack at the command
  160. if (m_wndBar.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  161. return TRUE;
  162. // otherwise, do default handling
  163. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  164. }
  165. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  166. {
  167. lpMMI->ptMinTrackSize.x = 90;
  168. lpMMI->ptMaxTrackSize.x=200;
  169. lpMMI->ptMinTrackSize.y=200;
  170. CFrameWnd::OnGetMinMaxInfo(lpMMI);
  171. }
  172. LRESULT CMainFrame::OnHotKey(WPARAM wParam,LPARAM lParam)
  173. {
  174. if (wParam== 1001||wParam==1002)
  175. {
  176. ShowWindow(SW_NORMAL); 
  177. SetForegroundWindow();
  178. return 1;
  179. }
  180. else if(wParam== 1003||wParam==1004)
  181. {
  182. SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,0);
  183. return 1;
  184. }
  185. return 0;
  186. }
  187. LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  188. {
  189. if(message==WM_SYSCOMMAND)
  190. {
  191. if(wParam==SC_MINIMIZE)
  192. {
  193. ShowWindow(SW_HIDE);
  194. return 0;
  195. }
  196. else if(wParam==SC_CLOSE)
  197. {
  198. ShowWindow(SW_HIDE);
  199. return 0;
  200. }
  201. }
  202. return CFrameWnd::WindowProc(message, wParam, lParam);
  203. }
  204. LRESULT CMainFrame::OnTrayNotification(WPARAM wp,LPARAM lp)
  205. {
  206. return m_TrayIcon.OnTrayNotification(wp,lp);
  207. }
  208. void CMainFrame::OnClose() 
  209. {
  210. ::UnregisterHotKey(m_hWnd,1001); 
  211. ::UnregisterHotKey(m_hWnd,1002); 
  212. ::UnregisterHotKey(m_hWnd,1003); 
  213. ::UnregisterHotKey(m_hWnd,1004); 
  214. CFrameWnd::OnClose();
  215. }
  216. LRESULT CMainFrame::OnOutbarNotify(WPARAM wParam, LPARAM lParam)
  217. {
  218. switch (wParam)
  219. {
  220. case NM_OB_ITEMCLICK:
  221. // cast the lParam to an integer to get the clicked item
  222. {
  223. nGroupFlag=m_wndBar.iSelFolder;
  224. nCurSelID = m_wndBar.GetItemData(lParam);
  225. nCurSelIndex=lParam;
  226. CMenu menu;
  227. CGfxPopupMenu cMenu;
  228. menu.LoadMenu(IDR_POPMENU);
  229. cMenu.Attach(menu.GetSubMenu(0)->GetSafeHmenu());
  230. if(nGroupFlag==1)
  231. {
  232. cMenu.AppendMenu(MF_STRING,ID_ADD_FRIEND,"加为好友");
  233. }
  234. cMenu.LoadToolBarResource(IDR_TOOLBAR3);
  235. cMenu.RemapMenu(&cMenu);
  236. CPoint mouse;
  237. GetCursorPos(&mouse);
  238. cMenu.TrackPopupMenu(TPM_LEFTALIGN,mouse.x,mouse.y,this);
  239. }
  240. return 1;
  241. case NM_OB_ITEMDCLICK:
  242. {
  243. nGroupFlag=m_wndBar.iSelFolder;
  244. nCurSelID = m_wndBar.GetItemData(lParam);
  245. nCurSelIndex=lParam;
  246. SendMessage(WM_COMMAND,ID_SEND_MESSAGE,0);
  247. }
  248. return 1;
  249. case NM_OB_ONLABELENDEDIT:
  250. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited item
  251. // return 1 to do the change and 0 to cancel it
  252. {
  253. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  254. //TRACE2("Editing item %d, new text:%sn", pOI->index, pOI->cText);
  255. }
  256. return 1;
  257. case NM_OB_ONGROUPENDEDIT:
  258. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited folder
  259. // return 1 to do the change and 0 to cancel it
  260. {
  261. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  262. TRACE2("Editing folder %d, new text:%sn", pOI->index, pOI->cText);
  263. }
  264. return 1;
  265. case NM_OB_DRAGITEM:
  266. // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the dragged items
  267. // return 1 to do the change and 0 to cancel it
  268. {
  269. OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam;
  270. TRACE2("Drag item %d at position %dn", pOI->iDragFrom, pOI->iDragTo);
  271. }
  272. return 1;
  273. }
  274. return 0;
  275. }
  276. LRESULT CMainFrame::ProcRecv(WPARAM wParam,LPARAM lParam)
  277. {
  278. CData* pData=(CData*)wParam;
  279. UINT index=pData->index;
  280. int & iOnlineState=GetApp()->m_bOnlineState;
  281. switch(index)
  282. {
  283. case SEND_MSG_TO_FRIEND:
  284. {
  285. //recv from friend or server
  286. if(iOnlineState==0)break;
  287. CMsg1 msg;
  288. CopyDataBuf(&msg,pData);
  289. if(!msg.LoadFromBuf())
  290. {
  291. TRACE0("msg.LoadFromBuf error!n");
  292. break;
  293. }
  294. int mindex=0;
  295. SaveMsg* pMsg=new SaveMsg;
  296. pMsg->type=NORMAL_MSG;
  297. pMsg->ID=msg.MyId;
  298. pMsg->Time=msg.Time;
  299. pMsg->Msg=msg.Msg;
  300. UserInfo *pInfo=NULL;
  301. FriendState *pState=NULL;
  302. if(FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,msg.MyId,pInfo,pState))
  303. {
  304. pState->aMsg.Add(pMsg);
  305. }
  306. else
  307. {
  308. // 陌生人
  309. if(FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,msg.MyId,pInfo,pState))
  310. {
  311. pState->aMsg.Add(pMsg);
  312. }
  313. else
  314. {
  315. pInfo=new UserInfo;
  316. pInfo->Id=msg.MyId;
  317. pInfo->HaveDetail=0;
  318. pState=new FriendState;
  319. pState->IP=msg.tarIP;
  320. pState->Port=msg.nPort;
  321. pState->OnlineState=1;
  322. pState->aMsg.Add(pMsg);
  323. GetApp()->m_aStranger.Add(pInfo);
  324. GetApp()->m_aStrangerState.Add(pState);
  325. GetApp()->m_aStranger.GetSize();
  326. CString str;
  327. str.Format("%d",pInfo->Id);
  328. m_wndBar.AddItem(1,str,0,pInfo->Id);
  329. m_wndBar.Invalidate();
  330. }
  331. }
  332. if(pState->pRecv==NULL)
  333. {
  334. pState->pRecv=new CLookDlg;
  335. pState->pRecv->Create(CLookDlg::IDD,GetDesktopWindow());
  336. }
  337. pState->pRecv->PostMessage(WM_RECVMSG,(WPARAM)pInfo,(LPARAM)pState);
  338. break;
  339. }
  340. case SOMEONE_ONHIDE:
  341. {
  342. if(iOnlineState==0)break;
  343. CNoticeMsg msg;
  344. CopyDataBuf(&msg,pData);
  345. if(!msg.LoadFromBuf())break;
  346. UserInfo *pInfo=NULL;
  347. FriendState *pState=NULL;
  348. if(FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,msg.MyId,pInfo,pState))
  349. {
  350. pState->OnlineState=2;
  351. pState->IP=msg.IP;
  352. pState->Port=msg.Port;
  353. m_wndBar.SetOnlineImage(msg.MyId,FALSE);
  354. m_wndBar.Invalidate();
  355. }
  356. break;
  357. }
  358. case SOMEONE_ONLINE:
  359. {
  360. if(iOnlineState==0)break;
  361. CNoticeMsg msg;
  362. CopyDataBuf(&msg,pData);
  363. if(!msg.LoadFromBuf())break;
  364. UserInfo *pInfo=NULL;
  365. FriendState *pState=NULL;
  366. if(FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,msg.MyId,pInfo,pState))
  367. {
  368. pState->OnlineState=1;
  369. pState->IP=msg.IP;
  370. pState->Port=msg.Port;
  371. m_wndBar.SetOnlineImage(msg.MyId);
  372. m_wndBar.Invalidate();
  373. }
  374. break;
  375. }
  376. case SOMEONE_OFFLINE:
  377. {
  378. if(iOnlineState==0)break;
  379. UserInfo *pInfo=NULL;
  380. FriendState *pState=NULL;
  381. if(FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,pData->MyId,pInfo,pState))
  382. {
  383. pState->OnlineState=0;
  384. m_wndBar.SetOnlineImage(pData->MyId,FALSE);
  385. m_wndBar.Invalidate();
  386. }
  387. break;
  388. }
  389. case ONLINE_OK:
  390. {
  391. if(!GetApp()->m_bOnlineState)
  392. SetTimer(1,TimerSpanClient,NULL);
  393. GetApp()->m_bOnlineState=1;
  394. CString str=GetApp()->m_strCurUserDir;
  395. str=str.Left(str.GetLength()-1);
  396. m_TrayIcon.SetIcon(IDR_ONLINE,str);
  397. AfxBeginThread(RequestFriendDetail,0,THREAD_PRIORITY_BELOW_NORMAL);
  398. break;
  399. }
  400. case ONHIDE_OK:
  401. {
  402. if(!GetApp()->m_bOnlineState)
  403. SetTimer(1,TimerSpanClient,NULL);
  404. GetApp()->m_bOnlineState=2;
  405. CString str=GetApp()->m_strCurUserDir;
  406. str=str.Left(str.GetLength()-1);
  407. m_TrayIcon.SetIcon(IDR_ONHIDE,str);
  408. AfxBeginThread(RequestFriendDetail,0,THREAD_PRIORITY_BELOW_NORMAL);
  409. break;
  410. }
  411. case ALL_FRIEND_ID:
  412. {
  413. if(iOnlineState==0)break;
  414. CMsg2 msg;
  415. CopyDataBuf(&msg,pData);
  416. if(!msg.LoadFromBuf())
  417. break;
  418. CString str1;
  419. for(int i=0;i<msg.aFriendId.GetSize();i++)
  420. {
  421. if(FindInArray(GetApp()->m_aUserInfo,msg.aFriendId.GetAt(i))!=-1)
  422. continue;
  423. UserInfo* pInfo=new UserInfo;
  424. pInfo->Id=msg.aFriendId.GetAt(i);
  425. str1.Format("%d",pInfo->Id);
  426. pInfo->HaveDetail=0;
  427. lstrcpy(pInfo->Name,str1);
  428. FriendState* pState=new FriendState;
  429. pState->OnlineState=0;
  430. GetApp()->m_aUserInfo.Add(pInfo);
  431. GetApp()->m_aUserState.Add(pState);
  432. GetApp()->m_aUserInfo.GetSize();
  433. m_wndBar.AddItem(0,str1,0,pInfo->Id);
  434. }
  435. m_wndBar.Invalidate();
  436. break;
  437. }
  438. case ONLINE_FRIEND:
  439. {
  440. //current all online friend
  441. if(iOnlineState==0)break;
  442. CMsgOnlineFriend msg;
  443. CopyDataBuf(&msg,pData);
  444. if(!msg.LoadFromBuf())break;
  445. UserInfo *pInfo=NULL;
  446. FriendState *pState=NULL;
  447. for(int i=0;i<msg.aFriendId.GetSize();i++)
  448. {
  449. if(FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,msg.aFriendId.GetAt(i),pInfo,pState))
  450. {
  451. pState->OnlineState=msg.aFriendState.GetAt(i);
  452. pState->IP=msg.aFriendIP.GetAt(i);
  453. pState->Port=msg.aFriendPort.GetAt(i);
  454. if(pState->OnlineState==1)
  455. m_wndBar.SetOnlineImage(msg.aFriendId.GetAt(i));
  456. }
  457. }
  458. m_wndBar.Invalidate();
  459. break;
  460. }
  461. case RE_FRIEND_DETAIL:
  462. {
  463. if(iOnlineState==0)break;
  464. CMsgPerson msg;
  465. CopyDataBuf(&msg,pData);
  466. if(!msg.LoadFromBuf())break;
  467. TRACE1("Friend Detail %dn",msg.MyId);
  468. UserInfo *pInfo=NULL;
  469. if(FindInArray(GetApp()->m_aUserInfo,pData->MyId,pInfo))
  470. {
  471. pInfo->HaveDetail=1;
  472. pInfo->CanbeAdd=msg.Canbeadd;
  473. pInfo->Sex=msg.Sex;
  474. pInfo->PhotoId=msg.PhotoId;
  475. lstrcpy(pInfo->Address,msg.Address);
  476. lstrcpy(pInfo->Age,msg.Age);
  477. lstrcpy(pInfo->Department,msg.Department);
  478. lstrcpy(pInfo->Description,msg.Description);
  479. lstrcpy(pInfo->Email,msg.Email);
  480. lstrcpy(pInfo->Fax,msg.Fax);
  481. lstrcpy(pInfo->Homepage,msg.Homepage);
  482. lstrcpy(pInfo->Phone,msg.Phone);
  483. lstrcpy(pInfo->Name,msg.Name);
  484. m_wndBar.ModifyItem(pInfo->Id,pInfo->PhotoId,pInfo->Name);
  485. m_wndBar.Invalidate();
  486. }
  487. else if(FindInArray(GetApp()->m_aStranger,pData->MyId,pInfo))
  488. {
  489. pInfo->HaveDetail=1;
  490. pInfo->CanbeAdd=msg.Canbeadd;
  491. pInfo->Sex=msg.Sex;
  492. pInfo->PhotoId=msg.PhotoId;
  493. lstrcpy(pInfo->Address,msg.Address);
  494. lstrcpy(pInfo->Age,msg.Age);
  495. lstrcpy(pInfo->Department,msg.Department);
  496. lstrcpy(pInfo->Description,msg.Description);
  497. lstrcpy(pInfo->Email,msg.Email);
  498. lstrcpy(pInfo->Fax,msg.Fax);
  499. lstrcpy(pInfo->Homepage,msg.Homepage);
  500. lstrcpy(pInfo->Phone,msg.Phone);
  501. lstrcpy(pInfo->Name,msg.Name);
  502. m_wndBar.ModifyItem(pInfo->Id,pInfo->PhotoId,pInfo->Name);
  503. m_wndBar.Invalidate();
  504. }
  505. break;
  506. }
  507. case BE_ADDED_AS_FRIEND:
  508. case FRIEND_IDENTITY_VALIDATE:
  509. {
  510. if(iOnlineState==0)break;
  511. CMsg1 msg;
  512. CopyDataBuf(&msg,pData);
  513. if(!msg.LoadFromBuf())break;
  514. SaveMsg * pMsg=new SaveMsg;
  515. if(index==BE_ADDED_AS_FRIEND)pMsg->type=BEADDED_MSG;
  516. else pMsg->type=ID_CHECK_MSG;
  517. pMsg->ID=msg.MyId;
  518. pMsg->Time=msg.Time;
  519. pMsg->Msg=msg.Msg;
  520. GetApp()->m_aSysMsg.Add(pMsg);
  521. GetApp()->m_aOtherMsg.Add(pMsg);
  522. if(m_pShowOther==NULL)
  523. {
  524. m_pShowOther=new CShowAddMsgDlg;
  525. m_pShowOther->Create(CShowAddMsgDlg::IDD,GetDesktopWindow());
  526. }
  527. //m_pShowOther->PostMessage();
  528. TRACE0("R: BE_ADDED_AS_FRIENDn");
  529. break;
  530. }
  531. case SYSTEM_BROADCAST:
  532. case ACCEPT_AS_FRIEND:
  533. case REFUSE_AS_FRIEND:
  534. {
  535. if(iOnlineState==0)break;
  536. CMsg1 msg;
  537. CopyDataBuf(&msg,pData);
  538. if(!msg.LoadFromBuf())break;
  539. SaveMsg * pMsg=new SaveMsg;
  540. pMsg->type=NOTICE_MSG;
  541. pMsg->ID=msg.MyId;
  542. pMsg->Time=msg.Time;
  543. pMsg->Msg=msg.Msg;
  544. GetApp()->m_aSysMsg.Add(pMsg);
  545. GetApp()->m_aNoticeMsg.Add(pMsg);
  546. if(m_pShowNotice==NULL)
  547. {
  548. m_pShowNotice=new CShowBroadcastDlg;
  549. m_pShowNotice->Create(CShowBroadcastDlg::IDD,GetDesktopWindow());
  550. }
  551. m_pShowNotice->PostMessage(WM_SHOW_NOTICE);
  552. break;
  553. }
  554. case TOTAL_ONLINE:
  555. {
  556. if(iOnlineState==0)break;
  557. CMsg3 msg;
  558. CopyDataBuf(&msg,pData);
  559. if(!msg.LoadFromBuf())break;
  560. if(msg.Value>0)
  561. {
  562. GetApp()->m_nTotalOnline=msg.Value;
  563. CString str;
  564. str.Format("%d人在线",msg.Value);
  565. SetWindowText(str);
  566. }
  567. m_bRecvTotal=TRUE;
  568. TRACE0("R: TOTAL_ONLINEn");
  569. break;
  570. }
  571. case NAME_NOT_FOUND_BY_NAME:
  572. {
  573. if(iOnlineState==0)break;
  574. break;
  575. }
  576. case FOUND_FRIEND_BY_ID:
  577. {
  578. if(iOnlineState==0)break;
  579. CMsgPerson msg;
  580. CopyDataBuf(&msg,pData);
  581. if(!msg.LoadFromBuf())break;
  582. for(int i=0;i<m_aTempInfo.GetSize();i++)
  583. delete m_aTempInfo.GetAt(i);
  584. m_aTempInfo.RemoveAll();
  585. UserInfo *pInfo=new UserInfo;
  586. pInfo->HaveDetail=1;
  587. pInfo->CanbeAdd=msg.Canbeadd;
  588. pInfo->Sex=msg.Sex;
  589. pInfo->PhotoId=msg.PhotoId;
  590. lstrcpy(pInfo->Address,msg.Address);
  591. lstrcpy(pInfo->Age,msg.Age);
  592. lstrcpy(pInfo->Department,msg.Department);
  593. lstrcpy(pInfo->Description,msg.Description);
  594. lstrcpy(pInfo->Email,msg.Email);
  595. lstrcpy(pInfo->Fax,msg.Fax);
  596. lstrcpy(pInfo->Homepage,msg.Homepage);
  597. lstrcpy(pInfo->Phone,msg.Phone);
  598. lstrcpy(pInfo->Name,msg.Name);
  599. m_aTempInfo.Add(pInfo);
  600. break;
  601. }
  602. case ID_NOT_FOUND_BY_ID:
  603. {
  604. if(iOnlineState==0)break;
  605. break;
  606. }
  607. case RE_ADD_AS_FRIEND:
  608. {
  609. if(iOnlineState==0)break;
  610. CMsg3 msg;
  611. CopyDataBuf(&msg,pData);
  612. if(!msg.LoadFromBuf())break;
  613. break;
  614. }
  615. }
  616. if(pData)
  617. delete pData;
  618. return 0;
  619. }
  620. void CMainFrame::OnTimer(UINT nIDEvent) 
  621. {
  622. if(nIDEvent==1&&GetApp()->m_bOnlineState)
  623. {
  624. /* CString str;
  625. if(m_bRecvTotal)
  626. {
  627. m_bRecvTotal=FALSE;
  628. }
  629. else
  630. {
  631. GetApp()->m_bOnlineState=0;
  632. str.Format("%d",GetApp()->m_uCurrentUserID);
  633. m_TrayIcon.SetIcon(IDR_OFFLINE,str);
  634. for(int i=0;i<GetApp()->m_aUserState.GetSize();i++)
  635. GetApp()->m_aUserState.GetAt(i)->OnlineState=0;
  636. m_wndBar.SetOfflineState();
  637. KillTimer(1);
  638. }
  639. str.Format("ID:%d",GetApp()->m_uCurrentUserID);
  640. SetWindowText(str);
  641. */ }
  642. }
  643. void CMainFrame::OnSendMessage() 
  644. {
  645. UserInfo *pInfo=NULL;
  646. FriendState *pState=NULL;
  647. if(nGroupFlag==0||nGroupFlag>2)
  648. {
  649. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  650. }
  651. else
  652. {
  653. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  654. }
  655. if(pState->pTalk==NULL)
  656. {
  657. pState->pTalk=new CTalkDlg;
  658. pState->pTalk->Create(CTalkDlg::IDD,GetDesktopWindow());
  659. }
  660. pState->pTalk->SendMessage(WM_SEND_MSG,(WPARAM)pInfo,(LPARAM)pState);
  661. }
  662. void CMainFrame::OnUpdateSendMessage(CCmdUI* pCmdUI) 
  663. {
  664. pCmdUI->Enable(GetApp()->m_bOnlineState);
  665. }
  666. void CMainFrame::OnSendEmail() 
  667. {
  668. UserInfo *pInfo=NULL;
  669. FriendState *pState=NULL;
  670. if(nGroupFlag==0||nGroupFlag>2)
  671. {
  672. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  673. }
  674. else
  675. {
  676. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  677. }
  678. CString str(pInfo->Email);
  679. ShellExecute(NULL,"open","mailto:"+str,NULL,NULL,SW_SHOW);
  680. }
  681. void CMainFrame::OnUpdateSendEmail(CCmdUI* pCmdUI) 
  682. {
  683. UserInfo *pInfo=NULL;
  684. FriendState *pState=NULL;
  685. if(nGroupFlag==0||nGroupFlag>2)
  686. {
  687. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  688. }
  689. else
  690. {
  691. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  692. }
  693. BOOL enabled=pInfo->HaveDetail==1&&lstrlen(pInfo->Email)>0;
  694. pCmdUI->Enable(enabled);
  695. }
  696. void CMainFrame::OnFriendDetail() 
  697. {
  698. UserInfo *pInfo=NULL;
  699. FriendState *pState=NULL;
  700. if(nGroupFlag==0||nGroupFlag>2)
  701. {
  702. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  703. }
  704. else
  705. {
  706. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  707. }
  708. if(pState->pFInfo==NULL)
  709. {
  710. pState->pFInfo=new CFriendDetailDlg;
  711. pState->pFInfo->Create(CFriendDetailDlg::IDD,GetDesktopWindow());
  712. }
  713. pState->pFInfo->SendMessage(WM_SHOW_FRIEND_DETAIL,(WPARAM)pInfo,(LPARAM)pState);
  714. }
  715. void CMainFrame::OnPersonHomepage() 
  716. {
  717. UserInfo *pInfo=NULL;
  718. FriendState *pState=NULL;
  719. if(nGroupFlag==0||nGroupFlag>2)
  720. {
  721. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  722. }
  723. else
  724. {
  725. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  726. }
  727. CString str(pInfo->Homepage);
  728. ShellExecute(NULL,"open","http://"+str,NULL,NULL,SW_SHOW);
  729. }
  730. void CMainFrame::OnUpdatePersonHomepage(CCmdUI* pCmdUI) 
  731. {
  732. UserInfo *pInfo=NULL;
  733. FriendState *pState=NULL;
  734. if(nGroupFlag==0||nGroupFlag>2)
  735. {
  736. FindInArray(GetApp()->m_aUserInfo,GetApp()->m_aUserState,nCurSelID,pInfo,pState);
  737. }
  738. else
  739. {
  740. FindInArray(GetApp()->m_aStranger,GetApp()->m_aStrangerState,nCurSelID,pInfo,pState);
  741. }
  742. BOOL enabled=pInfo->HaveDetail==1&&lstrlen(pInfo->Homepage)>0;
  743. pCmdUI->Enable(enabled);
  744. }
  745. void CMainFrame::OnOffline() 
  746. {
  747.   if(GetApp()->m_bOnlineState)
  748. {
  749. CData msg;
  750. msg.index=OFFLINE;
  751. msg.MyId=GetApp()->m_uCurrentUserID;
  752. msg.tarIP=GetApp()->m_uServerIP;
  753. msg.nPort=GetApp()->m_uServerPort;
  754. GetApp()->m_Socket.SendDataDirect(&msg);
  755. GetApp()->m_bOnlineState=0;
  756. CString str;
  757. str.Format("%d",GetApp()->m_uCurrentUserID);
  758. m_TrayIcon.SetIcon(IDR_OFFLINE,str);
  759. for(int i=0;i<GetApp()->m_aUserState.GetSize();i++)
  760. GetApp()->m_aUserState.GetAt(i)->OnlineState=0;
  761. m_wndBar.SetOfflineState();
  762. KillTimer(1);
  763. str.Format("ID:%d",GetApp()->m_uCurrentUserID);
  764. SetWindowText(str);
  765. }
  766. }
  767. void CMainFrame::OnOnhide() 
  768. {
  769. if(GetApp()->m_bOnlineState==2)return;
  770. CData msg;
  771. msg.index=ONHIDE;
  772. msg.MyId=GetApp()->m_uCurrentUserID;
  773. msg.tarIP=GetApp()->m_uServerIP;
  774. msg.nPort=GetApp()->m_uServerPort;
  775. GetApp()->m_Socket.SendDataDirect(&msg);
  776. }
  777. void CMainFrame::OnOnline() 
  778. {
  779. if(GetApp()->m_bOnlineState==1)return;
  780. CData msg;
  781. msg.index=ONLINE;
  782. msg.MyId=GetApp()->m_uCurrentUserID;
  783. msg.tarIP=GetApp()->m_uServerIP;
  784. msg.nPort=GetApp()->m_uServerPort;
  785. GetApp()->m_Socket.SendDataDirect(&msg);
  786. }
  787. void CMainFrame::OnSearch() 
  788. {
  789. if(GetApp()->m_bOnlineState==0)
  790. {
  791. AfxMessageBox(IDS_NOT_LOGIN_SERVER);
  792. return;
  793. }
  794. if(m_pSearch==NULL)
  795. {
  796. m_pSearch=new CSearchDlg;
  797. m_pSearch->Create(CSearchDlg::IDD,GetDesktopWindow());
  798. }
  799. m_pSearch->ShowWindow(SW_NORMAL);
  800. }
  801. void CMainFrame::OnPersoninfoSetup() 
  802. {
  803. if(m_pModifyPI==NULL)
  804. {
  805. m_pModifyPI=new CModifyPIDlg;
  806. m_pModifyPI->Create(CModifyPIDlg::IDD,GetDesktopWindow());
  807. }
  808. m_pModifyPI->SendMessage(WM_SHOW_FRIEND_DETAIL,(WPARAM)(GetApp()->m_aUserInfo.GetAt(0)),0);
  809. }
  810. void CMainFrame::OnMultisend() 
  811. {
  812. if(GetApp()->m_bOnlineState==0)
  813. {
  814. AfxMessageBox(IDS_NOT_LOGIN_SERVER);
  815. return;
  816. }
  817. if(m_pMultiSend==NULL)
  818. {
  819. m_pMultiSend=new CMultiSendDlg;
  820. m_pMultiSend->Create(CMultiSendDlg::IDD,GetDesktopWindow());
  821. }
  822. m_pMultiSend->ShowWindow(SW_NORMAL);
  823. }
  824. void CMainFrame::OnSendtoAll() 
  825. {
  826. if(GetApp()->m_bOnlineState==0)
  827. {
  828. AfxMessageBox(IDS_NOT_LOGIN_SERVER);
  829. return;
  830. }
  831. if(m_pSendToAll==NULL)
  832. {
  833. m_pSendToAll=new CSendToAllDlg;
  834. m_pSendToAll->Create(CSendToAllDlg::IDD,GetDesktopWindow());
  835. }
  836. m_pSendToAll->ShowWindow(SW_NORMAL);
  837. }
  838. void CMainFrame::OnMessageManage() 
  839. {
  840. AfxMessageBox(IDS_NOT_FINISH);
  841. }
  842. void CMainFrame::OnShowOnline() 
  843. {
  844. if(GetApp()->m_bOnlineState==0)
  845. {
  846. AfxMessageBox(IDS_NOT_LOGIN_SERVER);
  847. return;
  848. }
  849. if(m_pShowOnline==NULL)
  850. {
  851. m_pShowOnline=new CShowOnlineDlg;
  852. m_pShowOnline->Create(CShowOnlineDlg::IDD,GetDesktopWindow());
  853. }
  854. m_pShowOnline->ShowWindow(SW_NORMAL);
  855. }
  856. void CMainFrame::OnSendBroadcast() 
  857. {
  858. if(GetApp()->m_bOnlineState==0)
  859. {
  860. CString str;
  861. str.LoadString(IDS_NOT_LOGIN_SERVER);
  862. MessageBox(str);
  863. return;
  864. }
  865. if(m_pSendBroad==NULL)
  866. {
  867. m_pSendBroad=new CSendBroadcastDlg;
  868. m_pSendBroad->Create(CSendBroadcastDlg::IDD,GetDesktopWindow());
  869. }
  870. m_pSendBroad->ShowWindow(SW_NORMAL);
  871. }
  872. LRESULT CMainFrame::OnAddFriendRefresh(WPARAM wParam,LPARAM lParam)
  873. {
  874. DWORD uFriendID=wParam;
  875. if(uFriendID<=0)return 0;
  876. if(FindInArray(GetApp()->m_aUserInfo,uFriendID)!=-1)return 0;
  877. UserInfo* pInfo=NULL;
  878. FriendState* pState=NULL;
  879. int rindex=FindInArray(GetApp()->m_aStranger,uFriendID);
  880. if(rindex!=-1)
  881. {
  882. pInfo=GetApp()->m_aStranger.GetAt(rindex);
  883. pState=GetApp()->m_aStrangerState.GetAt(rindex);
  884. GetApp()->m_aStranger.RemoveAt(rindex);
  885. GetApp()->m_aStrangerState.RemoveAt(rindex);
  886. m_wndBar.RemoveAItem(1,uFriendID,FALSE);
  887. }
  888. else
  889. {
  890. pInfo=new UserInfo;
  891. pInfo->Id=uFriendID;
  892. pInfo->HaveDetail=0;
  893. pInfo->PhotoId=0;
  894. itoa(uFriendID,pInfo->Name,10);
  895. pState=new FriendState;
  896. pState->OnlineState=0;
  897. }
  898. GetApp()->m_aUserInfo.Add(pInfo);
  899. GetApp()->m_aUserState.Add(pState);
  900. m_wndBar.AddItem(0,pInfo->Name,pInfo->PhotoId,pInfo->Id);
  901. m_wndBar.Invalidate();
  902. if(!pInfo->HaveDetail)
  903. {
  904. CMsg1 msg;
  905. msg.index=FRIEND_DETAIL;
  906. msg.MyId=GetApp()->m_uCurrentUserID;
  907. msg.tarIP=GetApp()->m_uServerIP;
  908. msg.nPort=GetApp()->m_uServerPort;
  909. msg.FriendId=uFriendID;
  910. GetApp()->m_Socket.SendDataDirect(&msg);
  911. }
  912. return 1;
  913. }
  914. void CMainFrame::OnAddFriend() 
  915. {
  916.   if(m_pAddFriendDlg==NULL)
  917. {
  918. m_pAddFriendDlg=new CAddFriendDlg;
  919. m_pAddFriendDlg->Create(CAddFriendDlg::IDD);
  920. }
  921. m_pAddFriendDlg->uID=nCurSelID;
  922. if(m_pAddFriendDlg->SendMessage(WM_NOTICE_ADDFRIEND))
  923. m_wndBar.RemoveAItem(1,nCurSelIndex);
  924. }
  925. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  926. {
  927. if(pMsg->message==WM_KEYDOWN)
  928. {
  929. if(pMsg->wParam>'0' &&pMsg->wParam<'5'&&GetKeyState(VK_CONTROL)&0x80)
  930. {
  931. nCurSelIndex=pMsg->wParam-'1';
  932. nGroupFlag=m_wndBar.iSelFolder;
  933. nCurSelID = m_wndBar.GetItemData(nCurSelIndex);
  934. if(nCurSelID!=0)SendMessage(WM_COMMAND,ID_SEND_MESSAGE,0);
  935. return 1;
  936. }
  937. }
  938. return CFrameWnd::PreTranslateMessage(pMsg);
  939. }