Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

Simple Drag and Drop Question

I am attempting to perform simple dragging and dropping in a non-ole application (in fact it is a simple dialog based app).  

I have created a cwnd derived child window, made it a drop target (using coledroptarget), and inserted it into my dialog box.  in my OnLButtonDown message handler inside my dialog box class i create a data source (coledatasource) and immediately call DoDragDrop()- using all default arguments.  It was my understanding that this routine would not return until the mouse button is released to end the drag/drop operation.  Instead, what i see is that DoDragDrop returns immediately with a return value of 0.

Is this implementation of drag/drop completely off base?  The mfc knowledge base article "drag and drop: implementing a drop source" basically tells me that what i did was correct.  Whats going on?

thanks, in advance.
0
brickb
Asked:
brickb
1 Solution
 
gelbertCommented:
COleDataSource::DoDragDrop():
The drag-and-drop operation does not start immediately. It waits until the mouse cursor leaves the rectangle specified by lpRectStartDrag or until a specified number of milliseconds have passed. If lpRectStartDrag is NULL, the size of the rectangle is one pixel. The delay time is specified by the DragDelay value in the [Windows] section of WIN.INI. If this value is not in WIN.INI, the default value of 200 milliseconds is used.

See details in VC++ help for this function.

But I think you do not need OLE support to implement drag and drop. As soon as you detected that user wants to start drag and drop( check in OmMouseMove if left mouse button is down (use some flag which is set TRUE in OnLbuttonDown() and FALSE in OnLButtonUp()) and mouse in moving) then change cusrsor shape to
which ever you want to indicate drag and drop operation by using SetCursor() in OnMouseMove() and setting the same cursor with SetClassLong() if neccessary. When you detect OnLButtonUp in target window then change cursor shape to normal and copy data from source. You can also handle Esc key to let user stop drag and drop operation
0
 
brickbAuthor Commented:
thank you gelbert.  your response contained many good points.

it turns out that my problem was that i was not calling AfxOleInit() in my InitInstance().


Bob Brickhouse
Grayson Wireless
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now