where can I download your whole project ? error C2065: 'SelectDropTarget' : undeclared identifier error C2065: 'GetParentItem' : undeclared identifier
ReplyOriginally posted by: astian
How to set the position of the mouse pointer on the screen in VC++
Originally posted by: johnson yang
------
the updated code should be like this:
if (m_bLDragging)
HTREEITEM prev=GetPrevVisibleItem(hitem);
CImageList::DragShowNolock(TRUE);
You can add the codes below into the OnMouseMove event to deal th scroller.(you needn't to use the Timer way described in the other essay.)
HTREEITEM prev=GetPrevVisibleItem(hitem);
HTREEITEM next=GetNextVisibleItem(hitem);
EnsureVisible(prev);
EnsureVisible(next);
------
void CTreeCtrlX::OnMouseMove(UINT nFlags, CPoint point)
{
HTREEITEM hitem;
UINT flags;
{
POINT pt = point;
ClientToScreen( &pt );
CImageList::DragMove(pt);
if ((hitem = HitTest(point, &flags)) != NULL)
{
CImageList::DragShowNolock(FALSE);
SelectDropTarget(hitem);
m_hitemDrop = hitem;
HTREEITEM next=GetNextVisibleItem(hitem);
EnsureVisible(prev);
EnsureVisible(next);
}
}
CTreeCtrl::OnMouseMove(nFlags, point);
}
Originally posted by: Patrick Fitzpatrick
When I use this code, the image that is created for the drag contains the text of the tree item too. If I drag a different tree item, the text does not change and always gives me the text of the first dragged item. Any Idea how to solve this?
This method always returns NULL value I don't know why ? Please help me
ReplyOriginally posted by: Adriana
My program is a Dialog based app and I have included a Tree control, so I don't have a class for CTreeCtrl to create this events from. I was able to create a MouseMove and MouseUp functions but they are from my main dialog (CDialog) and it will work for a short time, then when draging the image will only show in the rest of my dialog except over the tree control.
Does anybody have an idea?. I will really appreciate it. Thanx =D
ReplyOriginally posted by: Anibal Itriago
//in CODE.cpp
void CCustomTreeControl::SetNewParent(HTREEITEM newPosition, HTREEITEM oldPosition)
if(m_bLDragging)
Here you have something that can be usefull in this code.
1. This part copies the old branch info complete.
//in HEADER.h
protected:
HTREEITEM CopyBranch(HTREEITEM oldItem, HTREEITEM newParent, HTREEITEM iPosition);
void SetNewParent(HTREEITEM newPosition, HTREEITEM oldPosition);
...
HTREEITEM CCustomTreeControl::CopyBranch(HTREEITEM oldItem, HTREEITEM newParent, HTREEITEM iPosition)
{
HTREEITEM newItem=InsertItem( GetItemText(oldItem), newParent,iPosition);
SetNewParent(newItem,oldItem);
return newItem;
}
{
HTREEITEM oldChild=GetChildItem(oldPosition);
HTREEITEM newChild;
while(oldChild){
newChild=InsertItem( GetItemText(oldChild), newPosition,TVI_LAST );
SetNewParent(newChild,oldChild);
oldChild=GetNextItem(oldChild, TVGN_NEXT);
}
}
****************************************
2. If you are dragging, and the drag&drop must scroll the client view... that doesn't work fine in this sample... So what I did (still with a little refresh bug) is:
void CCustomTreeControl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
HTREEITEM hitem;
UINT flags;
{
POINT pt = point;
ClientToScreen( &pt );
CImageList::DragMove(pt);
if ((hitem = HitTest(point, &flags)) != NULL)
{
CImageList::DragShowNolock(FALSE);
SelectDropTarget(hitem);
m_hitemDrop = hitem;
CImageList::DragShowNolock(TRUE);
}
RECT rect;
GetClientRect( &rect );
HTREEITEM hitem =GetItemAtPos(point);
SelectDropTarget(hitem);
CImageList::DragShowNolock(FALSE);
Expand(hitem,TVE_EXPAND);//If you want to expand the entire child branch
CImageList::DragShowNolock(TRUE);
if( point.y < rect.top + 10 )
{
// We need to scroll up
// Scroll slowly if cursor near the treeview control
int slowscroll = 6 - (rect.top + 10 - point.y) / 20;
CImageList::DragShowNolock(FALSE);
SendMessage( WM_VSCROLL, SB_LINEUP);
CImageList::DragShowNolock(TRUE);
}
else if( point.y > rect.bottom - 10 )
{
// We need to scroll down
// Scroll slowly if cursor near the treeview control
CImageList::DragShowNolock(FALSE);
SendMessage( WM_VSCROLL, SB_LINEDOWN);
CImageList::DragShowNolock(TRUE);
}
}
CTreeCtrl::OnMouseMove(nFlags, point);
}
.........
:) Enjoy!
Anibal.
Originally posted by: Ben
working great!
ReplyOriginally posted by: Seok Heon Seop[KOREA]
if m_pDragImage is NULL, "delete m_pDragImage" command is fatal error.
repair!!
included patch:
Avoiding flicker during drag'n drop
Minor change to the constructor
[constructor]
CTreeCtrlEx::CTreeCtrlEx()
{
.......
.......
m_pDragImage = NULL;
m_bLDragging = FALSE;
}
void CTreeCtrlEx::OnMouseMove(UINT nFlags, CPoint point)
{
.......
.......
CImageList::DragMove(pt);
hitem = HitTest(point, &flags);
if (hitem != m_hitemDrop)
{
CImageList::DragShowNolock(FALSE);
SelectDropTarget(hitem);
m_hitemDrop = hitem;
CImageList::DragShowNolock(TRUE);
}
.......
.......
}
void CTreeCtrlEx::OnLButtonUp(UINT nFlags, CPoint point)
{
.......
.......
ReleaseCapture();
if(m_pDragImage != NULL)
{
delete m_pDragImage;
m_pDragImage = NULL;
}
.......
.......
}
^____________________^;;;;;;;
Reply
Originally posted by: Mihir
HI all,
the onBeginDrag function never got called.. I think it can be because my tree view has a function called on LButtonDown. so is this the problem?>??????????
I dont know why it never reaches there?
thanks,
mihir.
Originally posted by: Ron Wolfe
I really like the way this code works. I looked for over a week for 'how' to use dragdrop, but stumbled upon this and many thanks to the author. The only trouble I had was, being a newbie, I had a bit of trouble getting it to work, until I realized all I had to do was build a couple bitmap images for it to load. Thanks again.
Reply