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
  5. Overriding The Methods of The Base Class Streambuf That Are Called When Output Should Be Written

Overriding the methods of the base class streambuf that are called when output should be written

By olaf , 30 June 2025

The methods sync and overflow are called from the base class when the output buffer will be written to the console device, e.g. upon calling flush. The overriden methods of sync and overflow call WriteToConsole and WriteCharToConsole which do the real job.
int OG_constreambuf::sync()
{
  WriteToConsole();
  return(0);
}

int OG_constreambuf::overflow(int c)
{
  WriteToConsole();

  if (c != EOF)
    if (pbase() == epptr())
      WriteCharToConsole(c);
    else
      sputc(c);

  return 0;
}

The destructor and the method DeleteConsole are trivial.

OG_constreambuf::~OG_constreambuf()
{
  sync();

  if (pReserve)
    delete pReserve;
  DeleteConsole();
}

void OG_constreambuf::DeleteConsole()
{
  CloseHandle(hConsoleOut);

  FreeConsole();
}

Book traversal links for 3

  • Implementation of the output method that writes into the console window
  • Up
  • Derive a new outer class which uses the inner class

Language switcher

  • English
  • German
Powered by Drupal