Solved

Ownerdraw CLIstCtrl drag&drop

Posted on 1997-11-16
9
794 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
 

Expert Comment

by:mileta
ID: 1310038
Hi,
Look at www.codeguru.com for ListView control.  There are source code for it.
Mileta
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Importing  SSL Certificate into Firefox using GPO 28 196
List out all word 7 224
EvenOdd challenge 10 83
sumHeights  challenge 17 61
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now