"Open/Open With..." from Win Explorer 
Author Message
 "Open/Open With..." from Win Explorer

Hi,

How would I go about having my program (text editor with a Rich Text
Box) open a file directly from Windows Explorer, either by associating
the extension with my program or by selecting "Open With..."?

I assume I have to put some code for that in the Form_Load event...
but do I need to use some API function or is it done differently?
Where does the file name come from?

Thanks.
--

Carole
_____________________________ ____ ___ __ __  _   _
http://www.*-*-*.com/ ~tio/coroner.htm
http://www.*-*-*.com/



Thu, 08 Jan 2004 22:45:17 GMT  
 "Open/Open With..." from Win Explorer


Hello Carole,

Yep, you have to associate your program with the extension(s).
Manually, you can go to  folder options -> file types.
Select the text files, add a method.  Open With My Notepad
Then point to your program with browse.
Put in MyNotePad.Exe %1

As for your app.
Create a Sub Main in a standard module.
In Project properties set 'startup' to Sub Main instead of Form1.

There are plenty of ways to do the rest.. this is one.

Sub Main()
        frmMain.Show
        if command = "" then ' something was sent in
                call frmMain.LoadFile(command) ' load the file
                ' or frmMain.RTB.LoadFile(command)
        endif
End Sub

Quote:
>Hi,

>How would I go about having my program (text editor with a Rich Text
>Box) open a file directly from Windows Explorer, either by associating
>the extension with my program or by selecting "Open With..."?

>I assume I have to put some code for that in the Form_Load event...
>but do I need to use some API function or is it done differently?
>Where does the file name come from?

>Thanks.
>--

>Carole
>_____________________________ ____ ___ __ __  _   _
>http://personalweb01.veriomail.com/~tio/coroner.htm
>http://www.geocities.com/grip_inc_mp3/index.htm

Regards, Frank.


Fri, 09 Jan 2004 00:45:40 GMT  
 "Open/Open With..." from Win Explorer
Creating a Visual Basic File Association
http://www.mvps.org/vbnet/code/reg/association.htm

And then use Command$ at your app's startup as Frank suggested.

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.


: Hi,
:
: How would I go about having my program (text editor with a Rich Text
: Box) open a file directly from Windows Explorer, either by associating
: the extension with my program or by selecting "Open With..."?
:
: I assume I have to put some code for that in the Form_Load event...
: but do I need to use some API function or is it done differently?
: Where does the file name come from?
:
: Thanks.
: --
:
: Carole
: _____________________________ ____ ___ __ __  _   _
: http://personalweb01.veriomail.com/~tio/coroner.htm
: http://www.geocities.com/grip_inc_mp3/index.htm



Fri, 09 Jan 2004 10:58:14 GMT  
 "Open/Open With..." from Win Explorer
Thanks for the example Randy. I applied this to a small app I made which
plays video files with extensions .mpg and it opens my app just fine but it
does not load the file and begin playing it. Is there an additional
parameter needed for my app to begin playing the file or will I need to add
some sort of additional fuction to my app to allow it to start playing the
file through this association?

Thanks for any help.
Gary


Quote:
> Creating a Visual Basic File Association
> http://www.mvps.org/vbnet/code/reg/association.htm

> And then use Command$ at your app's startup as Frank suggested.

> --

> Randy Birch
> MVP Visual Basic

> http://www.mvps.org/vbnet/

> Please respond only to the newsgroups so all can benefit.



> : Hi,
> :
> : How would I go about having my program (text editor with a Rich Text
> : Box) open a file directly from Windows Explorer, either by associating
> : the extension with my program or by selecting "Open With..."?
> :
> : I assume I have to put some code for that in the Form_Load event...
> : but do I need to use some API function or is it done differently?
> : Where does the file name come from?
> :
> : Thanks.
> : --
> :
> : Carole
> : _____________________________ ____ ___ __ __  _   _
> : http://personalweb01.veriomail.com/~tio/coroner.htm
> : http://www.geocities.com/grip_inc_mp3/index.htm



Fri, 09 Jan 2004 13:47:41 GMT  
 "Open/Open With..." from Win Explorer
You have to actually write the code to do that yourself. All the file
association stuff does is to start up the associated app (your app, in this
case) when the user double clicks a file with the appropriate extension.
Your own app has to have code that examines the Command() string, which will
contain the path of the file that was double clicked, and take whatever
action necessary. In your case, that would involve your own code invoking
whatever mp3 player you wish to use and directing it to play the file that
Command() passed to you.

Mike


