Reputation: 1111
Actually, I have no idea about what is the title of my question, so I couldn't search on Google, first I need to know what to say to this problem.
Well, I have developed a application in Visual Studio C++ 2010, in which 3D objects can be processed, so there is a function called Import Model which helps to import model.
What I want is, the user just right click on the object and press Open with [application name] or double click on it, and application should the get the path of that file and call the Import function. Same like we do with any MS word *.doc files, we double click on it and it gets open.
I want the same thing to make my software as a default program to open some specific files extension. When user double click on the model, it should open in my application.
Actually, I read something about argument parser, I don't know much about it. Is it what I need to look for ?
Thanks.
Update 1:
It is working Benjamin Lindley and others, but I am getting the following error before starting the application. The argument only passing through FLTK window. I have no idea from where this window comes? not even about these image options.. see the following picture please...
Upvotes: 1
Views: 1961
Reputation: 44354
You need file association, for example, in a .bat
file:
@ASSOC .3D=3DObject.File
@FTYPE 3DObject.File="C:\MyProjects\Release\myprog.exe" "%%1" %%*
This uses registry hive HKEY_CLASSES_ROOT
, and you might need write access to that, so "Run as Administrator".
Edit: As a programmer you could use the Registry APIs (RegCreateKeyEx
, RegSetValueEx
, etc.) to add the association to HKEY_CLASSES_ROOT
yourself, but probably not worth the effort since it is probably only needed once.
Upvotes: 3
Reputation: 103703
"File association", as mentioned in the comments and answers, is off topic (in my opinion), and probably belongs on Super User. But as a programmer, what do you have to do? Well, when someone double clicks on a file that is associated with your program, the filename comes in as an argument to your main function, and you can process that however you like:
int main(int argc, char** argv)
{
// the name file that was used to open your program is stored in argv[1]
if (argc == 2)
DoSomethingWithFile(argv[1])
}
Upvotes: 2