just a question
is there a way to write a C++ program so that it opens a file in a window (instead of using read and write to edit) ? i know this might be a dumb question but i just thought i would check first before spending a lot of time searching how to do it online
Just a text or image file? well if you think about it your program is going to have to call some kind of output window, or stream, appropriate to the output so that means opening a file in the normal way and then streaming the output to your device, formatting how it is displayed is handled by your code.
i suppose it is possible to write code to call the exe of an exisiting application on your machine, its not something i have ever looked into though.
yeah, i'm just looking to actually open a .txt file same as if i had double clicked it but using my C++ program to do it for me...any ideas?
I take it you want to double-click a file if explorer, say, and it opens in your program?
If the above holds true, then this is how it's usually done.
You would create a file extension or a shell command since .txt files really do have a file extension handler already, then point that command to your application. That usually means that Windows will launch your application with the command line being the path to the file you tried to double-click.
Command lines can be acquired using the GetCommandLine API, I believe.
The web should hold resources for manipulating file extension handlers.
Phaeren: Are you looking for a way to "magically" open, load and display a text file? I.e. you want to do "opentextfile("filename.txt"); and have that open the file in a text window?
For that to happen, you will have to find a library offering such functions. There is a lot going on when loading and displaying a text file, but it really isn't very hard to write the code yourself. I've written a text editor once, one of the few projects I actually did finish :P
I know its been like 1000 years since I coded for Windows but wasn't there an Open() call that just did the right thing based on file-type? ie Open("somefile.html") would open the browser or Open("somefile.txt") would open the text file in Notepad or whatever the default text editor was? Just seems to be making this harder than it needs to be but who knows; maybe Windows has evolved to be like this...
Oh you mean ShellExecute?
Sure, that's been possible since Windows NT 3.1 & Windows 95!