Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Associating a file extension to my app

Status
Not open for further replies.

LastCyborg

Programmer
Feb 7, 2003
256
MX
How can I associate certain file extensions to be opened with my application?
like .doc with MS Word, .txt with notepad, etc

--- LastCyborg ---
 
You need to set that in the registry. Do the following:

1) Open the HKEY_CLASSES_ROOT key to the registry.
2) See if KeyExists for "my_file_commands", or whatever you want to call it. Make it something related to your program. If not, create the key.
3) Add a "shell" key to this new key.
4) Add the commands you want the file to have as keys to the shell key, i.e. "edit", "open", "print", "printto", etc.
5) For each command key, add a value "command" and set it to the program to run for that file.
6) Add a new value to the root key with the filename extension, i.e. .php. and set this value to the key name you made previously.

That's it! So basically, in the registry, you'll see this:

+HKEY_CLASSES_ROOT
...
.php = php_auto_file
...
+php_auto_file
+shell
+open
+command = myprogram.exe %1
+edit
+command = myprogram.exe /e %1


Another way to view it is (and this is in microsoft's sdk):

HKEY_CLASSES_ROOT\.wri = wrifile
HKEY_CLASSES_ROOT\wrifile = Write Document
HKEY_CLASSES_ROOT\wrifile\DefaultIcon =
C:\Progra~1\Access~1\WORDPAD.EXE,2
HKEY_CLASSES_ROOT\wrifile\shell\open\command = WORDPAD.EXE %1
HKEY_CLASSES_ROOT\wrifile\shell\print\command =
C:\Progra~1\Access~1\WORDPAD.EXE /p "%1"
HKEY_CLASSES_ROOT\wrifile\shell\printto\command =
C:\Progra~1\Access~1\WORDPAD.EXE /pt "%1" "%2" "%3" "%4"

The %1 parameter is the filename, %2 is the printer name, %3 is the driver name, and %4 is the port name. In Windows 95, you can ignore the %3 and %4 parameters (the printer name is unique in Windows 95).

Hope all that helps.
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top