[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 822
  • Last Modified:

Ownerdraw CLIstCtrl drag&drop

I have a normal CListCtrl on which I have successfully implemented a drag&drop feature for its items. Then I was in the need to have an ownerdraw CListCtrl and my drag&drop strated to be defective. When I begin the drag, the dragged image is no more made by the icon+text, but only by the icon. I mean, I have lost the text label on the drag image.

How can I have the full drag image again?

Fabio Marzocca
0
winmeister
Asked:
winmeister
  • 3
  • 2
  • 2
  • +2
1 Solution
 
gelbertCommented:
Use CListCtrl::RedrawItems() to update positiuon of item on the screen
0
 
winmeisterAuthor Commented:
RedrawIItems is used to redraw current items in the list. My problem is related to the "drag image" associated with the cursor and has nothing to do with RedrawItems.

0
 
miletaCommented:
Hi,
Look at www.codeguru.com for ListView control.  There are source code for it.
Mileta
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
miletaCommented:
Hi,
Look at www.codeguru.com for ListView control.  There are source code for it.
Mileta
0
 
winmeisterAuthor Commented:
I have already checked there, and there is no help for the specific problem. The samples are not concerning ownerdrawn ClistCtrl
0
 
2goodCommented:
Visual C++ has a sample called ROWLIST which implements an owner-draw CListCtrl with wider selection. I borrowed that class and it works fine for me when I use DoDragDrop(...) to implement Drag & Drop.
0
 
winmeisterAuthor Commented:
Yes, it worked also for me...until I decided to set the OwnerDraw style. It doesn't work if your CListCtrl is of OwnerDraw type.
0
 
WBerthinCommented:
Hi winmeister,

CreateDragImage does not work for an owner draw list control.
If your item is not selected you can get a proper drag image if
you turn off the owner draw, create the image and then turn
owner draw back on again. If your item is selected, you also
have to turn off the selection, before getting the image. Turn
it on again once the drag image is created.

Assuming your list control is in a parent view the code looks
like this:

//TURN OFF OWNERDRAW AND REMOVE SELECTED STATE
//TO GET A PROPER DRAG IMAGE
m_ListControl.ModifyStyle(LVS_OWNERDRAWFIXED, 0);
LV_ITEM lvi;
ZeroMemory(&lvi, sizeof(LV_ITEM));
lvi.mask = LVIF_STATE;
lvi.stateMask = LVIS_DROPHILITED | LVIS_SELECTED;
m_ListControl.GetItem(&lvi);
if( lvi.state |= LVIS_SELECTED ||
    lvi.state |= LVIS_DROPHILITED )
{
     LV_ITEM lvi2;
     lvi2.state = 0;
     m_ListControl.SetItemState(m_nDragIndex, &lvi2);
     UpdateWindow();
}

//NOW CREATE THE DRAG IMAGE
m_pDragImage = m_ListControl.CreateDragImage(m_nDragIndex, &pt);

//THEN TURN OWNER DRAW BACK ON AND RESTORE THE SELECTED STATE
m_ListControl.ModifyStyle(0, LVS_OWNERDRAWFIXED);
if( lvi.state |= LVIS_SELECTED  ||
    lvi.state |= LVIS_DROPHILITED )
{
      m_ListControl.SetItemState(m_nDragIndex, &lvi);
      UpdateWindow();
}

0
 
WBerthinCommented:
I missed a few brackets on the line that should read:
if( (lvi.state |= LVIS_SELECTED) ||
    (lvi.state |= LVIS_DROPHILITED) )
This line occurs in two places. The |= has to be evaluated
before the ||.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now