Solved

Drag & drop between views: a better way needed

Posted on 2006-06-21
12
634 Views
Last Modified: 2013-11-20
Ah hello.

I have an app that supports drag/drop from a tree control.  I also have a part of the same app that supports drag drop from a list view into the tree control.

What I want is some sort of generic treeview/listview that supports dragging and dropping.  Currently, in the list view, I do this:

void CFileView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{      
      m_bIsDragging = TRUE;
      // Create drag image and display it
}

void CFileView::OnMouseMove(UINT nFlags, CPoint point)
{
      UINT uFlags;

      m_bSafeDropTarget = FALSE;

      if (m_bIsDragging)
      {
            CPoint pt(point);    
            ClientToScreen(&pt);

            CMyTargetView* pTargetView = NULL;
            m_pDragImage->DragMove(pt);
            m_pDropWnd = WindowFromPoint(pt);

            if ((m_pDropWnd->IsKindOf (RUNTIME_CLASS (CMyTargetView)))) // CMyTargetView is CTreeView derived
            {
                  // Valid drop window, handle this
                  m_bSafeDropTarget = TRUE;

                  // etc...
            }
            else
            {
                  // Invalid drop window, handle this.  
                  // Maybe display some sort of cursor to indicate invalid drop target etc                        }
      }
}

I don't like this; all the code is bundled up, and what if I want to add different drop target types ?

There must be a better way of doing this.

Please can someone point me at an example, or list some better code.

TIA
0
Comment
Question by:mrwad99
[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
  • 6
  • 5
12 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16957535
Refer following link 'Enhanced Drag and Drop between CListCtrl and CTreeCtrl'
http://www.codeguru.com/cpp/controls/treeview/dragdrop/comments.php/c697/?thread=7800 <====

you may also have look at no. of other articles here regarding this :
http://www.codeguru.com/cpp/controls/treeview/dragdrop/article.php/c697/
http://www.codeguru.com/cpp/controls/treeview/dragdrop/

-MAHESH
0
 
LVL 19

Author Comment

by:mrwad99
ID: 16958991
MAHESH

Thanks.  Those links really deal with dragging and dropping between the same tree control.  Although they give some nice pointers on separating out common functionality, that is not really what I am looking for.

I need to deal with dragging from *one tree control onto another*.  Not dragging and dropping within the *same* control.

I asked a similar question before at http:Q_21313497.html - but left it alone back then as another task came up.  Andy mentions passing a custom message to the drop target via SendMesssage.

What do you think of this ?

TIA
0
 
LVL 22

Assisted Solution

by:mahesh1402
mahesh1402 earned 250 total points
ID: 16959901
>>I need to deal with dragging from *one tree control onto another*.

Better to implement 'OLE Drag and Drop' based on COleDropTarget class.
Have look at this for reference 'Drag text between edit controls'
http://www.codeguru.com/cpp/controls/editctrl/article.php/c535/ <==

Also 'Drag and Drop between Tree controls'
http://www.codeguru.com/cpp/controls/treeview/dragdrop/article.php/c659/

-MAHESH
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!

 
LVL 22

Expert Comment

by:mahesh1402
ID: 16959969
I need to deal with dragging from *one tree control onto another*.  Not dragging and dropping within the *same* control.<<

Actually sample 'MFCDRAG' shows how to implement drag and drop between a CListCtrl and CTreeCtrl

http://support.microsoft.com/kb/q148738/ <== CListCtrl to CTreeCtrl, CListCtrl to CListCtrl, CTreeCtrl to CListCtrl, CTreeCtrl to CTreeCtrl ...

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16960046
>>I want to add different drop target types ?

Detect Begin Drag in the Tree Control. There you initialise whatever you need to for your drag and drop operation.
Then you give mouse control to the parent. In your main class you'll have your OnMouseMove handler, which, if dragging is in progress, will look after the actual dragging. In the ::OnLButtonUp handler, again, if dragging is active, first release the mouse by ReleaseCapture( ) then check if the mouse is positioned over the relevant destination control. If not, do nothing or give some feedback; if it is over the desired control, you should have that control handle the event.

So relay the event to the control using SendMessage or else simply call a routine defined in the control's class that handles the drop operation.

-MAHESH
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points
ID: 16962517
The message I proposed (in the previous question) was to determine if the recipient was a valid drop target.  (I have a situation for example that some items can NOT be dropped onto the root item or vice versa - ONLY to the root item).



Generic routines - this technique should work and be fairly general.

class CDragDropTree : public CTreeCtrl, public CMyDragObject
{
....

and
class CDragDropList : public CListCtrl, public CMyDragObject
{
....


now you implement a suite of functions in you class CMyDragObject that give you the common functionality you desire.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16969284
mrwad99,
One more thing when you drop target and you want to verify its a valid window you may effectively use 'GetWindowFromPoint()' function... something like  :

void CMyView::OnLButtonUp((UINT nFlags, CPoint point)
{
      ....

     //GET THE WINDOW UNDER THE DROP POINT
        GetApp()->cDropPoint = point;
        ClientToScreen(&GetApp()->cDropPoint);
        GetApp()->cpDropWnd = WindowFromPoint(GetApp()->cDropPoint);

     //Verification code  
        .....
}

Refer :
Drag and drop between views in a splitter window
http://www.codeguru.com/cpp/w-d/splitter/article.php/c1545/ <=== this demonstrate drag & drop operation within an explorer style project splitter window with left hand treeView and right hand listView !

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16969297
Read as  'WindowFromPoint' and NOT GetWindowFromPoint
0
 
LVL 19

Author Comment

by:mrwad99
ID: 17026916
Thanks for the info so far.  I have not finished with this yet, so will leave it open until I have all the info I need.  
0
 
LVL 19

Author Comment

by:mrwad99
ID: 17071803
Will be back to this question soon, thanks again for the patience :)
0
 
LVL 19

Author Comment

by:mrwad99
ID: 17176809
Coming back to this by the end of the week...
0
 
LVL 19

Author Comment

by:mrwad99
ID: 17241424
There will be a follow up to this posted shortly.

Thanks for the help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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: 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. …
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.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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