Solved

Ownerdraw CLIstCtrl drag&drop

Posted on 1997-11-16
9
802 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

691 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