• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 831
  • Last Modified:

Autioscroll while dragging CListCtrl

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
winmeister
Asked:
winmeister
  • 3
  • 3
1 Solution
 
galkinCommented:
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
 
winmeisterAuthor Commented:
My CListCtrl is not an OLE element. It doesn't scroll by itself.
0
 
galkinCommented:
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
Independent Software Vendors: 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!

 
winmeisterAuthor Commented:
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
 
galkinCommented:
Did you specify DROPEFFECT_SCROLL in COleDragSource DoDragDrop?
0
 
winmeisterAuthor Commented:
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
 
richhxbCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now