just a question

This is a discussion on just a question within the C++ Programming forums, part of the General Programming Boards category; is there a way to write a C++ program so that it opens a file in a window (instead of ...

  1. #1
    Registered User Phaeren's Avatar
    Join Date
    Dec 2009
    Posts
    3

    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

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    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.

  3. #3
    Registered User Phaeren's Avatar
    Join Date
    Dec 2009
    Posts
    3
    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?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    19
    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

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    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...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Oh you mean ShellExecute?
    Sure, that's been possible since Windows NT 3.1 & Windows 95!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21