Announcement

Collapse
No announcement yet.

Open file with

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Open file with

    I am new to this window programing and was wondering
    how your program can tell if it has be opened with
    another file. Like when you select a *.txt file it opens
    it with notepad. How does notepad know this. Thanks

  • #2
    It is a technique called "File Association", where a given file extension can be associated with a particular executable.

    Depending on your version of Windows, you'll find the file association list under the Tools or Options menu in Windows Explorer. It's usually located in a tabbed-dialog, abnd it gives you a way to edit the list or create new entries.

    Another way to quickly define a new association is to hold down the shift key while right-clicking on a file. This should present you with a "Open With..." option, and you can choose or change an association on the fly.

    You can also programmatically find the name of the executable that is associated with a given file. We discussed this only a couple of weeks ago - if you search the BBS for "FindExecutable" you should find a few examples.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      That it not exactly what I wanted to say. I want to know
      how the program can tell if windows wants the program to
      open the file that you selected. What is sent to the program
      as to were the file is and what its name is. I hope this
      is clearer. Thank for your help. Curtis

      Comment


      • #4
        The target path+filename is passed as a command-line parameter to the application. In recent editions of Windows, the command-line is enclosed in double quotes.



        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Originally posted by Lance Edmonds:
          In recent editions of Windows, the command-line is enclosed in double quotes.
          This is just to clarify this and avoid confusion, Lance. I know you already know this.

          The command line is not itself enclosed in double quotes, but any paths and filenames are so as to handle directory or file names containing spaces.

          This is actually controlled in the registry in the HKCR tree. If you look up the document type, then look under \shell\open\command, you will see the command used to launch the associated program and how the file name is passed. On my system (W2K) notepad looks like this:

          In HKEY_CLASSES_ROOT\txtfile\shell\open\command:
          %SystemRoot%\\system32\\NOTEPAD.EXE %1

          whereas wordpad documents look like this:

          In HKEY_CLASSES_ROOT\Wordpad.Document.1\shell\open\command:
          "%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"

          The %1 is replaced with the complete file and path of the document. The quotes to be included, if any, are specified here.

          Comment

          Working...
          X