Adblock breaks this site

Using windows explorers "Open With"!

Discussion in 'Programming General' started by Darthatron, Nov 6, 2007.

  1. Darthatron

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0
    Using windows explorers "Open With"!

    Alright, have you ever wondered how to open a file in your application directly from Windows Explorer? Well, I'll show you how, using the "Command$" command.

    It's just a few lines of code. I'll explain it as best I can.

    In General Declarations put this line of code...
    Code:
    Dim FileLocationName As String
    That just gives us a string to hold the File Location. Pretty basic stuff.

    Next in the Form_Load() section of your code put this...
    Code:
        If Command$ <> "" Then
            FileLocationName = Replace(Command$, """", "")
            'Do Events
        End If
    Alright, so the "Command$" command loads the Location of the file if "Open With" is used in Windows Explorer. I'm not 100% sure how it works but, I know it loads the location. ;) But the downfall is, it loads it with quotation marks. ("").

    So in order to remove those we use the "Replace" command. Which looks for a certain string inside the String you choose. Now, to find "'s we put (""""), we have to put 2 lots of quotation marks.

    Next we merely replace them with "" or nothing.

    Where I put "'Do Events" is where you would put the events you want to use the file with.

    I hope I have explained this enough. Have fun.
     
  2. pwnintheface

    pwnintheface Member
    Banned

    Joined:
    Jul 31, 2007
    Posts:
    70
    Referrals:
    0
    Sythe Gold:
    0
    Using windows explorers "Open With"!

    wait, whats this supposed to do?
     
  3. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    Using windows explorers "Open With"!

    I made a tutorial on this a while ago.


    You should also show more functions of "Command" ($ means string. (For the people that didn't know))

    Such as the Command line options when loading a program, and other such examples...


    If you make a shortcut to your program, and place it on the desktop, such as
    Code:
    "C:\...\Desktop\half-life 2 episode two\hl2.exe" -steam -game ep2
    The command line options in this case are
    -steam
    -game



    So in your startup routine (Sub Main rather then Form_Load) you could have something similar to this:

    Code:
          If InStr(1, Command, "[I]steam[/I]") <> 0 Then Do_Steam = True
          If InStr(1, Command, "[I]game[/I]") <> 0 Then Call RunGame
    The above is 100% made up, as an example.


    So your example is calling something similar to:
    Code:
    "C:\...\Desktop\half-life 2 episode two\hl2.exe" "C:\Program Files\Test.File"


    @pwnintheface

    If you have your own program, with it's own filetype, you can make your program start up by using the "Open with" option with windows explorer.

    This will not make your program load that file however.

    Darthatron here has shown how to make your program load that file if one has been specified.
     
  4. Darthatron

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0
    Using windows explorers "Open With"!

    =S Thanks Jazz, for summing that up so well.
     
< haha massive favour to ask | My second ever VERY useful program [its a source!] >


 
 
Adblock breaks this site