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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Drag and Drop (OLE)

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,826
JP
Is it possible, using VFP to drag files from a source outside the application (i.e. from a directory in an explorer Window) onto a control in VFP, which then saves that file to a new directory (we've coverd that already, so I have that code).

I'll keep it simple for the start, pick one file, drag it to a "target" drop it, and then a "new record" is created in the "DOCUMENTS" table, updates the table with file name and path (though the path is a destination we've saved the dragged (copied) file to).

I have set up an Image class file to use as a "Target". The default is an image that is literally a red target. When you drag the file onto it and drop it, the target turns green then, to let you know you can drop it there (visual cue).

But I can't seem to get OLE to even recognize I'm dragging an item over it to be dropped there.

If this is possible, then the next step would be to enable "multiple file drop" so you pick, say 8 files at once, and drop them on the target. I assume that's just an array of files that we then process making a new record for each one in the table until we have processed all the files.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi Scot

There is a lot of helpful stuff on drag and drop in the samples folder on your vfp installation.

I looked in c:\program files\Microsoft visual FoxPro 9\samples\solution\solution.app

run that, open up the programming window and there is a section on 'fun with drag and drop'

there is an example of exactly what you want to do

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Thanks Griff, I'll go have a look there!
I was just reading through all the FAQs here, but there's zip on that topic.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
The solution sample "Fun with OLE Drag & Drop" has an editbox as drop target for files copied from Windows Explorer. It's labeled "Drop files here from the Windows Explorer".
The sample lists full path file names of the files you dropped, so you can pick up from there with the code you already have.

Bye, Olaf.
 
Scott, the quick answer to your question is: Yes. It's perfectly possible to do what you want. But it is somewhat complicated, and you really need to understand the basics of OLE drag-and-drop before you start. As it's late on Saturday afternoon and I'm abuot to close down for the day, I'll leave you to read the Help file or look at the samples, as Griff suggested. If that doesn't help you crack it, no doubt others will be around to talk you through it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Griff,
Well, it seems the examples there are what I've already done in the past... it's all dragging and dropping within an existing form.
What I'm wanting to do is drag a file from an external location (i.e. outside the VFP controlled application), and drop it on the form for processing. (Like the ability to drag an image file, and drop it on Outlook messaging, and it then treats it as an "Attachment".

In my case I will process the file to be associated with a record, and store the file in a directory that I want it to be in. That part I can handle. But what I need to know is: How do you get VFP to recognize you're dropping an object with click-n-drag from outside the application?

Or am I trying to do something that can't be done as a limitation to the VFP legacy?

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
No Scotty, you can drag and drop in the sample from an explorer window - into the big text box and bingo it has the full
path.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Oh wait, yeah! I just found it there.
Thanks, I'm still banging on it.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Ok, progress... but very weird.

My idea was to just have an "image" that changed with the state of things, i.e. When you drag over it with a file, it changes the image appearance, (which it does, with MouseEnter). But now I think that VFP is trying to be "clever" and not allow me to pick it as a "drop" type for <random files>.

I'll try it with an image and see if it lets me do that. Because I copied the ListBox object in from the sample, and it allowed me to drop single and multiple files onto it. So maybe I'll have to rethink my control...

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Don't copy out control, you never catch all code depending on it and even if, you bind things into your project you don't want to.

I have inherited projects, where some fomrs contain controls defined in another project and simply copied over. The effect is, these controls point into classlibs of the other project, so the two are now only working when side by side. That kind of dependencies is what you never should allow.

Look at how it's done and which settings are set. The essential code is of course in OleDragDrop. It's essential to test whether the oDataObject contains data in Format 15 (CF_DROP),then you can get these in an array. Code is in the lstFile listbox.

Bye, Olaf.
 
Olaf,
I understand, and I wasn't planning to. I just put it in the form to see if I had some other problem/reason I couldn't drag N drop. It proved that there is some other issue.
What, I only suspect that the image baseclass is somehow rejecting files being dropped on it. It seems odd it has a DragNDrop methods and properties, but unless I'm missing something else, I can't get it to accept dragging single or multiple files on to it. It doesn't even seem to recognize the "Drag Over" event, as the mouse pointer does not change, and even if I put a "MESSAGEBOX" to fire it it, nothing happens.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Take a look at the OleDragOver event of the listbox and of course all the OLE properties.

Bye, Olaf.
 
Yes, I've done that.
Replicated the code from it to the image class equivalent, and got nowhere.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
I could get it going setting OleDropMode to 1 - Enabled. Tada.
In short: All Ole properties, not only the ole methods. So use the All tab of the properties windows and scroll to the properties beginning with Ole...

Well, the code itself does call This.Additem(), that of course does not apply to an image control, but you get the files, the array of file names and can process them the way you want.

Bye, Olaf.
 
Hi Olaf,
I seriously don't understand what I'm doing wrong. I have that set as well, and for the list box, it works fine. Same properties for the image class, and it doesn't work.
I'm wondering, do all the container properties above it need to be set to Enabled as well? In my case I have:
Form
PageFrame
Page
Image

Since the image is a child of Page, etc, do they all need to be set as well?

Because now my idea for interface is, I put the image on top of the listbox.
You drag images to the target, the target turns green when over the image (set with This.Picture = "GreenTarget.PNG" when you "OleDragOver".
Then when release, the target's Visible Property is set to .F., and the list box is set to .T., when the "OleDrop" happens, it's actually over the listbox, and then you get a list of files that have been droped, which will get processed one by one with an array, and remove them from the list until empty.
This way if it's very long list there is a bit of a "progress" visibility.
Short or one will probably just blink and annoy the user. :)

But I still can't get the image class to accept a Drag over or Drop event.
The mouse pointer does not change from the "Not allowed" drop icon to the one I get when over the listbox... :/

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hey Olaf, I found it...
Somehow the "Enabled" property of the image was getting set to .F. (not sure where still). I forced an Enabled = .T. in init, and suddenly, it worked! Because Image class has no Refresh() event (and that really annoys me too) the image itself never changes unless you tell it to change through some other programmatic change but image display has 0 to do with Enabled... so it was very very odd.
I think now I can get it all to work as I want to.
Cheers


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
I used the native image class, perhaps you have something in your image base class. Anyway, the OleDropMode seems the essential one to enable the image being a drop target. I did only need that and of course Ole

Enabled =.F.? It's not a default, but is a very global switchoff of any interaction with a control. If you really mean that, it has to be set somehow in your image control version.

Bye, Olaf.
 
That's the weird thing... I didn't find anything in my baseclass for Image that set it to disabled. I think it's something else in the form base, but forcing it to Enabled = .T. solved all the issues. So I suspect that's what I was fighting all along.
Anyway, it's working now.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top