Skip to main content
gamedev.net
🔒 Locked

Finding default program to open file type

Started by Trip99 5 replies 800+ views
Original Post
Trip99
Trip99
Hi, in my app I want to be able to find out the program that is set to load a certain file type. e.g. if someone selects to edit a .bmp file in my program I would like to start up whatever graphic editor is associated with .bmp files. Registry?
------------------------See my games programming site at: www.toymaker.info
flangazor
flangazor
On windows, you can just use the filename. For example, if I have an avi on my desktop of Ashlee Simpson making an utter fool of herself on SNL, I can just type "lipsync.avi" in the command prompt when in the desktop dir. It then performs the default action -which, for me, is to open it in my default avi viewing app and play the file.

system("lipsync.avi");

If I rename my file to "lipsync.flarg", and I have no default action for flarg files, then windows will ask me what I want to do with it.

I just double checked this works on Windows2000. I don't use XP so it is possible your mileage may vary.
Aprosenf
Aprosenf
Indeed, the registry. To check a filename's association, open up HKEY_CLASSES_ROOT\.bmp\(Default) to get some sort of name of the file type (I'm not completely sure what the interpretation of those names are). In this case, it is "Paint.Picture". So, to find the location of the executable associated with that file type, go to HKEY_CLASSES_ROOT\Paint.Picture\shell\edit\command\(Default) . Note that you should replace the "%1" with the name of the file you want Paint to open.
Trip99
Trip99
Hi, thanks both for the replies.

Flangazor - that did work although it was a bit odd as it opened a DOS prompt sat there for a while and then Photoshop loaded (this was for a .tga file). It may be acceptable although using the registry may ultimately be better - I will investigate....
------------------------See my games programming site at: www.toymaker.info
ShawnO
ShawnO
I'm not sure, but ShellExecute() may be more what you are looking for. It shouldn't open a DOS prompt like system() might.

Shawn
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
S1CA
S1CA
Quote:
Original post by Trip99
Hi, thanks both for the replies.

Flangazor - that did work although it was a bit odd as it opened a DOS prompt sat there for a while and then Photoshop loaded (this was for a .tga file). It may be acceptable although using the registry may ultimately be better - I will investigate....



use ShellExecuteEx().

system() is the DOS/C-Runtime style of spawning new processes - ShellExecuteEx() gives you a lot more control and is what you should be using for Windows based programs.


Another way to determine which program is used to open a particular file type, you can use FindExecutable() on the file in question.

Another advantage of using ShellExecuteEx() is you can specify the "verb" to use, such as "open", "edit", "print" etc.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Trip99
Trip99
Brilliant - that works thanks. I did think there must be someway of doing this.
------------------------See my games programming site at: www.toymaker.info

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.