WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
The TOutputWnd class was written originally as an IRC-style Output window. By this, I mean a window where the first line that is entered appears at the bottom, and the contents are scrolled upwards, ala mIRC. This is actually alot more difficult than writing text starting at the top of the window. But, forgetting IRC for the moment, this style also serves great as a general purpose output window. Whats more, it supports foreground and background colours together with optional wordwrapping. Text Selection has not, at the moment, been implemented.
The TOutputWnd class requires no special construction, so you can use the usual Create() or CreateEx() functions to create the window.
Text is easy to display in the window, just call the AddLine( CString& ) method, which takes a reference to a CString. This line is then immediately added. Just like in mIRC, if the user has scrolled back up the window, the view is not updated, so the window will not 'jump' just because a line has been added (just try using the ICQ chat system to know how annoying it is for a window to jump when you're trying to read the rest of the text). The other two ways of getting text in to the Output window, is to use the Load( const char* ) function. This Load() routine is far from optimized (it was intended originally just so I could get some kind of text in to the window to test the various functions. The Output Window is *not* designed to load large text files, although handling large amounts of text isn't the problem). The third and final method of setting text is to call the SetBuffer( CStringArray& ), which sets the entire buffer from a string array. This, combined with the GetBuffer( CStringArray& ) function enables the programmer to save and restore the output window's buffer when necessary.
You may also clear the buffer at any time using the ClearBuffer() function.
The output window uses embedded codes to denote foreground and background colours. the CONTROL_BYTE is #define'd in the header file (defaulting to '3'). The next 2 bytes following the control byte is the desired foreground colour index in the colour table ( 2 digits ), and optionally a comma and 2 further bytes denoting the background colour. The default colour table has colour constants defined to make explicit colour code setting easier. The following example adds a line with bright white foreground and blue background to the outputwindow:
CString strLine = CONTROL_BYTE; strLine += _T("00,04HEY!"); pOutputWnd->AddLine( strLine );
The Colour table
The output window uses a colour table of 16 colours to store the various colours that can be used as foreground and background. At any time you can pass an array of COLORREF's using the SetColourTable( COLORREF* ) function. The array should have 16 elements.
You can set the font used by the output window to any font you wish, using the SetFont( LOGFONT& ) function. By default, the output window will use the default mono-spaced font. It is worth noting that the rendering code checks to see if a monospaced font is being used and if so, uses a different method of calculating text width to speed the process up.
Word wrapping can be switched on and off as necessary. When word-wrapping is off, you will see quite a speed increase in rendering, and also the addition of a horizontal scrollbar.
Public MethodsThe following list describes the public methods that you can use to work with the output window:
void SetWordWrap( bool bWrap ); bool GetWordWrap() const; void SetDefaultTextColour( UINT nIndex ); UINT GetDefaultTextColour() const; void SetBuffer( CStringArray& ); bool GetBuffer( CStringArray& ) const; void AddLine( CString& strLine ); void SetFont( LOGFONT& lf ); bool GetFont( LOGFONT& lf ) const; void SetBackColour( COLORREF col ); COLORREF GetBackColour() const; void SetColourTable( COLORREF* pColTable ); void SetHead( int nHead ); int GetHead() const; void SetMaxLines( UINT nMaxLines ); UINT GetMaxLines() const; UINT GetMaxViewableLines(); int GetLineCount() const; CString GetLine( int l ) const ; void ClearBuffer(); void Load( const char* lpFilename );