拖动的控件问题???高手请进,小弟虚心讨教!

xbjob 2001-08-17 04:28:58
纵观VC、VB、photoshop一类可视化的具有拖动功能的编辑器,各个控件(部件)可以在表单内随意的拖动,拖动的时候产生了一个虚框(或者其他的东东),鼠标指针也会有一些变化!而且当鼠标指针超出了表单的区域(就是说,这个表单接受不到MouseMove消息了) ,这个框有的就消失了(photoshop),有的停留在表单的边上(VC,对话框编辑器),而鼠标的形状变成了 不能拖放的标志(一个圆,中间一个斜杠)!请问用VC调用什么实现的???
...全文
270 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
stilllikeyou 2001-09-03
  • 打赏
  • 举报
回复
xbjob兄,给我Email:lan@163.net ,我给你源程序!
xbjob 2001-08-31
  • 打赏
  • 举报
回复
有源程序吗?
xianglusong 2001-08-31
  • 打赏
  • 举报
回复
COleDropTarget, COleDropSource...
MSVCer 2001-08-31
  • 打赏
  • 举报
回复
perhaps this is what you want
http://www.codeguru.com/controls/resize.shtml
蒋晟 2001-08-31
  • 打赏
  • 举报
回复
MSDN DRAWCLI Sample
MSVCer 2001-08-28
  • 打赏
  • 举报
回复
_
蒋晟 2001-08-27
  • 打赏
  • 举报
回复
装金山词霸先
xbjob 2001-08-27
  • 打赏
  • 举报
回复
中文的最好,e文我看不太明白,有源程序就好了!
MSVCer 2001-08-26
  • 打赏
  • 举报
回复
偷偷跟上,别落下
haoliangli 2001-08-26
  • 打赏
  • 举报
回复
gz
蒋晟 2001-08-26
  • 打赏
  • 举报
回复
上面那个示例不够详细?
lili2000 2001-08-26
  • 打赏
  • 举报
回复
gz
xbjob 2001-08-26
  • 打赏
  • 举报
回复
有高手吗?能详细的说说吗?可以加分,保证给分!
蒋晟 2001-08-22
  • 打赏
  • 举报
回复
from MSDN:
DRAWCLI: Illustrates Windows 95 Logo Compliance
......

Handling a Drag-and-Drop Operation
Home | Overview | How Do I

The actual work of handling a drag-and-drop operation is done by overriding four member functions defined by CView:

virtual BOOL OnDrop(COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point);
virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject,
DWORD grfKeyState, CPoint point);
virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject,
DWORD grfKeyState, CPoint point);
virtual void OnDragLeave();

These functions are called by the OLE system DLL (via the MFC framework) during a drag-and-drop operation.

The first function called during an actual drag-and-drop operation is OnDragEnter, which is called when the mouse first enters the window:

DROPEFFECT CDrawView::OnDragEnter(COleDataObject* pDataObject,
DWORD grfKeyState, CPoint point)
{
ASSERT(m_prevDropEffect == DROPEFFECT_NONE);
m_bDragDataAcceptable = FALSE;
if (!COleClientItem::CanCreateFromData( pDataObject ))
return DROPEFFECT_NONE;

GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
CClientDC dc(NULL);
dc.HIMETRICtoDP(&m_dragSize);
dc.HIMETRICtoDP(&m_dragOffset);

return OnDragOver(pDataObject, grfKeyState, point);
}

This function first checks whether the COleDataObject provided by the drop source contains data that DRAWCLI can use. If not, the function sets a flag indicating that the data is unacceptable, and returns DROPEFFECT_NONE, indicating that a drop operation would have no effect. On the other hand, if DRAWCLI can use the data, the function computes the size and position of the focus rectangle. It does this by using the GetObjectInfo helper function to get the size of the object in the COleDataObject object.

The next function called during a drag-and-drop operation is OnDragOver, which is called whenever the mouse moves within the window. This function is responsible for determining whether the window can accept the drop operation, and if so, for providing target feedback:

