Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

OLEDragPicture, OLEGiveFeedback

This property and method give you control over what the user sees during OLE Drag and Drop. OLEDragPicture controls the image of what’s being dragged. OLEGiveFeedback is a method that lets you change the cursor used for the drag, as well as take other actions if you want.

Usage

oObject.OLEDragPicture = cPictureFile
cPictureFile = oObject.OLEDragPicture
PROCEDURE oObject.OLEGiveFeedback
LPARAMETERS nEffect, eMouseCursor

Parameter

Value

Meaning

cPictureFile

Filename

The name of the file containing the graphic to show being dragged.

nEffect

Numeric

The reaction of the object currently under the mouse to OLE drag and drop. Indicates whether a drop is welcome and, if it is, what the result is.

eMouseCursor

0

Use the cursor specified by the drop target for nEffect. We have no control over what that cursor is, but most objects seem to make good choices.

1-16

Specifies which of the built-in cursor graphics is currently being used or should be used.

Numeric other than 0-16

Only the regular mouse pointer appears.

Filename

The name of a graphic file containing the mouse pointer currently in use or the one that should be used.

It’s always nice to let users know what’s going on. With OLE Drag and Drop, there are two pieces of information you can provide.

The first is a picture of what’s being dragged. For example, in Windows Explorer, if you drag a single file, you see its name and icon going with you; when you drag a group of files, you get an outline of a bunch of boxes that sort of look like filenames and icons. In VFP, OLEDragPicture provides this information. It belongs to the drag source (the object you’re dragging from). Most often, we think, you’ll set this one in the Property Sheet and leave it alone. In some cases, though, you might want to set it in OLEStartDrag based on what’s actually highlighted and being dragged.

You can change OLEDragPicture on the fly, even while a drag is occurring, but the actual picture doesn’t change until the current drag ends and you start another.

The second piece of information users want is what will happen if you drop at the current position. Rather than having a property that controls this, there’s a method that fires and lets you specify what the user should see. OLEGiveFeedback fires each time you drag over something. (Free translation: this one fires a lot.) It tells you how the something will handle a drop if you release the mouse button, and what mouse cursor is currently in use. Unlike most events in VFP, though, the second parameter, eMouseCursor, is passed by reference, so you can change the cursor. You can set eMouseCursor to the name of a graphic cursor file (CUR or ANI). You can’t use ICO files, however.

OLEGiveFeedback is a drag source event, so it fires even when you're dragging over objects outside VFP. That's right, you can drag data from VFP into other apps and still control the mouse cursor. Giving control to the drag source is generally an improvement over VFP's native drag and drop, where the target can tell the source what DragIcon to use, but the source can't do anything about it.

While the nEffect parameter lets us know what action a drop will bring, it doesn’t tell us what object we’re over. Seems to us that passing a reference to the potential drop target would be handy. The new AMouseObj() function to the rescue. You can find out not only the drop target itself, but its container as well.

Example

* Specify a cursor based on the potential drop action
* Most drop targets will provide the usual cursors anyway,
* so we'll do strange things here.

LPARAMETERS nEffect, eMouseCursor

DO CASE
CASE nEffect = 0 && Can't drop here
   eMouseCursor = 11  && Hourglass - that'll confuse 'em
CASE nEffect = 1 && Copy
   eMouseCursor = 5 && Sizer
OTHERWISE
   eMouseCursor = 3 && I-Beam, why not?
ENDCASE

See Also

OLE drag and drop, OLEDragOver, OLEDropEffects