[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Ownerdraw CLIstCtrl drag&drop

Posted on 1997-11-16
9
Medium Priority
?
814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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