Quote:
> Thanks for the example Randy. I applied this to a small app I made which
> plays video files with extensions .mpg and it opens my app just fine but
it
> does not load the file and begin playing it. Is there an additional
> parameter needed for my app to begin playing the file or will I need to
add
> some sort of additional fuction to my app to allow it to start playing the
> file through this association?

> Thanks for any help.
> Gary



> > Creating a Visual Basic File Association
> > http://www.mvps.org/vbnet/code/reg/association.htm

> > And then use Command$ at your app's startup as Frank suggested.

> > --

> > Randy Birch
> > MVP Visual Basic

> > http://www.mvps.org/vbnet/

> > Please respond only to the newsgroups so all can benefit.



> > : Hi,
> > :
> > : How would I go about having my program (text editor with a Rich Text
> > : Box) open a file directly from Windows Explorer, either by associating
> > : the extension with my program or by selecting "Open With..."?
> > :
> > : I assume I have to put some code for that in the Form_Load event...
> > : but do I need to use some API function or is it done differently?
> > : Where does the file name come from?
> > :
> > : Thanks.
> > : --
> > :
> > : Carole
> > : _____________________________ ____ ___ __ __  _   _
> > : http://personalweb01.veriomail.com/~tio/coroner.htm
> > : http://www.geocities.com/grip_inc_mp3/index.htm



Fri, 09 Jan 2004 14:57:06 GMT  
 "Open/Open With..." from Win Explorer
As Michael said, the association only launches your app, passing to it the
name of the associated file that started it, if one was used.  In your code,
at startup, examine the Command$() function value ... if it <> "", it
contains the startup parameters, in this case, the filename to play.  ie ...

  x = Command$()

  If Len(x) > 0 then
   <begin app and play file specified in x>
  else
    <no command passed, just start the app>
  end if

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.


: Thanks for the example Randy. I applied this to a small app I made which
: plays video files with extensions .mpg and it opens my app just fine but
it
: does not load the file and begin playing it. Is there an additional
: parameter needed for my app to begin playing the file or will I need to
add
: some sort of additional fuction to my app to allow it to start playing the
: file through this association?
:
: Thanks for any help.
: Gary
:
:


: > Creating a Visual Basic File Association
: > http://www.mvps.org/vbnet/code/reg/association.htm
: >
: > And then use Command$ at your app's startup as Frank suggested.
: >
: > --
: >
: > Randy Birch
: > MVP Visual Basic
: >
: > http://www.mvps.org/vbnet/
: >
: > Please respond only to the newsgroups so all can benefit.
: >
: >
: >


: > : Hi,
: > :
: > : How would I go about having my program (text editor with a Rich Text
: > : Box) open a file directly from Windows Explorer, either by associating
: > : the extension with my program or by selecting "Open With..."?
: > :
: > : I assume I have to put some code for that in the Form_Load event...
: > : but do I need to use some API function or is it done differently?
: > : Where does the file name come from?
: > :
: > : Thanks.
: > : --
: > :
: > : Carole
: > : _____________________________ ____ ___ __ __  _   _
: > : http://personalweb01.veriomail.com/~tio/coroner.htm
: > : http://www.geocities.com/grip_inc_mp3/index.htm
: >
: >
:
:



Sat, 10 Jan 2004 09:04:28 GMT  
 "Open/Open With..." from Win Explorer
Thank you again Randy. That worked perfectly! But now I only have one last
thing if you could please help. How can I change the icons of the files
which are now associated with my program to an icon which I prefer?

Your help is much appreciated.
Gary


Quote:
> As Michael said, the association only launches your app, passing to it the
> name of the associated file that started it, if one was used.  In your
code,
> at startup, examine the Command$() function value ... if it <> "", it
> contains the startup parameters, in this case, the filename to play.  ie
...

>   x = Command$()

>   If Len(x) > 0 then
>    <begin app and play file specified in x>
>   else
>     <no command passed, just start the app>
>   end if

> --

> Randy Birch
> MVP Visual Basic

> http://www.mvps.org/vbnet/

> Please respond only to the newsgroups so all can benefit.



> : Thanks for the example Randy. I applied this to a small app I made which
> : plays video files with extensions .mpg and it opens my app just fine but
> it
> : does not load the file and begin playing it. Is there an additional
> : parameter needed for my app to begin playing the file or will I need to
> add
> : some sort of additional fuction to my app to allow it to start playing
the
> : file through this association?
> :
> : Thanks for any help.
> : Gary
> :
> :


> : > Creating a Visual Basic File Association
> : > http://www.mvps.org/vbnet/code/reg/association.htm
> : >
> : > And then use Command$ at your app's startup as Frank suggested.
> : >
> : > --
> : >
> : > Randy Birch
> : > MVP Visual Basic
> : >
> : > http://www.mvps.org/vbnet/
> : >
> : > Please respond only to the newsgroups so all can benefit.
> : >
> : >
> : >


