Archived

This topic is now archived and is closed to further replies.

C++ and Windows

This topic is 5376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, im wondering if anyone knows how to make c++ programs so they appear in a windows, rather then in dos, without using visual c++. I know that with dev-cpp you can make a windows exe program and when you run it it appears in a window, but cout etc don''t work with it. If anyone can help it would be greatly appreciated.

Share on other sites
I am confused by your question, you want your program to run in a window without dos box but you want cout to work? Without the dos box where should the program output to? You''ll have to find some other way than cout to output from a window.
As for the compiling without dos-box, i only know how to do it for gcc (mingw), there you add -mwindows to the linker command line.

Marijn

Share on other sites
quote:
Original post by Razza2003
Hi, im wondering if anyone knows how to make c++ programs so they appear in a windows, rather then in dos, without using visual c++.

Yes.

quote:
I know that with dev-cpp you can make a windows exe program and when you run it it appears in a window, but cout etc don''t work with it.

Yes.

My sarcastic replies aside, what exactly are you asking? You want a Win32 application (with a window, not in the console) yet you want to use cout for output? Not possible. Standard input and output streams, which cin and cout respectively encapsulate, are only defined for console windows. You can redirect them to files, but not to windows. If all you want is to give user notifications, look into MessageBox. Otherwise, you need a dialog box.

Share on other sites
you cannot use cout with windows. you have to use a different function (specifically TextOut...there are others). Any good win32 tutorial/book will show you how to draw text.

extended waranty, how can I lose!

Share on other sites
you can attach a "DOS window" to you GUI application and redirect the default in/output streams to it!

Share on other sites
That''s not true! cout & cerr are definetly defined (I''m not certain about cin) for win32 programs, but their default streambuf just throws the data away.

It is surprisingly easy to redirect cin & cerr to a file.
Conversations: Redirections

  std::ofstream logFile("out.txt");    std::streambuf *outbuf = std::cout.rdbuf(logFile.rdbuf());    std::streambuf *errbuf = std::cerr.rdbuf(logFile.rdbuf());        //use cin & cerr normally        // restore the buffers    std::cout.rdbuf(outbuf);    std::cerr.rdbuf(errbuf);

Now, getting the contents into a window on the screen is a little trickier. Just this week I''ve been looking at various methods for doing this, but have yet to determine the best method.

One way is to pretend the window is a file, and implement a fstreambuf, take over the overflow routine and write the characters into a multiline editbox instead.

Because of the crude hack that I am, I inherited from basic_stringstream, and am polling the contents every 100ms, sucking the stringstream and slapping it into the window.

Not possible... sheesh

Share on other sites
quote:
Original post by Oluseyi
You can redirect [cin and cout] to files, but not to windows.
I see no reason why it couldn''t be done, but it''d be rather complicated.

Share on other sites
Ok, question change, what are the equivilents, if any, or more important, where do i go to learn how to program win32 apps (without vc++).

Share on other sites
quote:
Original post by Razza2003
Ok, question change, what are the equivilents, if any, or more important, where do i go to learn how to program win32 apps (without vc++).

Well in order to answer this we need to know what compiler you intend on using... And even then the answer will be to use google, Im positive there are TONS of win32 programing tutorials out there

Share on other sites
i am not the experienced kind of programmer. but i belive the "Borland C++ Builder" will do the work...

----------------------------------------------------------
I dont have syntax error....
Only logical ones...

Share on other sites
Of course you can use cout in a window in C++ !
There is a simpler hack than the one Magmai Kai Holmlor proposed.
I implemented it while writing a Forth scripting editor.

I create a subclassed Edit control to retrieve the text each time the user presses the return key (see msdn for control subclassing - Codeproject also has an article on win32 encapsulation). I use it that way because the text content of my control only changes when the user enters some commands. But nothing prevents you to get the text from an Edit control with a timer (see msdn and the message WM_TIME).
The text is easily restrieved from an edit control by the message WM_GETTEXT giving as a parameter a char pointer.
You can then process this text within a string stream (look at GameDev articles for strstream ) using Cin and Cout.
When the text is modified, you can set back the text to the Edit control using the message WM_SETTEXT.
You just need to take care of the Caret position (look at Codeproject articles for the prompt edit control object ).

Hope that helps.
Ghostly yours,
Red.

Share on other sites
You can learn programming win32 apps at winprog.org.
This is not C++ , but it is enough to get started.
When you understand the basics, encapsulating will be a snap.
If you want to have a look at an implementation of a win32 encapsulation and are not afraid of a little technicality, I would advise you to look at www.relisoft.com.

Hope that helps.
Ghostly yours,
Red.

Share on other sites
it would be possible, if you made it a console app that also uses a window. think about it: all the stuff and demos you downloaded from sites like this, a lot of them use both. though you''ll probably be limited in what you do with your window.

Share on other sites
Red Ghost, that''s pretty much how I do it, though I hadn''t thought about using it to support cin too (neat idea!) btw, strstring is deprecated, you should use stringstream.

Win32 debug console

• Forum Statistics

• Total Topics
628706
• Total Posts
2984309

• 23
• 10
• 9
• 13
• 13