Listing 6 Definition of Function Put Text

// ostrwnd.cpp

#include   "stdhdr.h"
#include   "ostrwnd.h"

ostreamWnd::ostreamWnd (const char * window_name)
                    : CStrWnd (window_name)
{
max_lines_in_buffer = 50;
CMenu * control_menu = GetSystemMenu (FALSE);
VERIFY (control_menu->EnableMenuItem
                 (SC_CLOSE, MF_GRAYED ) != -1);
}

BEGIN_MESSAGE_MAP (ostreamWnd, CStrWnd)
   ON_WM_CLOSE ()
END_MESSAGE_MAP ()

void ostreamWnd::PutText (const char * buf,
                     int no_of_chars)
{
int ub = text_buffer.GetUpperBound ();
if (ub < 0)
   // text_buffer is empty so initialise it
   // by adding a null entry
   {
   text_buffer.Add ("");
   ub = text_buffer.GetUpperBound ();
   }
char * ptr = (char *) buf;
for (int i = 0; i < no_of_chars; i++)
   {
   if (*buf != '\n')
      // Append the character to the end of the
      // last CString in the text_buffer
      text_buffer [ub] += *buf;
   else
      {
      text_buffer.Add (""); // Add a new line
      ub = text_buffer.GetUpperBound ();
      }
   buf++;
   }
while (text_buffer.GetUpperBound ()
       >= max_lines_in_buffer)
   text_buffer.RemoveAt (0);
UpdateScreen ();
}
// End of File