> : > : Hi,
> : > :
> : > : How would I go about having my program (text editor with a Rich Text
> : > : Box) open a file directly from Windows Explorer, either by
associating
> : > : the extension with my program or by selecting "Open With..."?
> : > :
> : > : I assume I have to put some code for that in the Form_Load event...
> : > : but do I need to use some API function or is it done differently?
> : > : Where does the file name come from?
> : > :
> : > : Thanks.
> : > : --
> : > :
> : > : Carole
> : > : _____________________________ ____ ___ __ __  _   _
> : > : http://personalweb01.veriomail.com/~tio/coroner.htm
> : > : http://www.geocities.com/grip_inc_mp3/index.htm
> : >
> : >
> :
> :



Sat, 10 Jan 2004 12:04:35 GMT  
 "Open/Open With..." from Win Explorer
Frank,

I tried what you said but wasn't able to make it work. I placed the
following in my standard module:

Sub Main()

  frmNotepad.Show
  If Command = "" Then
    frmNotepad.rtbEditor.LoadFile (Command)
  End If

End Sub

If I use the above, the program does not open any file selected using
"Open With" in Explorer, just as it did before. I also tried to use <>
instead of = for the If statement, but then I get a run-time error 75
("The specified path/file name cannot be accessed or is invalid.")

What am I doing wrong? Did I misunderstand your explanations?

Thanks.



Quote:
>There are plenty of ways to do the rest.. this is one.

>Sub Main()
>    frmMain.Show
>    if command = "" then ' something was sent in
>            call frmMain.LoadFile(command) ' load the file
>            ' or frmMain.RTB.LoadFile(command)
>    endif
>End Sub

--

Carole
_____________________________ ____ ___ __ __  _   _
http://personalweb01.veriomail.com/~tio/coroner.htm
http://www.geocities.com/grip_inc_mp3/index.htm



Sun, 11 Jan 2004 01:47:57 GMT  
 "Open/Open With..." from Win Explorer


Hi Carole,

Did you define the association's aplication path as
myexe.exe %1 ?  The %1 is replaced with the file's path. Just like
good old batch programming.

Ahhh, just thought of this.
You can test the code itself if you go to Project properties and to
the 'Make' tab.  You'll find a text box near the bottom where you can
enter command line arguments.  Put a valid path to an existing text
file in there and Apply it.  Press F5 to see if the file opens ok.
It should work, if it does then the problem is not in the code, but in
your file association settings.
Don't forget to remove those cmdline arguments before compile.

See how you go, and we'll take it from there if it still doesn't
work.. :)

Quote:
>Frank,

>I tried what you said but wasn't able to make it work. I placed the
>following in my standard module:

>Sub Main()

>  frmNotepad.Show
>  If Command = "" Then
>    frmNotepad.rtbEditor.LoadFile (Command)
>  End If

>End Sub

>If I use the above, the program does not open any file selected using
>"Open With" in Explorer, just as it did before. I also tried to use <>
>instead of = for the If statement, but then I get a run-time error 75
>("The specified path/file name cannot be accessed or is invalid.")

>What am I doing wrong? Did I misunderstand your explanations?

>Thanks.



>>There are plenty of ways to do the rest.. this is one.

>>Sub Main()
>>        frmMain.Show
>>        if command = "" then ' something was sent in
>>                call frmMain.LoadFile(command) ' load the file
>>                ' or frmMain.RTB.LoadFile(command)
>>        endif
>>End Sub

>--

>Carole
>_____________________________ ____ ___ __ __  _   _
>http://personalweb01.veriomail.com/~tio/coroner.htm
>http://www.geocities.com/grip_inc_mp3/index.htm

Regards, Frank.


Sun, 11 Jan 2004 02:49:42 GMT  
 "Open/Open With..." from Win Explorer
<> seems right
and "%1" if there are any spaces in the path structure (better safe than
sorry, eh?)
tested with
Private Sub Form_Load()
  MsgBox Command
End Sub
Created an empty file with .ZXY extension then right clicked and chose OPEN
selecting my EXE as the opener.
After verifying that the message box did indeed display, then checked the
File Type options for open. The %1 was encased in quotes.
HTH
Billy Joe




Hi Carole,

Did you define the association's aplication path as
myexe.exe %1 ?  The %1 is replaced with the file's path. Just like
good old batch programming.

