Skip to main content
www.olaf-groeger.de

Main navigation

  • Home
  • NMR
  • Programming
    • Streams
    • Subclassing of edit controls
  • Software
    • Calimah Scheduler
    • ServicesCtl

Breadcrumb

  1. Home
  2. Programming
  3. Streams
  4. Console Window For GUI-based Windows Applications

Console window for GUI-based Windows applications

By olaf , 29 June 2025
This is an implementation for MFC with C++ and is quite antiquated.

I use this window for diagnostic issues in release versions. Visual C ++, unfortunately, doesn't initialize cin, court and cerr properly in non-text based application, ie one can in a gui based application not stream in a console window.

The solution to this problem is, of course, to design a separate output stream, that is linked to a console window. The implementation is so simple that it almost invites you to your own experiments.

To implement a stream sounds initially very complicated. But it is much easier than you think, since the design of the stream base classes has been designed for extension. This was made possible by splitting the implementation of a stream in two classes. An outer class (basic_istream, basic_ostream) provides the interface to the inner class (basic_streambuf), which make up the actual input/output accomplished in the device. At the same time the outer class takes care of the formatting of the output. All output streams are derived from basic_ostream. It follows that for the development of a new stream only the inner class must be changed. The outer class remains the same (of course it must use the new inner class). Enough of the preface:

  • Derivation of the inner class from std::streambuf
  • Implementation of the output method that writes into the console window
  • Overriding the methods of the base class streambuf that are called when output should be written
  • Derive a new outer class which uses the inner class
  • Usage and Download

Book traversal links for 3

  • Streams
  • Up
  • Derivation of the inner class from std::streambuf

Language switcher

  • English
  • German
Powered by Drupal