OUTPUTWND.H
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:5k
- /*
- =================================================================
- class TOutputWnd
- ----------------
- This is the colourful text display window.
- has optimisations when mono-spaced fonts are used.
- =================================================================
- */
- #pragma once
- #ifndef FLAG
- #define FLAG( a,b ) ( ( a & b ) == b )
- #endif // FLAG
- // -----------------------------------------------------------------
- // Control:
- // -----------------------------------------------------------------
- #define CONTROL_BYTE 3 // Control Character
- #define WRAP_BYTE 30 // Word-wrap byte
- // -----------------------------------------------------------------
- // Colour Code Structure.
- // -----------------------------------------------------------------
- typedef struct _tagCOLOURCODE
- {
- UINT nFore; // Foreground Colour Index
- UINT nBack; // Background Colour Index
- } COLOURCODE;
- // -----------------------------------------------------------------
- // Colour Codes:
- // -----------------------------------------------------------------
- #define COLOUR_WHITE 0
- #define COLOUR_BLACK 1
- #define COLOUR_BLUE 2
- #define COLOUR_GREEN 3
- #define COLOUR_LIGHTRED 4
- #define COLOUR_BROWN 5
- #define COLOUR_PURPLE 6
- #define COLOUR_ORANGE 7
- #define COLOUR_YELLOW 8
- #define COLOUR_LIGHTGREEN 9
- #define COLOUR_CYAN 10
- #define COLOUR_LIGHTCYAN 11
- #define COLOUR_LIGHTBLUE 12
- #define COLOUR_PINK 13
- #define COLOUR_GREY 14
- #define COLOUR_LIGHTGREY 15
- // -----------------------------------------------------------------
- // class TOutputWnd
- // -----------------------------------------------------------------
- class TOutputWnd : public CWnd
- {
- protected:
- CFont* m_pFont; // Font we are using
- LOGFONT m_lfFont; // Font as a LOGFONT
- COLORREF m_BackCol; // Background Colour
- CStringArray m_Lines; // Lines
- int m_nHead; // Head of the buffer
- int m_nMaxLines; // Maximum buffer size
- int m_nDefTextCol; // Default Text Colour Index
- int m_nXOffset; // X Offset for drawing
- int m_nMaxWidth; // Maximum Written so far
- int m_nAvgCharWidth; // Average Char Width
- bool m_bWordWrap; // Word wrapping?
- HCURSOR m_hCursor; // Cursor for the window
- int m_nFontHeight; // Height of the font
- COLORREF m_ColTable[ 16 ]; // Colour Table
- // Really internal shit:
- int m_nLinesDone; // Actual number of lines we drew last-time
- // Private function to obtain a LINEINFO structure
- int GetLineInfo( CString&, CDC*, int );
- void RenderSingleLine( CString&, CDC*, int, int );
- int GetColourCodes( CString&, COLOURCODE* ); // Remains the same
- public:
- TOutputWnd();
- virtual ~TOutputWnd();
- // Operations:
- void SetWordWrap( bool bWrap ); // Set Word-wrapping
- bool GetWordWrap() const { return( m_bWordWrap ); };
- void SetDefaultTextColour( UINT nIndex ) { m_nDefTextCol = nIndex; if( GetSafeHwnd() ) Invalidate(); }; // Set default text colour
- UINT GetDefaultTextColour() const { return( m_nDefTextCol ); };
- void SetBuffer( CStringArray& ); // Set the buffer
- bool GetBuffer( CStringArray& ) const; // Return the buffer
- void AddLine( CString& strLine ); // Add a Line
- void SetFont( LOGFONT& lf ); // Set the Font
- bool GetFont( LOGFONT& lf ) const; // Return the Font
- void SetBackColour( COLORREF col ); // Set the background Colour
- COLORREF GetBackColour() const { return( m_BackCol ); };// Retrieve the background Colour
- void SetColourTable( COLORREF* pColTable ) { memcpy( &m_ColTable, pColTable, sizeof( COLORREF ) * 16 ); if( GetSafeHwnd() ) Invalidate(); };
- void SetHead( int nHead ); // Set the Head
- int GetHead() const { return( m_nHead ); }; // Return the Head
- void SetMaxLines( UINT nMaxLines ); // Set max number of lines
- UINT GetMaxLines() const { return( m_nMaxLines ); }; // Return max number of lines
- UINT GetMaxViewableLines(); // Return viewable lines
- int GetLineCount() const { return( m_Lines.GetUpperBound() + 1 ); }; // Get Line Count
- CString GetLine( int l ) const { return( m_Lines.GetAt( l ) ); }; // Retrieve a specific line
- void ClearBuffer(); // Clear the buffer
- void Load( const char* lpFilename ); // Load from a file
- void Save( const char* lpFilename ); // Save to a file
- protected:
- // Update the Vertical/Horizontal scrollbars...
- virtual void UpdateHScroll();
- virtual void UpdateVScroll();
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(TOutputWnd)
- //}}AFX_VIRTUAL
- // Generated message map functions
- protected:
- //{{AFX_MSG(TOutputWnd)
- afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
- afx_msg void OnDestroy();
- afx_msg void OnPaint();
- afx_msg BOOL OnEraseBkgnd(CDC* pDC);
- afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
- afx_msg void OnSize(UINT nType, int cx, int cy);
- afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
- afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
- afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
- afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };