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
class CDropSource: public COleDropSource
{
public:
CDropSource();
SCODE GiveFeedback(DROPEFFECT dropEffect);
virtual SCODE QueryContinueDrag(BOOL bEscapePressed, DWORD dwKeyState);
virtual BOOL OnBeginDrag(CWnd* pWnd);
};
SCODE CDropSource::GiveFeedback(DROPEFFECT dropEffect)
{
ASSERT_VALID(this);
switch(dropEffect)
{
case DROPEFFECT_NONE:
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_MOVE:
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_COPY:
SetCursor(LoadCursor(NULL,IDC_NO));
break;
case DROPEFFECT_LINK:
SetCursor(AfxGetApp()->LoadCursor(IDC_DRAGSRC));
break;
case DROPEFFECT_SCROLL:
SetCursor(LoadCursor(NULL,IDC_NO));
break;
}
return S_OK;
return m_bDragStarted ? DRAGDROP_S_USEDEFAULTCURSORS : S_OK;
}
2.pass the member of CDropSource to the COleDataSource::DoDragDrop function when beginning drag
CDropSource m_DropSource;
COleDataSource source;
source.CacheGlobalData(m_nformat, hData );
source.DoDragDrop(DROPEFFECT_LINK,NULL,&m_DropSource);
GlobalFree( hData );
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.-