Search code examples
c++windowsfile-association

Show text from opened file


I am not sure how to explain this, so I will give a scenario.

I want to write a program, which will be set as the default program for a file extension. When the program opens, it will output everything in the program. i.e file.txt contains the word hello, and when opened, my program opens and displays the word hello.

The idea is like Notepad. When a text file is opened, the contents are displayed. However, mine will be in a DOS window.

How can I achieve this?

Sorry if there is another question like this somewhere on here, TBH I am not too sure what this is called and thus can't search.

EDIT: My apologies. I am running Windows 7


Solution

  • If you open a file "with" your program (for instance using file type associations or by dragging the file onto the .exe), then the filename of the data file is passed as the command-line parameter to your application.

    See:

    What are the arguments to main() for?