// // WIN32TERM.H // // Source code from: // // Serial Communications: A C++ Developer's Guide, 2nd Edition // by Mark Nelson, M&T Books, 1999 // // Please see the book for information on usage. // // This header file contains the declarations for // class Win32Term. This class creates a window that // can be used as part of a Win32 terminal emulator. // #include #include using namespace std; // // The vector > variables in this class // end up with incredibly long expanded names. This // pragma disables the associated warnings // #pragma warning( disable : 4786 ) class Win32Term { public : // // This nested class is used to hold the background // and foreground colors for a single character // on the screen. Packaging the two together into // a class makes a few things a little easier in // some of the members. // struct TextColor { TextColor( COLORREF f = 0, COLORREF b = 0 ) : m_Foreground( f ), m_Background( b ) {} bool operator!=( const TextColor &that ) { if ( m_Foreground != that.m_Foreground ) return true; return m_Background != that.m_Background; } COLORREF m_Foreground; COLORREF m_Background; }; // // This little class is used in a bunch of different // places in the class where we hold both an x and a // y value for something, like size, scrolling range, // offset, etc. It's another convenience class, mostly // here for clarity. // struct Pair { Pair( int i = 0, int j = 0 ) { x = i; y = j; } int x; int y; }; // // This is the structure that we have to use to // pass data to the WinProc on a WM_CREATE // struct CreateData { SHORT size; Win32Term *pTerm; }; Win32Term( HWND hParent, const char *window_name, int rows, int cols ); virtual ~Win32Term() { if ( m_hWnd ) SetWindowLong( m_hWnd, 0, 0 ); if ( m_hFont ) DeleteObject( m_hFont ); } void SetForegroundColor( COLORREF color ) { m_CurrentColor.m_Foreground = color; } void SetBackgroundColor( COLORREF color ) { m_CurrentColor.m_Background = color; } COLORREF GetForegroundColor() { return m_CurrentColor.m_Foreground; } COLORREF GetBackgroundColor() { return m_CurrentColor.m_Background; } COLORREF GetBorderColor() { return m_BorderColor; } LOGFONT GetLogFont() { return m_lfFont; } void SetBorderColor( COLORREF color ); virtual void Clear(); void Output( char c ); void Output( const char *pBuf, int length = -1 ); void SetFont( LOGFONT LogFont ); int SetCursorPosition( int row, int col ); void GetCursorPosition( int &row, int &col ); protected : BOOL Paint(); void UpdateCursor(); void SetFocus(); void KillFocus(); void VerticalScroll( WPARAM wParam ); void HorizontalScroll( WPARAM wParam ); void Size( int x, int y ); virtual LRESULT Dispatch( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); public : HWND m_hWnd; protected: HWND m_hParent; TextColor m_CurrentColor; vector< vector > m_ScreenText; vector< vector > m_ScreenColor; bool m_bWrap; bool m_bShowingCursor; HFONT m_hFont; LOGFONT m_lfFont; Pair m_VisibleSize; const Pair m_VirtualSize; Pair m_ScrollRange; Pair m_Offset; Pair m_Position; Pair m_CharSize; int m_iCharDescent; COLORREF m_BorderColor; protected: static bool m_bClassRegistered; protected: static LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); }; //EOF Win32Term.h