DROPEFFECT CDrawView::OnDragOver(COleDataObject*,
DWORD grfKeyState, CPoint point)
{
if (m_bDragDataAcceptable == FALSE)
return DROPEFFECT_NONE;

point -= m_dragOffset; // adjust target rect by cursor offset

// check for point outside logical area
// GetTotalSize() returns the size passed to SetScrollSizes()
CRect rectScroll(CPoint(0, 0), GetTotalSize());

CRect rectItem(point,m_dragSize);
rectItem.OffsetRect(GetDeviceScrollPosition());

DROPEFFECT de = DROPEFFECT_NONE;
CRect rectTemp;
if (rectTemp.IntersectRect(rectScroll, rectItem))
{
// check for force link
if ((grfKeyState & (MK_CONTROL|MK_SHIFT)) ==
(MK_CONTROL|MK_SHIFT))
de = DROPEFFECT_NONE; // we don’t support linking
// check for force copy
else if ((grfKeyState & MK_CONTROL) == MK_CONTROL)
de = DROPEFFECT_COPY;
// check for force move
else if ((grfKeyState & MK_ALT) == MK_ALT)
de = DROPEFFECT_MOVE;
// default -- recommended action is move
else
de = DROPEFFECT_MOVE;
}

if (point == m_dragPoint)
return de;

// else, cursor has moved -- need to update the drag feedback
CClientDC dc(this);
if (m_prevDropEffect != DROPEFFECT_NONE)
{
// erase previous focus rect
dc.DrawFocusRect(CRect(m_dragPoint, m_dragSize));
}
m_prevDropEffect = de;
if (m_prevDropEffect != DROPEFFECT_NONE)
{
m_dragPoint = point;
dc.DrawFocusRect(CRect(point, m_dragSize));
}
return de;
}

This function first checks the flag m_bDragDataAcceptable to see if it’s necessary to do any more processing. If so, the function then checks which, if any, keys are being depressed, determining whether the user wants a link operation, a move, or a copy. Since DRAWCLI isn’t a linking container, this function returns DROPEFFECT_NONE when a link operation is specified, meaning that the view won’t accept the dragged object. DRAWCLI does accept copy or move operations, so the function returns DROPEFFECT_COPY and DROPEFFECT_MOVE in those instances. (The drop source receives these DROPEFFECT values and modifies the mouse cursor appropriately.) Finally, if the operation is a copy or a move, the function draws the focus rectangle to indicate where the object would land if it were dropped.

If the mouse leaves the window without having dropped the object, the function that gets called is OnDragLeave. This function simply performs a little clean-up:

void CDrawView::OnDragLeave()
{
CClientDC dc(this);
if (m_prevDropEffect != DROPEFFECT_NONE)
{
// erase previous focus rect
dc.DrawFocusRect(CRect(m_dragPoint,m_dragSize));
m_prevDropEffect = DROPEFFECT_NONE;
}
}

If the drag-and-drop operation was one that DRAWCLI was willing to accept, the function removes the target feedback by erasing the last focus rectangle drawn.

Finally, the function that gets called if the user actually performs the drop is OnDrop:

BOOL CDrawView::OnDrop(COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point)
{
ASSERT_VALID(this);

// clean up focus rect
OnDragLeave();

// offset point as appropriate for dragging
GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
CClientDC dc(NULL);
dc.HIMETRICtoDP(&m_dragSize);
dc.HIMETRICtoDP(&m_dragOffset);
point -= m_dragOffset;

// invalidate current selection since it will be deselected
OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
if (m_bDragDataAcceptable)
PasteEmbedded( *pDataObject, point );

// update the document and all views
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(NULL, 0, NULL);

return TRUE;
}

This function determines the point at which the dropped object resides, deselects the currently selected object, and creates an OLE embedded object, using the COleDataObject object provided by the drop source. Note that the CDrawView::PasteEmbedded function now takes an additional parameter compared with the previous version of DRAWCLI; this parameter lets the caller specify the location of a new embedded object, something that is unnecessary for Paste operations but is useful for drag-and-drop operations.

It would also be possible to make DRAWCLI a drop source, allowing the user to drag a selection from one of DRAWCLI’s windows into another application’s. However, DRAWCLI doesn’t offer any common Clipboard formats, nor is DRAWCLI an OLE server, so there are no applications that could accept a dragged object originating from DRAWCLI. Consequently, the current version of DRAWCLI would not be a useful drop source.

For more information on MFC’s drag-and-drop support, see Drag and Drop (OLE). For more information about drag-and-drop in general, see Inside OLE or the OLE documentation on the MSDN Library CD.


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
xbjob 2001-08-22
  • 打赏
  • 举报
回复
能够告诉我的同志,我出300分!!!
as good as well 2001-08-21
  • 打赏
  • 举报
回复
关注!
xbjob 2001-08-21
  • 打赏
  • 举报
回复
wait
xbjob 2001-08-21
  • 打赏
  • 举报
回复
谢谢,可是photoshop, vc 他们都是这么做的吗?
tryibest 2001-08-21
  • 打赏
  • 举报
回复
是继承了CDialogBar,
CToolbar,什么的都从他继承而来的,你可以写一个继承类,就可以实现这样的功能,不过
好像新的vc里有一个CDock类,
还有你要注意生明xxx.enabledocking.
docking(xxx)
这样你的写的控件就可以在窗口悬停了,
我看过一点原代码,大概5000行吧,
xbjob 2001-08-21
  • 打赏
  • 举报
回复
高手???
加载更多回复(2)

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