|
|
1.1.1.3 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: 13: #define USECOMM // yes, we need the COMM API 14: 1.1.1.3 ! root 15: //#undef NO_STRICT // be bold! ! 16: ! 17: //#define HINSTANCE HANDLE 1.1.1.2 root 18: 1.1 root 19: #ifndef WIN32 20: #define WIN31 // this is a Windows 3.1 application 21: #endif 22: 23: #include <windows.h> 24: #include <commdlg.h> 25: #include <string.h> 26: 27: #include "version.h" 28: #include "resource.h" 29: 30: // constant definitions 31: 32: #ifdef WIN32 33: #define GWL_NPTTYINFO 0 34: #define TTYEXTRABYTES sizeof( LONG ) 35: #else 36: #define GWW_NPTTYINFO 0 37: #define TTYEXTRABYTES sizeof( WORD ) 38: #endif 39: 40: #define ABOUTDLG_USEBITMAP 1 41: 42: #define ATOM_TTYINFO 0x100 43: 1.1.1.3 ! root 44: // hard coded maximum number of ports for device under Win32 ! 45: ! 46: #ifdef WIN32 ! 47: #define MAXPORTS 4 ! 48: #endif ! 49: 1.1 root 50: // terminal size 51: 52: #define MAXROWS 25 53: #define MAXCOLS 80 54: 55: #define MAXBLOCK 80 56: 57: #define MAXLEN_TEMPSTR 81 58: 59: #define RXQUEUE 4096 60: #define TXQUEUE 4096 61: 62: // cursor states 63: 64: #define CS_HIDE 0x00 65: #define CS_SHOW 0x01 66: 67: // Flow control flags 68: 69: #define FC_DTRDSR 0x01 70: #define FC_RTSCTS 0x02 71: #define FC_XONXOFF 0x04 72: 73: // ascii definitions 74: 75: #define ASCII_BEL 0x07 76: #define ASCII_BS 0x08 77: #define ASCII_LF 0x0A 78: #define ASCII_CR 0x0D 79: #define ASCII_XON 0x11 80: #define ASCII_XOFF 0x13 81: 82: // we are going to fake the CN_EVENT notifications using another 83: // thread in Win32 84: 85: #ifdef WIN32 1.1.1.3 ! root 86: #define WM_COMMNOTIFY 0x0044 1.1 root 87: #define CN_EVENT 0x04 88: #endif 89: 90: // data structures 91: 92: typedef struct tagTTYINFO 93: { 94: #ifdef WIN32 95: HANDLE idComDev ; 96: #else 97: int idComDev ; 98: #endif 99: BYTE bPort, abScreen[ MAXROWS * MAXCOLS ] ; 100: BOOL fConnected, fXonXoff, fLocalEcho, fNewLine, fAutoWrap, 101: fUseCNReceive, fDisplayErrors; 102: BYTE bByteSize, bFlowCtrl, bParity, bStopBits ; 103: #ifdef WIN32 104: DWORD dwBaudRate ; 105: WORD wCursorState ; 106: #else 107: WORD wBaudRate, wCursorState ; 108: #endif 109: HFONT hTTYFont ; 110: LOGFONT lfTTYFont ; 111: DWORD rgbFGColor ; 112: int xSize, ySize, xScroll, yScroll, xOffset, yOffset, 113: nColumn, nRow, xChar, yChar ; 114: #ifdef WIN32 115: HANDLE hPostEvent, hWatchThread, hWatchEvent ; 116: HWND hTermWnd ; 117: DWORD dwThreadID ; 118: OVERLAPPED osWrite, osRead ; 119: #endif 120: 121: } TTYINFO, NEAR *NPTTYINFO ; 122: 123: // macros ( for easier readability ) 124: 125: #ifdef WIN32 126: #define GETHINST( x ) ((HINSTANCE) GetWindowLong( x, GWL_HINSTANCE )) 127: #define GETNPTTYINFO( x ) ((NPTTYINFO) GetWindowLong( x, GWL_NPTTYINFO )) 128: #define SETNPTTYINFO( x, y ) SetWindowLong( x, GWL_NPTTYINFO, (LONG) y ) 129: #else 130: #define GETHINST( x ) ((HINSTANCE) GetWindowWord( x, GWW_HINSTANCE )) 131: #define GETNPTTYINFO( x ) ((NPTTYINFO) GetWindowWord( x, GWW_NPTTYINFO )) 132: #define SETNPTTYINFO( x, y ) SetWindowWord( x, GWW_NPTTYINFO, (WPARAM) y ) 133: #endif 134: 135: #define COMDEV( x ) (x -> idComDev) 136: #define PORT( x ) (x -> bPort) 137: #define SCREEN( x ) (x -> abScreen) 138: #define CONNECTED( x ) (x -> fConnected) 139: #define XONXOFF( x ) (x -> fXonXoff) 140: #define LOCALECHO( x ) (x -> fLocalEcho) 141: #define NEWLINE( x ) (x -> fNewLine) 142: #define AUTOWRAP( x ) (x -> fAutoWrap) 143: #define BYTESIZE( x ) (x -> bByteSize) 144: #define FLOWCTRL( x ) (x -> bFlowCtrl) 145: #define PARITY( x ) (x -> bParity) 146: #define STOPBITS( x ) (x -> bStopBits) 147: #ifdef WIN32 148: #define BAUDRATE( x ) (x -> dwBaudRate) 149: #else 150: #define BAUDRATE( x ) (x -> wBaudRate) 151: #endif 152: #define CURSORSTATE( x ) (x -> wCursorState) 153: #define HTTYFONT( x ) (x -> hTTYFont) 154: #define LFTTYFONT( x ) (x -> lfTTYFont) 155: #define FGCOLOR( x ) (x -> rgbFGColor) 156: #define XSIZE( x ) (x -> xSize) 157: #define YSIZE( x ) (x -> ySize) 158: #define XSCROLL( x ) (x -> xScroll) 159: #define YSCROLL( x ) (x -> yScroll) 160: #define XOFFSET( x ) (x -> xOffset) 161: #define YOFFSET( x ) (x -> yOffset) 162: #define COLUMN( x ) (x -> nColumn) 163: #define ROW( x ) (x -> nRow) 164: #define XCHAR( x ) (x -> xChar) 165: #define YCHAR( x ) (x -> yChar ) 166: #define USECNRECEIVE( x ) (x -> fUseCNReceive) 167: #define DISPLAYERRORS( x ) (x -> fDisplayErrors) 168: 169: #ifdef WIN32 170: #define POSTEVENT( x ) (x -> hPostEvent) 171: #define TERMWND( x ) (x -> hTermWnd) 172: #define HTHREAD( x ) (x -> hWatchThread) 173: #define THREADID( x ) (x -> dwThreadID) 174: #define WRITE_OS( x ) (x -> osWrite) 175: #define READ_OS( x ) (x -> osRead) 176: #endif 177: 178: #define SET_PROP( x, y, z ) SetProp( x, MAKEINTATOM( y ), z ) 179: #define GET_PROP( x, y ) GetProp( x, MAKEINTATOM( y ) ) 180: #define REMOVE_PROP( x, y ) RemoveProp( x, MAKEINTATOM( y ) ) 181: 182: // global stuff 183: 184: char gszTTYClass[] = "TTYWndClass" ; 185: char gszAppName[] = "TTY" ; 186: HANDLE ghAccel ; 187: 188: DWORD BaudTable[] = 189: { 190: CBR_110, CBR_300, CBR_600, CBR_1200, CBR_2400, 191: CBR_4800, CBR_9600, CBR_14400, CBR_19200, CBR_38400, 192: CBR_56000, CBR_128000, CBR_256000 193: } ; 194: 195: DWORD ParityTable[] = 196: { 197: NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY 198: } ; 199: 200: DWORD StopBitsTable[] = 201: { 202: ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS 203: } ; 204: 205: // CRT mappings to NT API 206: 207: #define _fmemset memset 208: #define _fmemmove memmove 209: 210: // function prototypes (private) 211: 212: BOOL NEAR InitApplication( HANDLE ) ; 213: HWND NEAR InitInstance( HANDLE, int ) ; 214: LRESULT NEAR CreateTTYInfo( HWND ) ; 215: BOOL NEAR DestroyTTYInfo( HWND ) ; 216: BOOL NEAR ResetTTYScreen( HWND, NPTTYINFO ) ; 217: BOOL NEAR KillTTYFocus( HWND ) ; 218: BOOL NEAR PaintTTY( HWND ) ; 219: BOOL NEAR SetTTYFocus( HWND ) ; 220: BOOL NEAR ScrollTTYHorz( HWND, WORD, WORD ) ; 221: BOOL NEAR ScrollTTYVert( HWND, WORD, WORD ) ; 222: BOOL NEAR SizeTTY( HWND, WORD, WORD ) ; 223: BOOL NEAR ProcessTTYCharacter( HWND, BYTE ) ; 224: BOOL NEAR WriteTTYBlock( HWND, LPSTR, int ) ; 225: int NEAR ReadCommBlock( HWND, LPSTR, int ) ; 226: BOOL NEAR WriteCommByte( HWND, BYTE ) ; 227: BOOL NEAR MoveTTYCursor( HWND ) ; 228: BOOL NEAR OpenConnection( HWND ) ; 229: BOOL NEAR SetupConnection( HWND ) ; 230: BOOL NEAR CloseConnection( HWND ) ; 231: BOOL NEAR ProcessCOMMNotification( HWND, WPARAM, LPARAM ) ; 232: VOID NEAR GoModalDialogBoxParam( HINSTANCE, LPCSTR, HWND, DLGPROC, LPARAM ) ; 233: VOID NEAR FillComboBox( HINSTANCE, HWND, int, DWORD NEAR *, WORD, DWORD ) ; 234: BOOL NEAR SelectTTYFont( HWND ) ; 235: BOOL NEAR SettingsDlgInit( HWND ) ; 236: BOOL NEAR SettingsDlgTerm( HWND ) ; 237: 238: // function prototypes (public) 239: 240: LRESULT FAR PASCAL TTYWndProc( HWND, UINT, WPARAM, LPARAM ) ; 241: BOOL FAR PASCAL AboutDlgProc( HWND, UINT, WPARAM, LPARAM ) ; 242: BOOL FAR PASCAL SettingsDlgProc( HWND, UINT, WPARAM, LPARAM ) ; 243: 244: #ifdef WIN32 245: DWORD FAR PASCAL CommWatchProc( LPSTR ) ; 246: #endif 247: 248: //--------------------------------------------------------------------------- 249: // End of File: tty.h 250: //---------------------------------------------------------------------------
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.