开发者

COleDataSource/COleDropTarget cancel drag&drop operation

开发者 https://www.devze.com 2022-12-11 03:30 出处:网络
I have implemented my custom drag&drop by deriving from COleDataSource and COleDropTarget. Everythings work fine but I have an scenario that makes the application crashes.

I have implemented my custom drag&drop by deriving from COleDataSource and COleDropTarget. Everythings work fine but I have an scenario that makes the application crashes.

That happens when the dialog where the drag&drop controls are placed is destroyed while the user is in the middle of a drag&drop operation. This is not usual because normally to close a dialog the user have to use the mouse or the keyboard and then the 开发者_运维知识库drag&drop operation is automatically canceled. But in this scenario the dialog can be closed due to an external condition (a custom message that changes the view) and then the drap&drop operation is not canceled.

So my question is, how can I programmatically cancel the drag&drop operation? The operation is started from the OnLButtonDown message handle calling COleDataSource::DoDragDrop.

Update:

I've implemented using DelayRender and it continues crashing. These are the two asserts I am getting:

  1. When the mouse pointer (while dragging) is inside a control that is a COleDropTarget-derived class.

alt text http://www.freeimagehosting.net/uploads/b34a62c5ac.jpg

The assert is in the Revoke method and this is the line:

ASSERT(m_lpDataObject == NULL);
  1. When the mouse pointer is not inside a COleDropTarget-derived class.

alt text http://www.freeimagehosting.net/uploads/a0e8298490.jpg

In this case the assert is in the destruction of the COleDataSource (in fact it is in its parent class CCmdTarget). In this line:

ASSERT(m_dwRef <= 1);

Thanks in advance!


I noticed this type of crash starting with Windows Vista. Make sure the COleDataSource is created on the heap!

CYourDataSource *pSource = new CYourDataSource; pSource->DoDragDrop(); pSource->InternalRelease();


I'm not sure if this would work but you could try overriding the QueryContinueDrag method of the COleDropTarget instance and returning DRAGDROP_S_CANCEL in the case where the dialog has been closed

0

精彩评论

暂无评论...
验证码 换一张
取 消