欢迎来到天天文库
浏览记录
ID:40547596
大小:45.50 KB
页数:4页
时间:2019-08-04
《ctreectrl向clistctrl拖放》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Ctreectrl向cListctrl拖放1)首先需要定制全局变量CImageListm_Image;CImageList*m_pDragImage;BOOLm_bDragging;HTREEITEMm_hDragItem,m_hDropItem;intm_nDropIndex;CWnd*m_pDropWnd;以及afx_msgvoidOnLButtonUp(UINTnFlags,CPointpoint);afx_msgvoidOnMouseMove(UINTnFlags,CPointpoint);afx_msgvoidOnBeginDrag(NMHDR*pnmhdr
2、,LRESULT*pResult);voidDropItemOnList(CListCtrl*pList);四个函数。前边的都是需要在.h文件中写的。ON_WM_LBUTTONUP()ON_WM_MOUSEMOVE()ON_NOTIFY_REFLECT(LVN_BEGINDRAG,OnBegindrag)这是前边三个函数对应的消息。这些需要在.CPP中写的。2)voidCMyDlg::OnBeginDrag(NMHDR*pnmhdr,LRESULT*pResult){//createadragimage//Added7/29/96NM_TREEVIEW*pNMTree
3、View=(NM_TREEVIEW*)pnmhdr;m_hDragItem=pNMTreeView->itemNew.hItem;m_pDragImage=m_treectrl.CreateDragImage(m_hDragItem);//函数为项创建拖拉图象列表//changesthecursortothedragimage(DragMove()isstillrequiredin//OnMouseMove())m_pDragImage->BeginDrag(0,CPoint(8,8));//此函数开始拖动一个图像m_pDragImage->DragEnter(Get
4、DesktopWindow(),((NM_TREEVIEW*)pnmhdr)->ptDrag);//拖动操作中,封锁对pWndLock确定的窗口的更新,在由point确定的位置显示拖动图象//setdraggingflagm_bDragging=TRUE;m_hDropItem=NULL;m_nDropIndex=-1;m_pDropWnd=&m_treectrl;//m_treectrl为控件变量//captureallmousemessagesSetCapture();}voidCMyDlg::OnMouseMove(UINTnFlags,CPointpoint)
5、{if(TRUE==m_bDragging){CPointpt(point);ClientToScreen(&pt);//movethedragimageVERIFY(m_pDragImage->DragMove(pt));//此函数移动在拖放操作中正被拖动的图象//unlockwindowupdatesVERIFY(m_pDragImage->DragShowNolock(FALSE));//确定是否显示拖动图象。//gettheCWndpointerofthewindowthatisunderthemousecursorCWnd*pDropWnd=WindowFr
6、omPoint(pt);//获得包含指定点的窗口的句柄ASSERT(pDropWnd);//ifwedragoutsidecurrentwindowif(pDropWnd!=m_pDropWnd){//turnoffdraghilitefortreecontrolif(m_hDropItem){((CTreeCtrl*)m_pDropWnd)->SelectDropTarget(NULL);//此成员函数用指明一次拖放操作的目标的风格来重画该项m_hDropItem=NULL;}//turnoffdraghiliteforlistcontrolif(m_nDropIn
7、dex!=-1){CListCtrl*pList=(CListCtrl*)m_pDropWnd;VERIFY(pList->SetItemState(m_nDropIndex,0,LVIS_DROPHILITED));//redrawitemVERIFY(pList->RedrawItems(m_nDropIndex,m_nDropIndex));pList->UpdateWindow();m_nDropIndex=-1;}}//savecurrentwindowpointerm_pDropWnd=pDropWnd;//convertfromscre
此文档下载收益归作者所有