Ahhh, just thought of this.
You can test the code itself if you go to Project properties and to
the 'Make' tab.  You'll find a text box near the bottom where you can
enter command line arguments.  Put a valid path to an existing text
file in there and Apply it.  Press F5 to see if the file opens ok.
It should work, if it does then the problem is not in the code, but in
your file association settings.
Don't forget to remove those cmdline arguments before compile.

See how you go, and we'll take it from there if it still doesn't
work.. :)

Quote:
>Frank,

>I tried what you said but wasn't able to make it work. I placed the
>following in my standard module:

>Sub Main()

>  frmNotepad.Show
>  If Command = "" Then
>    frmNotepad.rtbEditor.LoadFile (Command)
>  End If

>End Sub

>If I use the above, the program does not open any file selected using
>"Open With" in Explorer, just as it did before. I also tried to use <>
>instead of = for the If statement, but then I get a run-time error 75
>("The specified path/file name cannot be accessed or is invalid.")

>What am I doing wrong? Did I misunderstand your explanations?

>Thanks.



>>There are plenty of ways to do the rest.. this is one.

>>Sub Main()
>> frmMain.Show
>> if command = "" then ' something was sent in
>> call frmMain.LoadFile(command) ' load the file
>> ' or frmMain.RTB.LoadFile(command)
>> endif
>>End Sub

>--

>Carole
>_____________________________ ____ ___ __ __  _   _
>http://personalweb01.veriomail.com/~tio/coroner.htm
>http://www.geocities.com/grip_inc_mp3/index.htm

Regards, Frank.


Sun, 11 Jan 2004 07:54:51 GMT  
 "Open/Open With..." from Win Explorer
I have to say that I'm a little bit confused now...

I did the check of pasting a file's path in the Project's command
line, and it worked if I used <> in my Command's conditional statement
in Sub Main. But it still doesn't load anything if I select "Open
With..." from Explorer.

I haven't done anything with the Windows file associations... I don't
understand why I have to do that? (or exactly how...)

What I wanted to do is: Shift-right click on a text or RTF file in
Explorer, select "Open With..." then select my program to open the
file, without actually associating all .TXT and .RTF files with it.
When I do that with any other programs, it works fine and I don't have
to associate anything permanently, nor deal with any %1 variable...

Do I have to put that %1 somewhere in my code?



Quote:
>Did you define the association's aplication path as
>myexe.exe %1 ?  The %1 is replaced with the file's path. Just like
>good old batch programming.

>Ahhh, just thought of this.
>You can test the code itself if you go to Project properties and to
>the 'Make' tab.  You'll find a text box near the bottom where you can
>enter command line arguments.  Put a valid path to an existing text
>file in there and Apply it.  Press F5 to see if the file opens ok.
>It should work, if it does then the problem is not in the code, but in
>your file association settings.
>Don't forget to remove those cmdline arguments before compile.

--

Carole
_____________________________ ____ ___ __ __  _   _
http://personalweb01.veriomail.com/~tio/coroner.htm
http://www.geocities.com/grip_inc_mp3/index.htm



Sun, 11 Jan 2004 10:49:48 GMT  
 "Open/Open With..." from Win Explorer
Have I been forgotten? :} I still can get this to work...

Thanks.



Quote:
>I have to say that I'm a little bit confused now...

>I did the check of pasting a file's path in the Project's command
>line, and it worked if I used <> in my Command's conditional statement
>in Sub Main. But it still doesn't load anything if I select "Open
>With..." from Explorer.

>I haven't done anything with the Windows file associations... I don't
>understand why I have to do that? (or exactly how...)

>What I wanted to do is: Shift-right click on a text or RTF file in
>Explorer, select "Open With..." then select my program to open the
>file, without actually associating all .TXT and .RTF files with it.
>When I do that with any other programs, it works fine and I don't have
>to associate anything permanently, nor deal with any %1 variable...

>Do I have to put that %1 somewhere in my code?



>>Did you define the association's aplication path as
>>myexe.exe %1 ?  The %1 is replaced with the file's path. Just like
>>good old batch programming.

>>Ahhh, just thought of this.
>>You can test the code itself if you go to Project properties and to
>>the 'Make' tab.  You'll find a text box near the bottom where you can
>>enter command line arguments.  Put a valid path to an existing text
>>file in there and Apply it.  Press F5 to see if the file opens ok.
>>It should work, if it does then the problem is not in the code, but in
>>your file association settings.
>>Don't forget to remove those cmdline arguments before compile.

--

Carole
_____________________________ ____ ___ __ __  _   _
http://personalweb01.veriomail.com/~tio/coroner.htm
http://www.geocities.com/grip_inc_mp3/index.htm



Mon, 12 Jan 2004 22:23:45 GMT  
 "Open/Open With..." from Win Explorer
