Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drag & drop between views: a better way needed

Posted on 2006-06-21
12
Medium Priority
?
639 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
  • 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 45

Accepted Solution

by:
AndyAinscow earned 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

879 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