Show text from opened file - c++

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

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?

I want to write a program, which will be set as the default program for a file extension.
See:
How File Associations Work
File Types and File Associations
You will associate your app with file extension and your app will do whatever it has to do.

Related

Make C++ program receive file as parameter

What I want to do is a program like notepad. I want that all the ".txt" files, when I double click on them, open with my program instead of notepad. But I don't have any clue how to do this. So, in resume, I want:
Make my program predeterminate for .txt extension files
Make a program that open "automatically? " that file. Like when I open a test.txt file, and the notepad show the content of that file.
If you have any doubt, or I didn't explained very well, please ask!
This can be done by changing your OS setting. For example: Right Click -> Open With -> Choose default program, then select a direction to your execute.
I don't think you can implement it into your program.
I think this will get you started:
http://www.codeproject.com/Articles/12474/How-To-Make-A-Very-Simple-Text-Editor-Using-MFC-in

glade filechooserdialog Where does the opened file go?

I learning how to use Python(2.7) GTK(2.0) and Glade(3.8) and at the moment i am trying to use the filechooserdialog to open a file and use it in my program, however i can not seem to find any information on where the opened file "goes". I have found many tutorials explaining how to use or make a file choosing dialog window but none explaning how to open the file in your program, for example i have a file with numbers that i want in a chart.
Does any of you kind gentlemen/women have a clue ?

Qt: How to create a file using a path on any Windows machine?

I am not exactly sure if the title captures what exactly I want to ask so here it is:
I just made my first desktop application that uses a XML file to store data. The XML File is stored somewhere in C:/Users/myname/Documents/adjsklf/asdjfklasd/.... on my own machine.
How do I go about creating this file in a specific location C:/Users/theirname/Documents/myAppName/data.xml? Or more specifically, how do I get the "theirname" file name? For machines that have multiple users, how do I get the filename that belongs to the user who actually is using the app?
Also, when I first started this application, I wasn't really thinking of deploying this application. So I made an explicit constructor of a class, dataManipulation, that manipulates all the data in my XML file. What happens is that when my program runs, it executes MainWindow, which at the same time constructs my dataManipulation object with the path I want. However, since now I have a few friends who want to try out this app, I need to be able to detect whether the file exists first using the path I mentioned earlier. What's the best way to achieve that?
Thank you so much!
Use QStandardPaths::writableLocation.
There are many ways to perform file opening checks. If you want to do it in Qt-like way, take a look at QFile and do similarily. In constructor it only sets the path, but the file is opened only in QFile::open, and its return value indicates whether it was successfully opened. You can create init() method in your data manipulation class, check its return value and show a message to user if needed.

C++ - Making a program open itself

I have a program that opens a WAV file and then plots the waveform. If the WAV file has 2 channels, two graphs are shown, one for each channel. It's working fine but I want to add things in the File Menu that I created. So far, I have three buttons: New, Open File, and Close. So far, the Open File and the Close buttons are working fine.
I want to make the program to be able to let the user view several waveforms of several WAV Files at the same time. One option would be to create more graphs, the process would be quite tedious. Another option would be to open another window and this is what I want to do.
However, this is my problem. I made a quick search on how to open an existing program in C++, and so far, the solutions that I encounter involve opening an exe file and the project folder does not contain an exe file.
I also tried to take a quick look on the functions and I can't find the function that seems to open the window and I can't seem to find it.
Your best bet is to use fork. Alternatively you could use threads.
Use GetModuleFileName API to get the path+ name of your executable. Then Use ShellExecute to run this APP.

How to capture the result of DOS Commands in C++

I am creating a windows application that must capture results of several DOS Commands without the command prompt opening and save them into a string. I am using the borland libraries.
system("dir") therefore is not good. The result of each command needs to be written to a string variable so I can write it to a log and a separate file.
I have an XML file where they are defined.
The thing i'm struggling on the most is actually capturing the output into a string variable. I have heard of _popen but having problems trying to use it.
I think what you really want is freopen() that allows you to redirect the usual streams to a file (either temporary or the separate file you mentioned), and when the process closes, read the file into your log.
I assume the 'result' is the output from the command, and not its return value.