--- Robert Poland <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I want to be able to Drag & Drop a file on my app and have it
> opened.
> 
> I have set AcceptFileTypes to accept text files.
> 
> I have a method that when selecting Open from the Menu Bar a
> file  
> will open.
> 
> I would assume that the Drag & Drop needs a link to the method
> to  
> accomplish this.
> 
> Any hints?

Here's how I do it.

Let's say I have a Window called MyDocWindow, and I've set it up
so that it displays my documents the way I want.  In the code for
MyDocWIndow, I've set up a menu handler called "FileOpen" that
opens up a file dialog, gets a FolderItem, and (after checking
for a nil folderitem) loads my document data into my window.

Now I want to support drag and drop on the app icon. I look at my
FileOpen menu handler, and most of my code is there, only I can't
call a menuhandler directly. So I create a method (in
MyDocWindow) that takes a folder item as an argument, and I call
this method "OpenMyDoc(f As FolderItem)". It's a simple matter to
cut some of the code out of my menu handler and paste it into the
body of OpenMyDoc(). Then I just have my menu handler call
OpenMyDoc(f) at the point where the code used to appear.

Now my menu handler takes care of bringing up a File Open dialog
and getting a non-nil FolderItem. It then passes the FolderItem
to OpenMyDoc(f), which opens the file and loads the data into the
window.  One last point: I make sure that the OpenMyDoc() method
is set to "public" visibility, not "private" or "protected."

Now, in my App.OpenDocument handler, I get a FolderItem passed in
as an argument. Here's the code I need:

Sub OpenDocument(item As FolderItem)

   Dim w As new MyDocWindow
   w.OpenMyDoc(item)

End Sub

That's really all there is to it. It's important to create w as a
new MyDocWindow because if the user drags more than one file onto
your app, the OpenDocument event will fire multiple times with a
different item each time.



Mark Nutter

Quick and easy regex creation and debugging!
http://www.bucktailsoftware.com/products/regexplorer/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to