File Associations Part 2

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I have a code-editor application. I have associated a filetype with the
application. Double-clicking on a file will open the code-editor and
open the file. Works great.

My application is an MDI application. Each file is opened in a new child
window. However, if the application is already running, it does
according to the initial CommandLineArgs value. If there were no initial
command line args, then double-clicking on a new file does nothing. If
there was an initial CommandLineArg value, it re-opens the initial file
contained therin.

So, if the app is already running, and I double-click a file to open it,
how do I get my app to respond and open the clicked-on file?
 
Found my own answer! Needed to use the ApplicationEvents.vb to handle
the StartupNextInstanceEvent. But trying to elegantly run the document
load code in the main form is not easy. I came up with this
not-so-elegant way of doing it:

In the ApplicationEvents.vb under the StartupNextInstanceEvent handler,
I have this:

modGlobals.docToOpen=e.CommandLine(0).ToString

Then in the MainForm under the Activated Event Handler, I have this:

If modGlobals.docToOpen<>"" Then
ShowNewChildForm(docToOpen)
docToOpen=""
End If

Is this a good way to do it? Or is there a better way?
 
Back
Top