I’m trying to implement drag and drop in CMyListCtrl (Derived from
CListCtrl).
I've mapped the LVN_BEGINDRAG, WM_LBUTTONUP and WM_MOUSEMOVE
to the relative member functions.
Every thing works fine EXCEPT when I drag the icon (32x32) and its
associated text they leave big black marks behind them!
This is my OnBeginDrag method
void CMyListCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
CPoint ptItem, ptAction, ptImage;
NM_LISTVIEW *pnmListView = (NM_LISTVIEW *)pNMHDR;
ASSERT(!m_bDragging);
m_bDragging = TRUE;
m_iItemDrag = pnmListView->iItem;
ptAction = pnmListView->ptAction;
GetItemPosition(m_iItemDrag, &ptItem); // ptItem is relative to (0,0) and
not the view origin
GetOrigin(&m_ptOrigin);
ASSERT(m_pimageListDrag == NULL);
m_pimageListDrag = CreateDragImage(m_iItemDrag, &ptImage);
m_sizeDelta = ptAction - ptImage; // difference between cursor pos and
image pos - change me
m_ptHotSpot = ptAction - ptItem + m_ptOrigin; // calculate hotspot for
the cursor
m_pimageListDrag->DragShowNolock(TRUE); // lock updates and show drag
image - false?
m_pimageListDrag->SetDragCursorImage(0, m_ptHotSpot); // define the hot
spot for the new cursor image
m_pimageListDrag->BeginDrag(0, CPoint(0, 0));
ptAction -= m_sizeDelta;
m_pimageListDrag->DragEnter(this, ptAction);
m_pimageListDrag->DragMove(ptAction); // move image to overlap original
icon
SetCapture();
}
It is taken almost directly from the cmnctrls sample!
CMyListCtrl's OnPaint and OnEraseBkgnd methods have been
overridden but the problem persists even when they just
call the base classes default methods.
Any Ideas?
Thanks
Karen.
Try to make little changes in your code, I hope this will help:
>void CMyListCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
>{
>CPoint ptItem, ptAction, ptImage;
>NM_LISTVIEW *pnmListView = (NM_LISTVIEW *)pNMHDR;
>ASSERT(!m_bDragging);
>m_bDragging = TRUE;
>m_iItemDrag = pnmListView->iItem;
>ptAction = pnmListView->ptAction;
>GetItemPosition(m_iItemDrag, &ptItem); // ptItem is relative to (0,0) and
>not the view origin
>GetOrigin(&m_ptOrigin);
>ASSERT(m_pimageListDrag == NULL);
>m_pimageListDrag = CreateDragImage(m_iItemDrag, &ptImage);
>m_sizeDelta = ptAction - ptImage; // difference between cursor pos and
>image pos - change me
>m_ptHotSpot = ptAction - ptItem + m_ptOrigin; // calculate hotspot for
>the cursor
/***** Remove lines below -- note that DragShowNoLock and DragEnter in fact,
are mutualy exclusive; *****/
>m_pimageListDrag->DragShowNolock(TRUE); // lock updates and show drag
>image - false?
>m_pimageListDrag->SetDragCursorImage(0, m_ptHotSpot); // define the hot
>spot for the new cursor image
/***** Change the line ******/
>m_pimageListDrag->BeginDrag(0, CPoint(0, 0));
/***** like *****/
>m_pimageListDrag->BeginDrag(0, m_ptHotSpot);
>ptAction -= m_sizeDelta;
>m_pimageListDrag->DragEnter(this, ptAction);
/***** I think this line will be removed too *****/
>m_pimageListDrag->DragMove(ptAction); // move image to overlap original
>icon
>
>SetCapture();
>}
>
Good luck,
Dmitry