Click to See Complete Forum and Search --> : Drag n' Drop? SOMEONE PLZ!!


laiason5
May 17th, 1999, 09:41 PM
ok, heres the deal. im tryin to learn mfc and here i am on tree controls. im trying to implement drag n' drop with them but the problem is that when i try to CreateDragImage(...), it always returns null. this is the code im usin(consequently its from the samples page on codeguru)

void CMyTreeCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;

m_hitemDrag = pNMTreeView->itemNew.hItem;
m_hitemDrop = NULL;

m_pDragImage = CreateDragImage(m_hitemDrag); //WHY WONT THIS RETURN A VALUE???
if(!m_pDragImage)
return;
m_bLDragging = true;
m_pDragImage->BeginDrag(0, CPoint(0,0) );
POINT pt = pNMTreeView->ptDrag;
ClientToScreen(&pt);
m_pDragImage->DragEnter(NULL, pt);
SetCapture();
}

i have a major programming project due in three weeks so any reply would be welcome.

thanks
L5

olivier
May 18th, 1999, 10:30 AM
m_hCursorNoDrop = AfxGetApp()->LoadCursor(IDC_NODROP);
m_hCursorDrag = AfxGetApp()->LoadCursor(IDC_DROP);


============================================================
void CMyTreeCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{

NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

SetCursor(m_hCursorDrag);
SetCapture();

*pResult = 0;
}

/////////////////////////////////////////////////////////////////////////////
// OnMouseMove :
/////////////////////////////////////////////////////////////////////////////

void CMyTreeCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bDragging)
{
if (iHit == -1)
SetCursor(m_hCursorNoDrop); // the No cursor
else
SetCursor(m_hCursorDrag); // the drag Cursor
}

CTreeCtrl::OnMouseMove(nFlags, point);
}



/////////////////////////////////////////////////////////////////////////////
// OnLButtonUp :
/////////////////////////////////////////////////////////////////////////////

void CMyTreeCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_bDragging)
{
// Reset boolean.
m_bDragging = FALSE;

// Release the mouse.
ReleaseCapture();
}

CTreeCtrl::OnLButtonUp(nFlags, point);
}

laiason5
May 18th, 1999, 04:18 PM
thanks, ill try it
L5