Solved

Autioscroll while dragging CListCtrl

Posted on 1997-12-23
7
769 Views
Last Modified: 2013-11-19
In my CListView I have implemented items drag&drop (OnBeginDrag, etc..)
Now I need that the CListCtrl scrolls automatically when the item is dragged above or below client area. How??
0
Comment
Question by:winmeister
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1312951
OLE itself scrolls target window when mouse pointer within a boder approximately 4 pixels(defined in WIN.INI). I suppose tt gets window using WindowFromPoint and calls ScrollWindow(Ex)
0
 
LVL 1

Author Comment

by:winmeister
ID: 1312952
My CListCtrl is not an OLE element. It doesn't scroll by itself.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1312953
Implement drop target using COleDropTarget MFC class. Call its register in CListCtrl derved class OnCreate message handler. By such a way you registeryou list control as OLE drop target. Now it will be scrolled.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:winmeister
ID: 1312954
Sorry galkin, but I just did that way and it still doesn't work.
I have create a class instance (private) of COleDropTarget:

COleDropTarget m_dropTarget;

and then I have added this method:

int CListViewEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CListView::OnCreate(lpCreateStruct) == -1)
            return -1;
      
      // TODO: Add your specialized creation code here
      m_dropTarget.Register(this);
      return 0;
}

...but when dragging an item, the list doesn't scroll. I am dragging items with OnBeginDrag method.

0
 
LVL 7

Expert Comment

by:galkin
ID: 1312955
Did you specify DROPEFFECT_SCROLL in COleDragSource DoDragDrop?
0
 
LVL 1

Author Comment

by:winmeister
ID: 1312956
Aaah!
I am not using that approach. I have started from the ROWLIST example in VC++ CDROM. If you look at that example, the item dragging is obtained by overriding OnBeginDrag, OnMouseMove  and OnLButtonUp methods. No OLE support.
My application is almost finished and I have just this open item, so I don't want to change all the philosophy.
Besides this, I don't think it is necessary an OLE support to move items in a CListCtrl!

0
 
LVL 1

Accepted Solution

by:
richhxb earned 70 total points
ID: 1312957
You have to create your own CListDropTarget class derived
from COleDropTarget.

class CListDropTarget : public COleDropTarget
{
public:
    CListDropTarget()
    {
      ms_bBeginDrop=FALSE;
      ms_pListCtl=NULL;
    }

    BOOL        Register(CListViewEx* pList);
    BOOL        OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
    DROPEFFECT  OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
    void        OnDragLeave(CWnd* pWnd);
    DROPEFFECT  OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
      DROPEFFECT  OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point);

private:
    BOOL        ms_bBeginDrop;
    CListViewEx*  ms_pListCtl;
};

First, override Register function in CListDropTarget.

BOOL CListDropTarget::Register(CListViewEx* pListView)
{
    ms_pListCtl=pListView;
    return COleDropTarget::Register(pListView);
}

Then, register your ListView as a drop target in your
own CListViewEx::OnCreate function.

CListDropTarget m_dropTarget;
m_dropTarget.Register(this);

Last, you should also override OnDragScroll function
in your CListDropTarget class.

DROPEFFECT CListDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point)
{
    //Since pWnd is a kind of CView, we let COleDropTarget to handle it.
      if (pWnd->IsKindOf(RUNTIME_CLASS(CView)))
            return COleDropTarget::OnDragScroll(pWnd,dwKeyState,point);
}

Now it should works.




0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
Process filename extension 3 156
windows 10 how make picture as desktop background 2 49
Hibernate methods 2 58
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

26 Experts available now in Live!

Get 1:1 Help Now