当鼠标移动未注册为COleDropTarget窗口的窗口时,如何在拖放过程中更改默认光标? [英] How to change the default cursor during drag and drop when the mouse moving the window which is not registered as the COleDropTarget window?
问题描述
我的问题与MFC编程中的拖放方面有关.
我知道有四个类(COleDataSource
,COleDataObject
,COleDropTarget
和COleDropSource
)可以实现拖放功能.数据源(由COleDataSource
对象实现)表示数据传输的源端.数据对象(由COleDataObject
对象实现)表示数据传输的目标端.COleDropTarget
提供了窗口与OLE库之间的通信机制.要使窗口接受放置命令,您首先应创建一个COleDropTarget
类的对象,然后使用指向所需CWnd
对象的指针作为唯一参数来调用Register函数.
COleDropTarget
类处理拖放操作的接收部分. COleDropSource
对象负责确定拖动操作何时开始,在拖动操作期间提供反馈以及确定拖动操作何时结束.
下降效果如下:
DROPEFFECT_NONE:
放置目标无法接受数据.对应的光标是
DROPEFFECT_COPY:
拖放将产生副本.原始数据不受拖动源的影响.对应的光标是
DROPEFFECT_MOVE
:拖动源应删除数据.对应的光标是
DROPEFFECT_LINK
:放置目标会将数据链接到".对应的光标是
这些光标不显示.但是我相信您也知道它们.这些光标是拖放时的默认光标.
现在,我想用自己的光标更改它们.我可以通过COleDropSource::GiveFeedback()
函数更改这些默认光标.该功能的规范在MSDN中进行了描述.
这是我的代码部分,用于更改默认光标.
1.重写COleDropSource
的类和相关函数
My question is related to the aspect of drag and drop in MFC programming.
I know there are four classes (COleDataSource
,COleDataObject
,COleDropTarget
and COleDropSource
)which can realize the function of drag and drop. Data sources (as implemented by COleDataSource
objects) represent the source side of the data transfer. Data objects (as implemented by COleDataObject
objects) represent the destination side of the data transfer.The COleDropTarget
provides the communication mechanism between a window and the OLE libraries.To get a window to accept drop commands, you should first create an object of the COleDropTarget
class, and then call the Register function with a pointer to the desired CWnd
object as the only parameter.
The COleDropTarget
class handles the receiving portion of the drag-and-drop operation. The COleDropSource
object is responsible for determining when a drag operation begins, providing feedback during the drag operation, and determining when the drag operation ends.
The drop effects are like this:
DROPEFFECT_NONE:
Drop target cannot accept the data. Corresponding cursor is
DROPEFFECT_COPY:
Drop results in a copy. The original data is untouched by the drag source. Corresponding cursor is
DROPEFFECT_MOVE
: Drag source should remove the data. Corresponding cursor is
DROPEFFECT_LINK
: The data will be "linked to" by the drop target. Corresponding cursor is
These cursors are not displayed. But i am sure you know them also.These cursors are default cursors when drop and drop.
Now i want to change them with my own cursors. I can change these default cursors through the COleDropSource::GiveFeedback()
function. The specification of the function is described in MSDN.
Here is the part of my codes to change the default cursor.
1.override the class of COleDropSource
and the related function
//override the class
class CDropSource: public COleDropSource
{
public:
CDropSource();
// Overrides
SCODE GiveFeedback(DROPEFFECT dropEffect);
virtual SCODE QueryContinueDrag(BOOL bEscapePressed, DWORD dwKeyState);
virtual BOOL OnBeginDrag(CWnd* pWnd);
};
//override the function of GiveFeedback to change these default cursors
SCODE CDropSource::GiveFeedback(DROPEFFECT dropEffect)
{
//change the default cursor corresponding to drop effect
//the new cursor can be either the other system cursors or the cursors //that user define
ASSERT_VALID(this);
switch(dropEffect)
{
case DROPEFFECT_NONE:
//change the default cursor corresponding to DROPEFFECT_NONE
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_MOVE:
//change the default cursor corresponding to DROPEFFECT_MOVE
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_COPY:
//change the default cursor corresponding to DROPEFFECT_COPY
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_LINK:
//change the default cursor corresponding to DROPEFFECT_LINK
SetCursor(AfxGetApp()->LoadCursor(IDC_DRAGSRC));
break;
case DROPEFFECT_SCROLL:
//change the default cursor corresponding to DROPEFFECT_SCROLL
SetCursor(LoadCursor(NULL,IDC_NO));
break;
}
return S_OK;
// don''t change the cursor until drag is officially started
return m_bDragStarted ? DRAGDROP_S_USEDEFAULTCURSORS : S_OK;
}
2.开始拖动时将CDropSource的成员传递给COleDataSource :: DoDragDrop函数
2.pass the member of CDropSource to the COleDataSource::DoDragDrop function when beginning drag
//begin drag
CDropSource m_DropSource;
COleDataSource source;
source.CacheGlobalData(m_nformat, hData );
source.DoDragDrop(DROPEFFECT_LINK,NULL,&m_DropSource);
GlobalFree( hData );
//end drag
现在的问题在这里.有两种情况.
首先,如果将窗口注册为COleDropTarget
窗口,则在CDropSource::GiveFeedback
函数中更改默认光标生效,并且可以更改四个默认光标.
其次,如果该窗口未注册为COleDropTarget窗口,则GiveFeedback
函数中dropEffect
的参数值为DROPEFFECT_NONE.现在无法更改默认光标,SetCursor
功能无效.
在第二种情况下如何更改默认光标?
我的英语不好,我希望你能理解我的意思.非常感谢.
问题已经上传了一天,但没有答案.我相信必须有人可以解决这个简单的问题.我真的需要你的帮助.非常感谢.
我更新了您的问题的格式以使其可读".
-E,G .-
Now the question is here. There are two situations.
First,if the window is registered as the COleDropTarget
window,then changing default cursor in CDropSource::GiveFeedback
function is in effect and the four default cursors are can be changed.
Second, if the window is not registered as the COleDropTarget window, then the parameter value of dropEffect
in GiveFeedback
function is DROPEFFECT_NONE. And now the default cursor can not be changed, the SetCursor
function is of no effect.
And how can i change the default cursor in the second situation?
My english is bad, i wish you can understand my meaning above. Thanks very much.
The question has been uploaded for one days,but there has no answer for the question. I believe that there must be somebody who can resolve this simple question. I really need your help. Thanks a lot.
I updated the format of your question to make it "readable".
-E,G.-
推荐答案
我猜:-O,
它不属于MFC拖放原理
允许未注册"窗口(例如CSplitterWnd
)
更改Source::DoDrag()
循环中的拖动光标...:)
I guess :-O ,
it does not lie in the MFC Drag&Drop philosophy
to allow the "not registered" windows (for exampleCSplitterWnd
)
to change the drag cursor inside ofSource::DoDrag()
loop... :)
嗨!...
我陷入了同样的问题.首先,我感谢解决方案的贡献者!!!我对以前的解决方案感到困惑.请澄清一下DoDrag方法是CDropSource还是COleDataSource的成员.我检查了两个类的成员函数,找不到DoDrag().期待您的宝贵建议.
谢谢
Hi !!..
I am stuck in the same problem. First of all , I thank the solution contributor !!! I am bit confused about previous solution. Could please clarify that the DoDrag method is member of CDropSource or COleDataSource ?. I checked both class''s member functions, I couldnt find out DoDrag(). Expecting your valuable suggestions.
Thanks
对于解决方案1,我无法理解您的意思.原因是DoDrag()方法不是COleDateSource的成员.我想,如果您想谈谈DoDragDrop方法?
坦克skaprakash.
For soluton 1, I can''t understand your meaning. Of cause the DoDrag() method is not the member of COleDateSource. I guess, if you want to talk about DoDragDrop method?
Tanks skaprakash.
这篇关于当鼠标移动未注册为COleDropTarget窗口的窗口时,如何在拖放过程中更改默认光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!