How do I make my program open a file by default?

Started by
7 comments, last by ManaStone 20 years, 5 months ago
I just created a program that can view ppm files and I''d like to know how to make my program open it automatically when a ppm file is clicked on. How can I do this?
-----------------------------Download my real time 3D RPG.
Advertisement
Do you want to know how to make the program modify the registry so it can do it? Or do you simply want to manually configure windows to do that?
.
No, I want to know how to call my opener function with the string of the filename when I click on the ppm file.
-----------------------------Download my real time 3D RPG.
quote:
No, I want to know how to call my opener function with the string of the filename when I click on the ppm file.

Yeah, you have to modify a key in the registry that associates extensions with programs. I''m not sure where it''s located, but I''m sure you can find it by just looking through the registry (or search for ppm). To edit the key search msdn for registry. Btw, to open the registry editor go to start->run and type in "regedit".

quote:Original post by ManaStone
No, I want to know how to call my opener function with the string of the filename when I click on the ppm file.


You still aren''t quite clear. That ability is done via a modified key in the registry. Windows does that, not your program. You can either manually configure windows so that it will do that, or you can modify your program so that it will edit registry and configure Windows to do that. To do it manually, hold shift down and right click on a ppm file. Then select Open With->Choose Program and select your program. You then have to modify your program to read the command line arguments and load the picture as needed.
.
Quite easy.

Open up any folder.
Go to Tools -> Folder Options.

Click the File Types tab.
Click on the New button.
Add your extension intop the box and click OK.
Then the file types list box with highlight your new file extension.
Click the change button and make the OpenWith point to the file path of your program.

Presto.
I don''t know if I''m not understanding you or you''re not understsanding me. I''ve already got it so I can open up my program when I click on a ppm file, but it I can''t get the ppm file to load autimatically when it opens.
-----------------------------Download my real time 3D RPG.
oh, so you want to know how to get the command-line arguments for a program?

um, for a console app, main should have two parameters (int argc & char** argv), argc is the number of parameters (including the program name itself) and argv is an array or char arrays containing the values.

for a windows app, there is an lpCommandLine parameter which has the command line in it.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
quote:Original post by ManaStone
I don''t know if I''m not understanding you or you''re not understsanding me. I''ve already got it so I can open up my program when I click on a ppm file, but it I can''t get the ppm file to load autimatically when it opens.

The filename should be passed in automatically and end up in your command line args. Second argument if i remember right..

This topic is closed to new replies.

Advertisement