home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / io / serial / tty.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  6.3 KB  |  210 lines

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