Solved

Autioscroll while dragging CListCtrl

Posted on 1997-12-23
7
800 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
[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
  • 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
Industry Leaders: 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 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

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!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

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