UserList.cpp
上传用户:seeker_wen
上传日期:2016-05-23
资源大小:2084k
文件大小:7k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. // UserList.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MSN.h"
  5. #include "UserList.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CUserList dialog
  13. CUserList::CUserList(CWnd* pParent /*=NULL*/)
  14. : CDialog(CUserList::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CUserList)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. CUserList::~CUserList()
  21. {
  22. for(std::vector<CUserChat*>::iterator it = arr_chat.begin(); it!= arr_chat.end(); ++it)
  23. delete *it;
  24. arr_chat.clear();
  25. }
  26. void CUserList::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CUserList)
  30. DDX_Control(pDX, IDC_EDIT16, m_search);
  31. DDX_Control(pDX, IDC_TREE1, m_UserTree);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CUserList, CDialog)
  35. //{{AFX_MSG_MAP(CUserList)
  36. ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree1)
  37. ON_WM_PAINT()
  38. ON_WM_ERASEBKGND()
  39. ON_WM_SIZE()
  40. ON_MESSAGE(WM_USER_EDITBUTTON_CLICKED,OnEditButtonClicked)
  41. ON_NOTIFY(NM_DBLCLK, IDC_TREE1, OnDblclkTree1)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CUserList message handlers
  46. void CUserList::OnPaint() 
  47. {
  48. CPaintDC dc(this); // device context for painting
  49. CRect rc;
  50. GetClientRect(rc);
  51. RECT   rcCtrl = {0};   
  52. CWnd*  pwndCtrl = GetWindow(GW_CHILD);   
  53. while(pwndCtrl)   
  54. {   
  55. if(IsWindow(pwndCtrl->m_hWnd)&&pwndCtrl->IsWindowVisible())   
  56. {   
  57. pwndCtrl->GetWindowRect(&rcCtrl);   
  58. ScreenToClient(&rcCtrl); 
  59. dc.ExcludeClipRect(&rcCtrl);   
  60. }   
  61. pwndCtrl = pwndCtrl->GetNextWindow();   
  62. }   
  63. dc.FillSolidRect(rc, 0xffffff);
  64. dc.Draw3dRect(rc, 0xffc0a2,0xffc0a2);
  65. CPen pen;
  66. pen.CreatePen(PS_SOLID,1,0xf3eae2);
  67. dc.SelectObject(pen);
  68. dc.MoveTo(0,36);
  69. dc.LineTo(rc.Width(), 36);
  70. }
  71. BOOL CUserList::OnEraseBkgnd(CDC* pDC) 
  72. {
  73. return TRUE;
  74. return CDialog::OnEraseBkgnd(pDC);
  75. }
  76. BOOL CUserList::OnInitDialog() 
  77. {
  78. CDialog::OnInitDialog();
  79. //SetWindowNoSkinHwnd(m_hWnd, FALSE);
  80. CRect rc;
  81. GetClientRect(rc);
  82. CButton *btn = (CButton *)GetDlgItem(3000);
  83. btn->MoveWindow(rc.right-52, 7, 22, 22);
  84. CTreeCtrl *m_ctrlTree = (CTreeCtrl *)GetDlgItem(IDC_TREE1);
  85. rc.InflateRect(1, 37,1,-37);
  86. m_ctrlTree->MoveWindow(rc);
  87. m_ILtabItem.Create(16, 16, ILC_MASK | ILC_COLOR32, 1, 1);
  88. ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Collapse));
  89. ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Expand));
  90. ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Collapse1));
  91. ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Expand1));
  92. m_ctrlTree->SetImageList(&m_ILtabItem,TVSIL_STATE);   //   设置图标链标   
  93. static HTREEITEM hParent=TVI_ROOT;
  94. hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "其他联系人(5/5)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);   
  95. m_ctrlTree->EnsureVisible(hParent);
  96. m_ctrlTree->InsertItem("连讪讪",hParent);
  97. m_ctrlTree->InsertItem("王非",hParent);
  98. m_ctrlTree->InsertItem("徐静雷",hParent);
  99. m_ctrlTree->InsertItem("周杰论",hParent);
  100. m_ctrlTree->InsertItem("刘德华",hParent);
  101. hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "skinfeature公司(5/5)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);   
  102. m_ctrlTree->EnsureVisible(hParent);
  103. m_ctrlTree->InsertItem("产品中心",hParent);
  104. m_ctrlTree->InsertItem("技术中心",hParent);
  105. m_ctrlTree->InsertItem("售后服务",hParent);
  106. m_ctrlTree->InsertItem("销售部门",hParent);
  107. m_ctrlTree->InsertItem("深圳分公司",hParent);
  108. m_ctrlTree->Expand(hParent, TVE_EXPAND);
  109. hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "非即时消息联系人(2/12)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);   
  110. m_ctrlTree->InsertItem("坏到刚刚好",hParent);
  111. m_ctrlTree->InsertItem("文江",hParent);
  112. m_ctrlTree->InsertItem("三国贾许",hParent);
  113. m_ctrlTree->InsertItem("改变习惯",hParent);
  114. m_ctrlTree->InsertItem("努力没有什么不可以",hParent);
  115. m_ctrlTree->Expand(hParent, TVE_EXPAND);
  116. hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "黑名单用户(1/25)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);   
  117. m_ctrlTree->InsertItem("冰冻的心",hParent);
  118. m_ctrlTree->InsertItem("夏天的冰块",hParent);
  119. m_ctrlTree->InsertItem("僧人boy",hParent);
  120. m_ctrlTree->InsertItem("孤单生活",hParent);
  121. m_ctrlTree->InsertItem("爱我就离开我",hParent);
  122. ::SendMessage(m_UserTree.m_hWnd, TVM_SETITEMHEIGHT, 20, 0);
  123. m_UserTree.ModifyStyle(0, 0x8000);   
  124. CRect rcEditArea(20,4,125,17);
  125. m_search.SetEditArea(rcEditArea);
  126. CRect rcButtonArea(128,3,143,18);
  127. m_search.SetButtonArea(rcButtonArea);
  128. m_search.SetOwner(this);
  129. m_search.SetButtonClickedMessageId(WM_USER_EDITBUTTON_CLICKED);
  130. m_search.SetButtonExistsAlways(FALSE);
  131. m_search.SetBitmaps("bitmap1.bmp", "bitmap_e.bmp");
  132. CEdit *edit =  (CEdit *)GetDlgItem(IDC_EDIT16);
  133. edit->MoveWindow(7, 7, rc.Width()-7-59, 22);
  134. return TRUE; 
  135. }
  136. void CUserList::OnSize(UINT nType, int cx, int cy) 
  137. {
  138. CTreeCtrl *m_ctrlTree = (CTreeCtrl *)GetDlgItem(IDC_TREE1);
  139. m_ctrlTree->MoveWindow(1,37,cx-2,cy-38);
  140. CButton *btn = (CButton *)GetDlgItem(3000);
  141. btn->MoveWindow( cx -52, 7, 22, 22);
  142. CEdit *edit =  (CEdit *)GetDlgItem(IDC_EDIT16);
  143. edit->MoveWindow(7, 2, cx-2-59, 32);
  144. CDialog::OnSize(nType, cx, cy);
  145. }
  146. void CUserList::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult) 
  147. {
  148. *pResult = 0;
  149. HTREEITEM hTreeSelectedItem = GetTreeItemFromPoint();
  150. if (hTreeSelectedItem == NULL)
  151. return;
  152. if (m_UserTree.GetChildItem(hTreeSelectedItem) == NULL)
  153. return;
  154. UINT nState = m_UserTree.GetItemState(hTreeSelectedItem, TVIS_EXPANDED);   
  155. if(0 != (nState&TVIS_EXPANDED))   
  156. {   
  157. m_UserTree.SetItemState(hTreeSelectedItem,INDEXTOSTATEIMAGEMASK(TVE_COLLAPSE),TVIS_STATEIMAGEMASK); 
  158. m_UserTree.SendMessage(TVM_EXPAND, (WPARAM)(UINT)(TVE_COLLAPSE|TVE_EXPANDPARTIAL),(LPARAM)(HTREEITEM)hTreeSelectedItem);   
  159. }   
  160. else   
  161. {   
  162. m_UserTree.SetItemState(hTreeSelectedItem,INDEXTOSTATEIMAGEMASK(TVM_EXPAND),TVIS_STATEIMAGEMASK); 
  163. m_UserTree.SendMessage(TVM_EXPAND, (WPARAM)(UINT)(TVE_EXPAND|TVE_EXPANDPARTIAL),(LPARAM)(HTREEITEM)hTreeSelectedItem);   
  164. }
  165. m_UserTree.Invalidate();
  166. }
  167. HTREEITEM CUserList::GetTreeItemFromPoint()
  168. {
  169. CPoint ptNew;
  170. ::GetCursorPos(&ptNew);
  171. CPoint ptClient(ptNew);
  172. m_UserTree.ScreenToClient(&ptClient);
  173. HTREEITEM hTreeItem = m_UserTree.HitTest(ptClient);
  174. return hTreeItem;
  175. }
  176. LRESULT CUserList::OnEditButtonClicked(WPARAM wParam, LPARAM lParam)
  177. {
  178. //clear edit control
  179. m_search.SetWindowText(_T(""));
  180. AfxMessageBox("d");
  181. return 1;
  182. }
  183. void CUserList::OnDblclkTree1(NMHDR* pNMHDR, LRESULT* pResult) 
  184. {
  185. HTREEITEM hItem = m_UserTree.GetSelectedItem();
  186. //chatInfoTip.ShowWindow(SW_HIDE);
  187. if (m_UserTree.GetParentItem(hItem)!=NULL)
  188. {
  189. CUserChat *main = new CUserChat();
  190. main->CreateDlg(MAKEINTRESOURCE(IDD_CHAT),NULL);
  191. main->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
  192. main->ShowWindow(SW_NORMAL);
  193. arr_chat.push_back(main);
  194. *pResult = 0;
  195. }
  196. *pResult = 0;
  197. }