C++ and Windows

Started by
12 comments, last by Razza2003 21 years, 1 month ago
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.
Advertisement
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
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.
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!
extended waranty, how can I lose!
you can attach a "DOS window" to you GUI application and redirect the default in/output streams to it!
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
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
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++).
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
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...
----------------------------------------------------------I dont have syntax error....Only logical ones...

This topic is closed to new replies.

Advertisement