UserList.cpp
资源名称:MSN.rar [点击查看]
上传用户:seeker_wen
上传日期:2016-05-23
资源大小:2084k
文件大小:7k
源码类别:
ICQ/即时通讯
开发平台:
Visual C++
- // UserList.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MSN.h"
- #include "UserList.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CUserList dialog
- CUserList::CUserList(CWnd* pParent /*=NULL*/)
- : CDialog(CUserList::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUserList)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CUserList::~CUserList()
- {
- for(std::vector<CUserChat*>::iterator it = arr_chat.begin(); it!= arr_chat.end(); ++it)
- delete *it;
- arr_chat.clear();
- }
- void CUserList::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUserList)
- DDX_Control(pDX, IDC_EDIT16, m_search);
- DDX_Control(pDX, IDC_TREE1, m_UserTree);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CUserList, CDialog)
- //{{AFX_MSG_MAP(CUserList)
- ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree1)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- ON_WM_SIZE()
- ON_MESSAGE(WM_USER_EDITBUTTON_CLICKED,OnEditButtonClicked)
- ON_NOTIFY(NM_DBLCLK, IDC_TREE1, OnDblclkTree1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUserList message handlers
- void CUserList::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CRect rc;
- GetClientRect(rc);
- RECT rcCtrl = {0};
- CWnd* pwndCtrl = GetWindow(GW_CHILD);
- while(pwndCtrl)
- {
- if(IsWindow(pwndCtrl->m_hWnd)&&pwndCtrl->IsWindowVisible())
- {
- pwndCtrl->GetWindowRect(&rcCtrl);
- ScreenToClient(&rcCtrl);
- dc.ExcludeClipRect(&rcCtrl);
- }
- pwndCtrl = pwndCtrl->GetNextWindow();
- }
- dc.FillSolidRect(rc, 0xffffff);
- dc.Draw3dRect(rc, 0xffc0a2,0xffc0a2);
- CPen pen;
- pen.CreatePen(PS_SOLID,1,0xf3eae2);
- dc.SelectObject(pen);
- dc.MoveTo(0,36);
- dc.LineTo(rc.Width(), 36);
- }
- BOOL CUserList::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- return CDialog::OnEraseBkgnd(pDC);
- }
- BOOL CUserList::OnInitDialog()
- {
- CDialog::OnInitDialog();
- //SetWindowNoSkinHwnd(m_hWnd, FALSE);
- CRect rc;
- GetClientRect(rc);
- CButton *btn = (CButton *)GetDlgItem(3000);
- btn->MoveWindow(rc.right-52, 7, 22, 22);
- CTreeCtrl *m_ctrlTree = (CTreeCtrl *)GetDlgItem(IDC_TREE1);
- rc.InflateRect(1, 37,1,-37);
- m_ctrlTree->MoveWindow(rc);
- m_ILtabItem.Create(16, 16, ILC_MASK | ILC_COLOR32, 1, 1);
- ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Collapse));
- ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Expand));
- ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Collapse1));
- ImageList_AddIcon(m_ILtabItem.m_hImageList, AfxGetApp()->LoadIcon(IDI_Expand1));
- m_ctrlTree->SetImageList(&m_ILtabItem,TVSIL_STATE); // 设置图标链标
- static HTREEITEM hParent=TVI_ROOT;
- hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "其他联系人(5/5)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);
- m_ctrlTree->EnsureVisible(hParent);
- m_ctrlTree->InsertItem("连讪讪",hParent);
- m_ctrlTree->InsertItem("王非",hParent);
- m_ctrlTree->InsertItem("徐静雷",hParent);
- m_ctrlTree->InsertItem("周杰论",hParent);
- m_ctrlTree->InsertItem("刘德华",hParent);
- hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "skinfeature公司(5/5)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);
- m_ctrlTree->EnsureVisible(hParent);
- m_ctrlTree->InsertItem("产品中心",hParent);
- m_ctrlTree->InsertItem("技术中心",hParent);
- m_ctrlTree->InsertItem("售后服务",hParent);
- m_ctrlTree->InsertItem("销售部门",hParent);
- m_ctrlTree->InsertItem("深圳分公司",hParent);
- m_ctrlTree->Expand(hParent, TVE_EXPAND);
- hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "非即时消息联系人(2/12)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);
- m_ctrlTree->InsertItem("坏到刚刚好",hParent);
- m_ctrlTree->InsertItem("文江",hParent);
- m_ctrlTree->InsertItem("三国贾许",hParent);
- m_ctrlTree->InsertItem("改变习惯",hParent);
- m_ctrlTree->InsertItem("努力没有什么不可以",hParent);
- m_ctrlTree->Expand(hParent, TVE_EXPAND);
- hParent=m_ctrlTree->InsertItem(TVIF_TEXT|TVIF_STATE|TVIF_PARAM, "黑名单用户(1/25)", 0, 1, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK, 1, TVI_ROOT, TVI_LAST);
- m_ctrlTree->InsertItem("冰冻的心",hParent);
- m_ctrlTree->InsertItem("夏天的冰块",hParent);
- m_ctrlTree->InsertItem("僧人boy",hParent);
- m_ctrlTree->InsertItem("孤单生活",hParent);
- m_ctrlTree->InsertItem("爱我就离开我",hParent);
- ::SendMessage(m_UserTree.m_hWnd, TVM_SETITEMHEIGHT, 20, 0);
- m_UserTree.ModifyStyle(0, 0x8000);
- CRect rcEditArea(20,4,125,17);
- m_search.SetEditArea(rcEditArea);
- CRect rcButtonArea(128,3,143,18);
- m_search.SetButtonArea(rcButtonArea);
- m_search.SetOwner(this);
- m_search.SetButtonClickedMessageId(WM_USER_EDITBUTTON_CLICKED);
- m_search.SetButtonExistsAlways(FALSE);
- m_search.SetBitmaps("bitmap1.bmp", "bitmap_e.bmp");
- CEdit *edit = (CEdit *)GetDlgItem(IDC_EDIT16);
- edit->MoveWindow(7, 7, rc.Width()-7-59, 22);
- return TRUE;
- }
- void CUserList::OnSize(UINT nType, int cx, int cy)
- {
- CTreeCtrl *m_ctrlTree = (CTreeCtrl *)GetDlgItem(IDC_TREE1);
- m_ctrlTree->MoveWindow(1,37,cx-2,cy-38);
- CButton *btn = (CButton *)GetDlgItem(3000);
- btn->MoveWindow( cx -52, 7, 22, 22);
- CEdit *edit = (CEdit *)GetDlgItem(IDC_EDIT16);
- edit->MoveWindow(7, 2, cx-2-59, 32);
- CDialog::OnSize(nType, cx, cy);
- }
- void CUserList::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- *pResult = 0;
- HTREEITEM hTreeSelectedItem = GetTreeItemFromPoint();
- if (hTreeSelectedItem == NULL)
- return;
- if (m_UserTree.GetChildItem(hTreeSelectedItem) == NULL)
- return;
- UINT nState = m_UserTree.GetItemState(hTreeSelectedItem, TVIS_EXPANDED);
- if(0 != (nState&TVIS_EXPANDED))
- {
- m_UserTree.SetItemState(hTreeSelectedItem,INDEXTOSTATEIMAGEMASK(TVE_COLLAPSE),TVIS_STATEIMAGEMASK);
- m_UserTree.SendMessage(TVM_EXPAND, (WPARAM)(UINT)(TVE_COLLAPSE|TVE_EXPANDPARTIAL),(LPARAM)(HTREEITEM)hTreeSelectedItem);
- }
- else
- {
- m_UserTree.SetItemState(hTreeSelectedItem,INDEXTOSTATEIMAGEMASK(TVM_EXPAND),TVIS_STATEIMAGEMASK);
- m_UserTree.SendMessage(TVM_EXPAND, (WPARAM)(UINT)(TVE_EXPAND|TVE_EXPANDPARTIAL),(LPARAM)(HTREEITEM)hTreeSelectedItem);
- }
- m_UserTree.Invalidate();
- }
- HTREEITEM CUserList::GetTreeItemFromPoint()
- {
- CPoint ptNew;
- ::GetCursorPos(&ptNew);
- CPoint ptClient(ptNew);
- m_UserTree.ScreenToClient(&ptClient);
- HTREEITEM hTreeItem = m_UserTree.HitTest(ptClient);
- return hTreeItem;
- }
- LRESULT CUserList::OnEditButtonClicked(WPARAM wParam, LPARAM lParam)
- {
- //clear edit control
- m_search.SetWindowText(_T(""));
- AfxMessageBox("d");
- return 1;
- }
- void CUserList::OnDblclkTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- HTREEITEM hItem = m_UserTree.GetSelectedItem();
- //chatInfoTip.ShowWindow(SW_HIDE);
- if (m_UserTree.GetParentItem(hItem)!=NULL)
- {
- CUserChat *main = new CUserChat();
- main->CreateDlg(MAKEINTRESOURCE(IDD_CHAT),NULL);
- main->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
- main->ShowWindow(SW_NORMAL);
- arr_chat.push_back(main);
- *pResult = 0;
- }
- *pResult = 0;
- }