Solved

Ownerdraw CLIstCtrl drag&drop

Posted on 1997-11-16
9
799 Views
Last Modified: 2013-11-19
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
Comment
Question by:winmeister
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 1310035
Use CListCtrl::RedrawItems() to update positiuon of item on the screen
0
 
LVL 1

Author Comment

by:winmeister
ID: 1310036
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
 

Expert Comment

by:mileta
ID: 1310037
Hi,
Look at www.codeguru.com for ListView control.  There are source code for it.
Mileta
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Expert Comment

by:mileta
ID: 1310038
Hi,
Look at www.codeguru.com for ListView control.  There are source code for it.
Mileta
0
 
LVL 1

Author Comment

by:winmeister
ID: 1310039
I have already checked there, and there is no help for the specific problem. The samples are not concerning ownerdrawn ClistCtrl
0
 
LVL 1

Expert Comment

by:2good
ID: 1310040
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
 
LVL 1

Author Comment

by:winmeister
ID: 1310041
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
 
LVL 1

Accepted Solution

by:
WBerthin earned 50 total points
ID: 1310042
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
 
LVL 1

Expert Comment

by:WBerthin
ID: 1310043
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question