Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing mouse cursor during OLE drag-and-drop

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I am writing code to let the user drag an object around a form. The form is divided into two areas: one where the user is free to drop the object, and a "no-drop" zone where they can't.

This is all working fine, except that I'd like to change the mouse pointer, to indicate where dropping is allowed.

So far, I have this code in the form's OLEDragOver:

Code:
LPARAMETERS oDataObject, nEffect, nButton, nShift, ;
  nXCoord, nYCoord, nState

IF nXCoord < 50 AND nYCoord < 100
  * This is the no-drop zone
  nEffect = 0
ELSE
  nEffect = 1
ENDIF

* Next line is for debugging only
WAIT WINDOW nEffect NOWAIT

I can see from the Wait window that nEffect is being correctly set.

In the OLEGiveFeedback event of the object being dragged (that is, the drag source), I have this code:

Code:
LPARAMETERS nEffect, eMouseCursor

* In the next line, 12 means no-drop cursor
eMouseCursor = IIF(nEffect = 0, 12, 0)

I'm finding that, during the drag, the mouse cursor is initially correct, but it doesn't change as the mouse moves between the two zones. In other words, it always shows the cursor as it should be at the point where the user starts dragging. I can't see how to make it change during the course of the drag.

Can anyone help me out on this?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

The following code is from the .OLEDragOver() event of a grid
Code:
LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState

DO CASE
CASE nState = 0	&& Drag enter
	IF oDataObject.getFormat(15)	;
			OR oDataObject.getFormat(1)
		THIS.OLEDropHasData = 1
		THIS.OLEDropEffects = 1
		nEffect	= 4
	ELSE
		THIS.OLEDropHasData = 0
		THIS.OLEDropEffects = 0
		nEffect	= 0
	ENDIF
CASE nState = 1	&& Drag_LEAVE

CASE nState = 2	&& Drag_Over
	IF oDataObject.getFormat(15)	;
			OR oDataObject.getFormat(1)
		THIS.OLEDropHasData = 1
		THIS.OLEDropEffects = 1
		nEffect	= 4
	ELSE
		THIS.OLEDropHasData = 0
		THIS.OLEDropEffects = 0
		nEffect	= 0
	ENDIF
ENDCASE
The following code is from the .OLEGiveFeedback() event of a grid
Code:
IF nEffect = 0
	eMouseCursor = 12	&& No drop circle with line
ENDI
For reasons various I can't test this app but it was working correctly last time I used it.

Modifying the code might take you towards your objective.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris,

Thanks for your reply, which is interesting.

Your OLEDragOver looks similar to mine. The main difference is that you are taking different action when leaving the target object compared to entering and dragging within the object.

I don't think that difference is relevant to my case. I want the mouse pointer to change at different points within the object, not when entering or leaving.

I see also that you are setting eMouseCursor in the target's OLEGiveFeedback. I was doing it in the source. I understood from the Help that OLEGiveFeedback is a source object event. However, I've tried moving my code the form's OLEGiveFeedback, and it made no difference.

So, I'm no further forward. I'll have to experiment some more.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Could you do something with "invisible" shapes?

Maybe either
[ol]
[li]have a thin shape down the centre of the form and test whether the mouse is to the right or left of it[/li]
[li]or 2 shapes on the left and right of the form, one of which allows dropping and the other doesn't?[/li][/ol]


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Stewart,

In fact, I already have shapes on the form, and these do in fact delineate the drop zone. I use the shapes to determine exactly what happens when the drop occurs.

That part of it is working OK. The problem is that I want to change the mouse pointer when the mouse moves over one of the shapes. I can do that if the user is just moving the mouse normally, but not, it seems, within a drag operation.

Thanks anyway for the suggestion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike - here's an excerpt from the HackFox section on OLEGiveFeedback. Note that I haven't tested this in a long time:

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

 
Tamar,

Thanks for your reply.

But, you know, the first thing I always do when approaching unfamiliar VFP territory is to check with Hackfox. Your "do strange things" code was amongst the first that I tried, and I couldn't get it to work.

I'm still confused about where that code should go -- whether in the OLEGiveFeedback of the source or the target object. But I can't get it to work either way.

Also, I noted your reference to AMOUSEOBJ(), but couldn't see how that came into the picture.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Now that I look at this a little harder, can't you just set OLEDropMode for the possible targets to get the effect you want?

Tamar
 
OK, I think I've solved it.

Basically, all I did was add NODEFAULT to the OLEDragOver. That seems to have done the trick.

To recap and summarise:

The problem arose where one part of the drop target could receive a drop, but another part couldn't. There was no problem where the entire target could either accept the drop or reject it.

To solve the problem, in the drop target's OLEDragOver, I set nEffect to 0 when the mouse was over the no-drop zone. Where dropping wass permitted, I made nEffect 2. The settings for OLEDropEffects and OLEDropHasData don't seem to be relevant here.

At the end of the OLEDragOver, I placed NODEFAULT.

In the OLEGiveFeedback (also in the drag target), I did this:

eMouseCursor = IIF(nEffect = 0, 12, 0)

Now, the mouse cursor changes in just the way I expected.

So, thanks to all who contributed. It's been educational.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top