Okay, Carol. Double Click My Computer, choose View / Folder Options and
click the File Types tab. Scroll down the list until you see "Text
Document". Click it to select it and then click the Edit button. That will
bring up a little "Edit File Type" window. Click the "New" button on that
window, which will bring up another little window called "New Action". In
the Action box type in something like Open With Carol's Thing (or whatever).
Then click the Browse button and browse to the compiled exe file of your own
program, select it and click the Open button. Close or OK your way out of
all the little windows. Now, each time you right click a text file there
will be a new item in the drop down list entitled "Open With Carol's Thing"
and selecting it will cause your own exe program to start up. The full path
and filename of the file that was right clicked will be passed to your
application and all you need to do is place some code in your main Form's
Load event, such as:

Dim s1 as string
s1=Command()
Caption = s1 ' just to check it all works
' Now do whatever you want with the file

The variable s1 will contain the full path and name of the "right clicked"
file. Do what you want with it!

Carry out a similar procedure with Rich Text Format.

Post again if you have any problems with this.

Mike


Quote:
> Have I been forgotten? :} I still can get this to work...

> Thanks.



> >I have to say that I'm a little bit confused now...

> >I did the check of pasting a file's path in the Project's command
> >line, and it worked if I used <> in my Command's conditional statement
> >in Sub Main. But it still doesn't load anything if I select "Open
> >With..." from Explorer.

> >I haven't done anything with the Windows file associations... I don't
> >understand why I have to do that? (or exactly how...)

> >What I wanted to do is: Shift-right click on a text or RTF file in
> >Explorer, select "Open With..." then select my program to open the
> >file, without actually associating all .TXT and .RTF files with it.
> >When I do that with any other programs, it works fine and I don't have
> >to associate anything permanently, nor deal with any %1 variable...

> >Do I have to put that %1 somewhere in my code?



> >>Did you define the association's aplication path as
> >>myexe.exe %1 ?  The %1 is replaced with the file's path. Just like
> >>good old batch programming.

> >>Ahhh, just thought of this.
> >>You can test the code itself if you go to Project properties and to
> >>the 'Make' tab.  You'll find a text box near the bottom where you can
> >>enter command line arguments.  Put a valid path to an existing text
> >>file in there and Apply it.  Press F5 to see if the file opens ok.
> >>It should work, if it does then the problem is not in the code, but in
> >>your file association settings.
> >>Don't forget to remove those cmdline arguments before compile.

> --

> Carole
> _____________________________ ____ ___ __ __  _   _
> http://personalweb01.veriomail.com/~tio/coroner.htm
> http://www.geocities.com/grip_inc_mp3/index.htm



Mon, 12 Jan 2004 23:56:45 GMT  
 "Open/Open With..." from Win Explorer


Whoops. I thought i was waiting on your next post. Sorry.  
Mike covered the howto now.

Quote:
>Have I been forgotten? :} I still can get this to work...

Regards, Frank.


Mon, 12 Jan 2004 01:52:38 GMT  
 "Open/Open With..." from Win Explorer
Yes! That worked! Thank you :)

BUT...  Ok, it works fine if I select the new "Open With [my program]"
right-click menu item I created. However, if I Shift-right-click a
text file and select "Open With...", then browse for my program, it
does not work -- it says "The specified path/file name cannot be
accessed or is invalid."

Why does it work with the Explorer menu item I created, but not with
"Open With..."? I thought it was all the same... How can I make it
work that way too?

Thanks!

On Thu, 26 Jul 2001 16:56:45 +0100, "Michael Williams"

Quote:

>Dim s1 as string
>s1=Command()
>Caption = s1 ' just to check it all works
>' Now do whatever you want with the file

>The variable s1 will contain the full path and name of the "right clicked"
>file. Do what you want with it!

>Carry out a similar procedure with Rich Text Format.

>Post again if you have any problems with this.

--

Carole
_____________________________ ____ ___ __ __  _   _
http://personalweb01.veriomail.com/~tio/coroner.htm
http://www.geocities.com/grip_inc_mp3/index.htm



Tue, 13 Jan 2004 22:18:23 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Trapping "Expand", "Open", "Explore" in Windows Explorer?

2. open dialog box "save as" or "open"

3. "open module"

4. Using the common dialog "Open file"

5. Using a standard "File open" dialog

6. Preventing "personal.xls" opening

7. word 2000 hangs at "document.open"

8. Open "Other User's Calendar"

9. "Unable to open the Outlook Window"

10. Open mail item in "reply-mode"

11. Disabling message: "Warning: Opening ..."

12. "Frozen" Document on Open

 

 
Powered by phpBB® Forum Software