【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了DragViewView.cpp相关资料,希望对各位网友有所帮助!
// DragViewView.cpp : implementation of the CDragViewView class
//
#include "stdafx.h"
#include "DragView.h"
#include "DragViewDoc.h"
#include "DragViewView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDragViewView
IMPLEMENT_DYNCREATE(CDragViewView, CListView)
BEGIN_MESSAGE_MAP(CDragViewView, CListView)
//{{AFX_MSG_MAP(CDragViewView)
ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBegindrag)
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDragViewView construction/destruction
CDragViewView::CDragViewView()
{
// TODO: add construction code here
}
CDragViewView::~CDragViewView()
{
}
BOOL CDragViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDragViewView drawing
void CDragViewView::OnDraw(CDC* pDC)
{
CDragViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CDragViewView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
CListCtrl* pListCtl=&GetListCtrl();
pListCtl->ModifyStyle(0L,LVS_REPORT);
pListCtl->SetExtendedStyle(LVS_EX_FLATSB
|LVS_EX_FULLROWSELECT
|LVS_EX_HEADERDRAGDROP
|LVS_EX_ONECLICKACTIVATE
|LVS_EX_GRIDLINES);
pListCtl->InsertColumn(0,"员工编号",LVCFMT_LEFT,100);
pListCtl->InsertColumn(1,"员工",LVCFMT_LEFT,100);
pListCtl->InsertColumn(2,"文化程度",LVCFMT_LEFT,100);
pListCtl->InsertItem(0,"0001");
pListCtl->SetItemText(0,1,"赵一");
pListCtl->SetItemText(0,2,"专科");
pListCtl->InsertItem(1,"0002");
pListCtl->SetItemText(1,1,"钱二");
pListCtl->SetItemText(1,2,"本科");
pListCtl->InsertItem(2,"0003");
pListCtl->SetItemText(2,1,"孙三");
pListCtl->SetItemText(2,2,"研究生");
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
/////////////////////////////////////////////////////////////////////////////
// CDragViewView printing
BOOL CDragViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDragViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDragViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDragViewView diagnostics
#ifdef _DEBUG
void CDragViewView::AssertValid() const
{
CListView::AssertValid();
}
void CDragViewView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CDragViewDoc* CDragViewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDragViewDoc)));
return (CDragViewDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDragViewView message handlers
void CDragViewView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
POINT pt;
m_ItmIndex = ((NM_LISTVIEW *)pNMHDR)->iItem;
int pos = GetListCtrl().GetSelectionMark();
m_pDrgImg = GetListCtrl().CreateDragImage(m_ItmIndex,&pt);
m_pDrgImg->BeginDrag(0,pt);
m_pDrgImg->DragEnter(this,pt);
m_Drag = TRUE;
*pResult = 0;
}
void CDragViewView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_Drag)
{
m_pDrgImg->EndDrag();
m_Drag = FALSE;
char name[256];
LV_ITEM lvi;
CString subitem[3];
for(int i=2;i>=0;i--)
{
ZeroMemory(&lvi,sizeof(LV_ITEM));
lvi.iItem = m_ItmIndex;
lvi.iSubItem = i;
lvi.mask = LVIF_IMAGE | LVIF_TEXT;
lvi.pszText = name;
lvi.cchTextMax = 255;
GetListCtrl().GetItem(&lvi);
subitem[i].Format("%s",name);
}
GetListCtrl().InsertItem(&lvi);
GetListCtrl().SetItemText(m_ItmIndex,1,subitem[1]);
GetListCtrl().SetItemText(m_ItmIndex,2,subitem[2]);
}
CListView::OnLButtonUp(nFlags, point);
}
void CDragViewView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_Drag)
{
CPoint pt;
pt.x = point.x;
pt.y = point.y + (m_ItmIndex + 1) * 15;
m_pDrgImg->DragMove(pt);
}
CListView::OnMouseMove(nFlags, point);
}
上一篇:
frmCPUID80000005.frm
下一篇:
基于web二手汽车交易管理系统(含录像)