We help IT Professionals succeed at work.

Argument, when Open

win32
win32 asked
on
Hi, I have made a program, that should open .txt files. When I double click on an .txt file, my program should open, and also it should open the .txt file I clicked on. As far as I know, window passes the "file.txt" as an argument to the program file, (my program)

How do I get that arugment, passed to my program when I try to open an file by clicking on it ?

CB.
Comment
Watch Question

Commented:
I'm not entirely sure how Windows tells the app the filename to open. But here's some steps you might take to at least get you the right clues to carry on:

1) You need to look at the command line when your app starts up. You can use something like this:

CString sCommandLine=AfxGetApp()->m_lpCmdLine;

and parse sCommandLine for a document name.

Or, you can use MFC's CCommandLineInfo m_strFileName or other constructs.

2)This is a Windows issue -- you have to tell Windows to trigger your app when a .txt file is clicked. Go to My Computer, then click on View Folder Options. Click on the File Types tab. Click on the Text File icon and click Edit. Click on Open and click edit, now you put your app in here instead of Notepad. At the very least, your app should start up, even if it doesn't get the document yet.

Hope this helps!

Author

Commented:
Thanks a lot for the help man :-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.