|
|
1.1 ! root 1: //--------------------------------------------------------------------------- ! 2: // ! 3: // Module: tty.c ! 4: // ! 5: // Purpose: ! 6: // The sample application demonstrates the usage of the COMM ! 7: // API. It implements the new COMM API of Windows 3.1. ! 8: // ! 9: // NOTE: no escape sequences are translated, only ! 10: // the necessary control codes (LF, CR, BS, etc.) ! 11: // ! 12: // Description of functions: ! 13: // Descriptions are contained in the function headers. ! 14: // ! 15: // Development Team: ! 16: // Bryan A. Woodruff ! 17: // ! 18: // History: Date Author Comment ! 19: // ! 20: // 5/ 8/91 BryanW Wrote it. ! 21: // ! 22: // 10/18/91 BryanW Sanitized code & comments. ! 23: // ! 24: // 10/22/91 BryanW Minor bug fixes. ! 25: // ! 26: // 12/31/91 BryanW Ported to Win32 (NT). ! 27: // ! 28: // 2/10/92 BryanW Fixed a problem with ReadCommBlock() ! 29: // and error detection. ReadComm() is ! 30: // now performed... if the result is < 0 ! 31: // the error status is read using ! 32: // GetCommError() and displayed. The ! 33: // length is adjusted (*= -1). ! 34: // ! 35: // 2/13/92 BryanW Updated to provide the option to ! 36: // implement/handle CN_RECEIVE ! 37: // notifications. ! 38: // ! 39: // 2/13/92 BryanW Implemented forced DTR control. DTR ! 40: // is asserted on connect and dropped ! 41: // on disconnect. ! 42: // ! 43: // 2/21/92 BryanW Removed overhead of local memory ! 44: // functions - now uses LPTR for ! 45: // allocation from heap. ! 46: // ! 47: // 2/26/92 BryanW Fixed off by one problem in paint ! 48: // calculations. ! 49: // ! 50: // 6/15/92 BryanW Ported the "updated" version of TTY ! 51: // for Win 3.1 including bug fixes. ! 52: // ! 53: //--------------------------------------------------------------------------- ! 54: // ! 55: // Written by Microsoft Product Support Services, Windows Developer Support. ! 56: // Copyright (c) 1991 Microsoft Corporation. All Rights Reserved. ! 57: // ! 58: //--------------------------------------------------------------------------- ! 59: ! 60: #include "tty.h" ! 61: ! 62: //--------------------------------------------------------------------------- ! 63: // int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance, ! 64: // LPSTR lpszCmdLine, int nCmdShow ) ! 65: // ! 66: // Description: ! 67: // This is the main window loop! ! 68: // ! 69: // Parameters: ! 70: // As documented for all WinMain() functions. ! 71: // ! 72: // History: Date Author Comment ! 73: // 5/ 8/91 BryanW Wrote it. ! 74: // ! 75: //--------------------------------------------------------------------------- ! 76: ! 77: int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, ! 78: LPSTR lpszCmdLine, int nCmdShow ) ! 79: { ! 80: HWND hTTYWnd ; ! 81: MSG msg ; ! 82: ! 83: if (!hPrevInstance) ! 84: if (!InitApplication( hInstance )) ! 85: return ( FALSE ) ; ! 86: ! 87: if (NULL == (hTTYWnd = InitInstance( hInstance, nCmdShow ))) ! 88: return ( FALSE ) ; ! 89: ! 90: while (GetMessage( &msg, NULL, 0, 0 )) ! 91: { ! 92: if (!TranslateAccelerator( hTTYWnd, ghAccel, &msg )) ! 93: { ! 94: TranslateMessage( &msg ) ; ! 95: DispatchMessage( &msg ) ; ! 96: } ! 97: } ! 98: return ( (int) msg.wParam ) ; ! 99: ! 100: } // end of WinMain() ! 101: ! 102: //--------------------------------------------------------------------------- ! 103: // BOOL NEAR InitApplication( HANDLE hInstance ) ! 104: // ! 105: // Description: ! 106: // First time initialization stuff. This registers information ! 107: // such as window classes. ! 108: // ! 109: // Parameters: ! 110: // HANDLE hInstance ! 111: // Handle to this instance of the application. ! 112: // ! 113: // History: Date Author Comment ! 114: // 5/ 8/91 BryanW Wrote it. ! 115: // 10/22/91 BryanW Fixed background color problem. ! 116: // ! 117: //--------------------------------------------------------------------------- ! 118: ! 119: BOOL NEAR InitApplication( HANDLE hInstance ) ! 120: { ! 121: WNDCLASS wndclass ; ! 122: ! 123: // register tty window class ! 124: ! 125: wndclass.style = NULL ; ! 126: wndclass.lpfnWndProc = TTYWndProc ; ! 127: wndclass.cbClsExtra = 0 ; ! 128: wndclass.cbWndExtra = TTYEXTRABYTES ; ! 129: wndclass.hInstance = hInstance ; ! 130: wndclass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( TTYICON ) ); ! 131: wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ; ! 132: wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ; ! 133: wndclass.lpszMenuName = MAKEINTRESOURCE( TTYMENU ) ; ! 134: wndclass.lpszClassName = gszTTYClass ; ! 135: ! 136: return( RegisterClass( &wndclass ) ) ; ! 137: ! 138: } // end of InitApplication() ! 139: ! 140: //--------------------------------------------------------------------------- ! 141: // HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow ) ! 142: // ! 143: // Description: ! 144: // Initializes instance specific information. ! 145: // ! 146: // Parameters: ! 147: // HANDLE hInstance ! 148: // Handle to instance ! 149: // ! 150: // int nCmdShow ! 151: // How do we show the window? ! 152: // ! 153: // History: Date Author Comment ! 154: // 5/ 8/91 BryanW Wrote it. ! 155: // ! 156: //--------------------------------------------------------------------------- ! 157: ! 158: HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow ) ! 159: { ! 160: HWND hTTYWnd ; ! 161: ! 162: // load accelerators ! 163: ghAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE( TTYACCEL ) ) ; ! 164: ! 165: // create the TTY window ! 166: hTTYWnd = CreateWindow( gszTTYClass, gszAppName, ! 167: WS_OVERLAPPEDWINDOW, ! 168: CW_USEDEFAULT, CW_USEDEFAULT, ! 169: CW_USEDEFAULT, CW_USEDEFAULT, ! 170: NULL, NULL, hInstance, NULL ) ; ! 171: ! 172: if (NULL == hTTYWnd) ! 173: return ( NULL ) ; ! 174: ! 175: ShowWindow( hTTYWnd, nCmdShow ) ; ! 176: UpdateWindow( hTTYWnd ) ; ! 177: ! 178: return ( hTTYWnd ) ; ! 179: ! 180: } // end of InitInstance() ! 181: ! 182: //--------------------------------------------------------------------------- ! 183: // LRESULT FAR PASCAL TTYWndProc( HWND hWnd, UINT uMsg, ! 184: // WPARAM wParam, LPARAM lParam ) ! 185: // ! 186: // Description: ! 187: // This is the TTY Window Proc. This handles ALL messages ! 188: // to the tty window. ! 189: // ! 190: // Parameters: ! 191: // As documented for Window procedures. ! 192: // ! 193: // Win-32 Porting Issues: ! 194: // - WM_HSCROLL and WM_VSCROLL packing is different under Win-32. ! 195: // - Needed LOWORD() of wParam for WM_CHAR messages. ! 196: // ! 197: // History: Date Author Comment ! 198: // 5/ 9/91 BryanW Wrote it. ! 199: // 6/15/92 BryanW Kill focus before disconnecting. ! 200: // 6/15/92 BryanW Ported to Win-32. ! 201: // ! 202: //--------------------------------------------------------------------------- ! 203: ! 204: LRESULT FAR PASCAL TTYWndProc( HWND hWnd, UINT uMsg, ! 205: WPARAM wParam, LPARAM lParam ) ! 206: { ! 207: switch (uMsg) ! 208: { ! 209: case WM_CREATE: ! 210: return ( CreateTTYInfo( hWnd ) ) ; ! 211: ! 212: case WM_COMMAND: ! 213: { ! 214: switch ( LOWORD( wParam ) ) ! 215: { ! 216: case IDM_CONNECT: ! 217: if (!OpenConnection( hWnd )) ! 218: MessageBox( hWnd, "Connection failed.", gszAppName, ! 219: MB_ICONEXCLAMATION ) ; ! 220: break ; ! 221: ! 222: case IDM_DISCONNECT: ! 223: KillTTYFocus( hWnd ) ; ! 224: CloseConnection( hWnd ) ; ! 225: break ; ! 226: ! 227: case IDM_SETTINGS: ! 228: { ! 229: NPTTYINFO npTTYInfo ; ! 230: ! 231: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 232: return ( FALSE ) ; ! 233: GoModalDialogBoxParam( GETHINST( hWnd ), ! 234: MAKEINTRESOURCE( SETTINGSDLGBOX ), hWnd, ! 235: SettingsDlgProc, ! 236: (LPARAM) (LPSTR) npTTYInfo ) ; ! 237: ! 238: // if fConnected, set new COM parameters ! 239: ! 240: if (CONNECTED( npTTYInfo )) ! 241: { ! 242: if (!SetupConnection( hWnd )) ! 243: MessageBox( hWnd, "Settings failed!", gszAppName, ! 244: MB_ICONEXCLAMATION ) ; ! 245: } ! 246: } ! 247: break ; ! 248: ! 249: case IDM_ABOUT: ! 250: GoModalDialogBoxParam ( GETHINST( hWnd ), ! 251: MAKEINTRESOURCE( ABOUTDLGBOX ), ! 252: hWnd, ! 253: AboutDlgProc, NULL ) ; ! 254: break; ! 255: ! 256: case IDM_EXIT: ! 257: PostMessage( hWnd, WM_CLOSE, NULL, 0L ) ; ! 258: break ; ! 259: } ! 260: } ! 261: break ; ! 262: ! 263: case WM_COMMNOTIFY: ! 264: ProcessCOMMNotification( hWnd, wParam, lParam ) ; ! 265: break ; ! 266: ! 267: case WM_PAINT: ! 268: PaintTTY( hWnd ) ; ! 269: break ; ! 270: ! 271: case WM_SIZE: ! 272: SizeTTY( hWnd, HIWORD( lParam ), LOWORD( lParam ) ) ; ! 273: break ; ! 274: ! 275: case WM_HSCROLL: ! 276: #ifdef WIN32 ! 277: ScrollTTYHorz( hWnd, LOWORD( wParam ), HIWORD( wParam ) ) ; ! 278: #else ! 279: ScrollTTYHorz( hWnd, (WORD) wParam, LOWORD( lParam ) ) ; ! 280: #endif ! 281: break ; ! 282: ! 283: case WM_VSCROLL: ! 284: #ifdef WIN32 ! 285: ScrollTTYVert( hWnd, LOWORD( wParam ), HIWORD( wParam ) ) ; ! 286: #else ! 287: ScrollTTYVert( hWnd, (WORD) wParam, LOWORD( lParam ) ) ; ! 288: #endif ! 289: break ; ! 290: ! 291: case WM_CHAR: ! 292: #ifdef WIN32 ! 293: ProcessTTYCharacter( hWnd, LOBYTE( LOWORD( wParam ) ) ) ; ! 294: #else ! 295: ProcessTTYCharacter( hWnd, LOBYTE( wParam ) ) ; ! 296: #endif ! 297: break ; ! 298: ! 299: case WM_SETFOCUS: ! 300: SetTTYFocus( hWnd ) ; ! 301: break ; ! 302: ! 303: case WM_KILLFOCUS: ! 304: KillTTYFocus( hWnd ) ; ! 305: break ; ! 306: ! 307: case WM_DESTROY: ! 308: DestroyTTYInfo( hWnd ) ; ! 309: PostQuitMessage( 0 ) ; ! 310: break ; ! 311: ! 312: case WM_CLOSE: ! 313: if (IDOK != MessageBox( hWnd, "OK to close window?", "TTY Sample", ! 314: MB_ICONQUESTION | MB_OKCANCEL )) ! 315: break ; ! 316: ! 317: // fall through ! 318: ! 319: default: ! 320: return( DefWindowProc( hWnd, uMsg, wParam, lParam ) ) ; ! 321: } ! 322: return 0L ; ! 323: ! 324: } // end of TTYWndProc() ! 325: ! 326: //--------------------------------------------------------------------------- ! 327: // LRESULT NEAR CreateTTYInfo( HWND hWnd ) ! 328: // ! 329: // Description: ! 330: // Creates the tty information structure and sets ! 331: // menu option availability. Returns -1 if unsuccessful. ! 332: // ! 333: // Parameters: ! 334: // HWND hWnd ! 335: // Handle to main window. ! 336: // ! 337: // Win-32 Porting Issues: ! 338: // - Needed to initialize TERMWND( npTTYInfo ) for secondary thread. ! 339: // - Needed to create/initialize overlapped structures used in reads & ! 340: // writes to COMM device. ! 341: // ! 342: // History: Date Author Comment ! 343: // 10/18/91 BryanW Pulled from tty window proc. ! 344: // 1/13/92 BryanW Fixed bug with invalid handle ! 345: // caused by WM_SIZE sent by ! 346: // ResetTTYScreen(). ! 347: // ! 348: //--------------------------------------------------------------------------- ! 349: ! 350: LRESULT NEAR CreateTTYInfo( HWND hWnd ) ! 351: { ! 352: HMENU hMenu ; ! 353: NPTTYINFO npTTYInfo ; ! 354: ! 355: if (NULL == (npTTYInfo = ! 356: (NPTTYINFO) LocalAlloc( LPTR, sizeof( TTYINFO ) ))) ! 357: return ( (LRESULT) -1 ) ; ! 358: ! 359: // initialize TTY info structure ! 360: ! 361: COMDEV( npTTYInfo ) = 0 ; ! 362: CONNECTED( npTTYInfo ) = FALSE ; ! 363: CURSORSTATE( npTTYInfo ) = CS_HIDE ; ! 364: LOCALECHO( npTTYInfo ) = FALSE ; ! 365: AUTOWRAP( npTTYInfo ) = TRUE ; ! 366: PORT( npTTYInfo ) = 1 ; ! 367: BAUDRATE( npTTYInfo ) = CBR_9600 ; ! 368: BYTESIZE( npTTYInfo ) = 8 ; ! 369: FLOWCTRL( npTTYInfo ) = FC_RTSCTS ; ! 370: PARITY( npTTYInfo ) = NOPARITY ; ! 371: STOPBITS( npTTYInfo ) = ONESTOPBIT ; ! 372: XONXOFF( npTTYInfo ) = FALSE ; ! 373: XSIZE( npTTYInfo ) = 0 ; ! 374: YSIZE( npTTYInfo ) = 0 ; ! 375: XSCROLL( npTTYInfo ) = 0 ; ! 376: YSCROLL( npTTYInfo ) = 0 ; ! 377: XOFFSET( npTTYInfo ) = 0 ; ! 378: YOFFSET( npTTYInfo ) = 0 ; ! 379: COLUMN( npTTYInfo ) = 0 ; ! 380: ROW( npTTYInfo ) = 0 ; ! 381: HTTYFONT( npTTYInfo ) = NULL ; ! 382: FGCOLOR( npTTYInfo ) = RGB( 0, 0, 0 ) ; ! 383: USECNRECEIVE( npTTYInfo ) = TRUE ; ! 384: DISPLAYERRORS( npTTYInfo ) = TRUE ; ! 385: #ifdef WIN32 ! 386: TERMWND( npTTYInfo ) = hWnd ; ! 387: ! 388: // create I/O event used for overlapped reads / writes ! 389: ! 390: READ_OS( npTTYInfo ).hEvent = CreateEvent( NULL, // no security ! 391: TRUE, // explicit reset req ! 392: FALSE, // initial event reset ! 393: NULL ) ; // no name ! 394: if (READ_OS( npTTYInfo ).hEvent == NULL) ! 395: { ! 396: LocalFree( npTTYInfo ) ; ! 397: return ( -1 ) ; ! 398: } ! 399: WRITE_OS( npTTYInfo ).hEvent = CreateEvent( NULL, // no security ! 400: TRUE, // explicit reset req ! 401: FALSE, // initial event reset ! 402: NULL ) ; // no name ! 403: if (NULL == WRITE_OS( npTTYInfo ).hEvent) ! 404: { ! 405: CloseHandle( READ_OS( npTTYInfo ).hEvent ) ; ! 406: LocalFree( npTTYInfo ) ; ! 407: return ( -1 ) ; ! 408: } ! 409: ! 410: // create "posted notification" event ! 411: ! 412: POSTEVENT( npTTYInfo ) = CreateEvent( NULL, // no security ! 413: TRUE, // manual reset ! 414: TRUE, // initial event is set ! 415: NULL ) ; // no name ! 416: ! 417: if (POSTEVENT( npTTYInfo ) == NULL) ! 418: { ! 419: CloseHandle( READ_OS( npTTYInfo ).hEvent ) ; ! 420: CloseHandle( WRITE_OS( npTTYInfo ).hEvent ) ; ! 421: LocalFree( npTTYInfo ) ; ! 422: return ( -1 ) ; ! 423: } ! 424: #endif ! 425: ! 426: // clear screen space ! 427: ! 428: _fmemset( SCREEN( npTTYInfo ), ' ', MAXROWS * MAXCOLS ) ; ! 429: ! 430: // setup default font information ! 431: ! 432: LFTTYFONT( npTTYInfo ).lfHeight = 12 ; ! 433: LFTTYFONT( npTTYInfo ).lfWidth = 0 ; ! 434: LFTTYFONT( npTTYInfo ).lfEscapement = 0 ; ! 435: LFTTYFONT( npTTYInfo ).lfOrientation = 0 ; ! 436: LFTTYFONT( npTTYInfo ).lfWeight = 0 ; ! 437: LFTTYFONT( npTTYInfo ).lfItalic = 0 ; ! 438: LFTTYFONT( npTTYInfo ).lfUnderline = 0 ; ! 439: LFTTYFONT( npTTYInfo ).lfStrikeOut = 0 ; ! 440: LFTTYFONT( npTTYInfo ).lfCharSet = OEM_CHARSET ; ! 441: LFTTYFONT( npTTYInfo ).lfOutPrecision = OUT_DEFAULT_PRECIS ; ! 442: LFTTYFONT( npTTYInfo ).lfClipPrecision = CLIP_DEFAULT_PRECIS ; ! 443: LFTTYFONT( npTTYInfo ).lfQuality = DEFAULT_QUALITY ; ! 444: LFTTYFONT( npTTYInfo ).lfPitchAndFamily = FIXED_PITCH | FF_MODERN ; ! 445: LFTTYFONT( npTTYInfo ).lfFaceName[0] = NULL ; ! 446: ! 447: // set TTYInfo handle before any further message processing. ! 448: ! 449: SETNPTTYINFO( hWnd, npTTYInfo ) ; ! 450: ! 451: // reset the character information, etc. ! 452: ! 453: ResetTTYScreen( hWnd, npTTYInfo ) ; ! 454: ! 455: hMenu = GetMenu( hWnd ) ; ! 456: EnableMenuItem( hMenu, IDM_DISCONNECT, ! 457: MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ; ! 458: EnableMenuItem( hMenu, IDM_CONNECT, MF_ENABLED | MF_BYCOMMAND ) ; ! 459: ! 460: return ( (LRESULT) TRUE ) ; ! 461: ! 462: } // end of CreateTTYInfo() ! 463: ! 464: //--------------------------------------------------------------------------- ! 465: // BOOL NEAR DestroyTTYInfo( HWND hWnd ) ! 466: // ! 467: // Description: ! 468: // Destroys block associated with TTY window handle. ! 469: // ! 470: // Parameters: ! 471: // HWND hWnd ! 472: // handle to TTY window ! 473: // ! 474: // Win-32 Porting Issues: ! 475: // - Needed to clean up event objects created during initialization. ! 476: // ! 477: // History: Date Author Comment ! 478: // 5/ 8/91 BryanW Wrote it. ! 479: // 6/15/92 BryanW Ported to Win-32. ! 480: // ! 481: //--------------------------------------------------------------------------- ! 482: ! 483: BOOL NEAR DestroyTTYInfo( HWND hWnd ) ! 484: { ! 485: NPTTYINFO npTTYInfo ; ! 486: ! 487: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 488: return ( FALSE ) ; ! 489: ! 490: // force connection closed (if not already closed) ! 491: ! 492: if (CONNECTED( npTTYInfo )) ! 493: CloseConnection( hWnd ) ; ! 494: ! 495: #ifdef WIN32 ! 496: // clean up event objects ! 497: ! 498: CloseHandle( READ_OS( npTTYInfo ).hEvent ) ; ! 499: CloseHandle( WRITE_OS( npTTYInfo ).hEvent ) ; ! 500: CloseHandle( POSTEVENT( npTTYInfo ) ) ; ! 501: #endif ! 502: ! 503: DeleteObject( HTTYFONT( npTTYInfo ) ) ; ! 504: ! 505: LocalFree( npTTYInfo ) ; ! 506: return ( TRUE ) ; ! 507: ! 508: } // end of DestroyTTYInfo() ! 509: ! 510: //--------------------------------------------------------------------------- ! 511: // BOOL NEAR ResetTTYScreen( HWND hWnd, NPTTYINFO npTTYInfo ) ! 512: // ! 513: // Description: ! 514: // Resets the TTY character information and causes the ! 515: // screen to resize to update the scroll information. ! 516: // ! 517: // Parameters: ! 518: // NPTTYINFO npTTYInfo ! 519: // pointer to TTY info structure ! 520: // ! 521: // History: Date Author Comment ! 522: // 10/20/91 BryanW Wrote it. ! 523: // ! 524: //--------------------------------------------------------------------------- ! 525: ! 526: BOOL NEAR ResetTTYScreen( HWND hWnd, NPTTYINFO npTTYInfo ) ! 527: { ! 528: HDC hDC ; ! 529: TEXTMETRIC tm ; ! 530: RECT rcWindow ; ! 531: ! 532: if (NULL == npTTYInfo) ! 533: return ( FALSE ) ; ! 534: ! 535: if (NULL != HTTYFONT( npTTYInfo )) ! 536: DeleteObject( HTTYFONT( npTTYInfo ) ) ; ! 537: ! 538: HTTYFONT( npTTYInfo ) = CreateFontIndirect( &LFTTYFONT( npTTYInfo ) ) ; ! 539: ! 540: hDC = GetDC( hWnd ) ; ! 541: SelectObject( hDC, HTTYFONT( npTTYInfo ) ) ; ! 542: GetTextMetrics( hDC, &tm ) ; ! 543: ReleaseDC( hWnd, hDC ) ; ! 544: ! 545: XCHAR( npTTYInfo ) = tm.tmAveCharWidth ; ! 546: YCHAR( npTTYInfo ) = tm.tmHeight + tm.tmExternalLeading ; ! 547: ! 548: // a slimy hack to force the scroll position, region to ! 549: // be recalculated based on the new character sizes ! 550: ! 551: GetWindowRect( hWnd, &rcWindow ) ; ! 552: SendMessage( hWnd, WM_SIZE, SIZENORMAL, ! 553: (LPARAM) MAKELONG( rcWindow.right - rcWindow.left, ! 554: rcWindow.bottom - rcWindow.top ) ) ; ! 555: ! 556: return ( TRUE ) ; ! 557: ! 558: } // end of ResetTTYScreen() ! 559: ! 560: //--------------------------------------------------------------------------- ! 561: // BOOL NEAR PaintTTY( HWND hWnd ) ! 562: // ! 563: // Description: ! 564: // Paints the rectangle determined by the paint struct of ! 565: // the DC. ! 566: // ! 567: // Parameters: ! 568: // HWND hWnd ! 569: // handle to TTY window (as always) ! 570: // ! 571: // History: Date Author Comment ! 572: // 5/ 9/91 BryanW Wrote it. ! 573: // 10/22/91 BryanW Problem with background color ! 574: // and "off by one" fixed. ! 575: // ! 576: // 2/25/92 BryanW Off-by-one not quite fixed... ! 577: // also resolved min/max problem ! 578: // for windows extended beyond ! 579: // the "TTY display". ! 580: // ! 581: //--------------------------------------------------------------------------- ! 582: ! 583: BOOL NEAR PaintTTY( HWND hWnd ) ! 584: { ! 585: int nRow, nCol, nEndRow, nEndCol, nCount, nHorzPos, nVertPos ; ! 586: HDC hDC ; ! 587: HFONT hOldFont ; ! 588: NPTTYINFO npTTYInfo ; ! 589: PAINTSTRUCT ps ; ! 590: RECT rect ; ! 591: ! 592: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 593: return ( FALSE ) ; ! 594: ! 595: hDC = BeginPaint( hWnd, &ps ) ; ! 596: hOldFont = SelectObject( hDC, HTTYFONT( npTTYInfo ) ) ; ! 597: SetTextColor( hDC, FGCOLOR( npTTYInfo ) ) ; ! 598: SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) ) ; ! 599: rect = ps.rcPaint ; ! 600: nRow = ! 601: min( MAXROWS - 1, ! 602: max( 0, (rect.top + YOFFSET( npTTYInfo )) / YCHAR( npTTYInfo ) ) ) ; ! 603: nEndRow = ! 604: min( MAXROWS - 1, ! 605: ((rect.bottom + YOFFSET( npTTYInfo ) - 1) / YCHAR( npTTYInfo ) ) ) ; ! 606: nCol = ! 607: min( MAXCOLS - 1, ! 608: max( 0, (rect.left + XOFFSET( npTTYInfo )) / XCHAR( npTTYInfo ) ) ) ; ! 609: nEndCol = ! 610: min( MAXCOLS - 1, ! 611: ((rect.right + XOFFSET( npTTYInfo ) - 1) / XCHAR( npTTYInfo ) ) ) ; ! 612: nCount = nEndCol - nCol + 1 ; ! 613: for (; nRow <= nEndRow; nRow++) ! 614: { ! 615: nVertPos = (nRow * YCHAR( npTTYInfo )) - YOFFSET( npTTYInfo ) ; ! 616: nHorzPos = (nCol * XCHAR( npTTYInfo )) - XOFFSET( npTTYInfo ) ; ! 617: rect.top = nVertPos ; ! 618: rect.bottom = nVertPos + YCHAR( npTTYInfo ) ; ! 619: rect.left = nHorzPos ; ! 620: rect.right = nHorzPos + XCHAR( npTTYInfo ) * nCount ; ! 621: SetBkMode( hDC, OPAQUE ) ; ! 622: ExtTextOut( hDC, nHorzPos, nVertPos, ETO_OPAQUE | ETO_CLIPPED, &rect, ! 623: (LPSTR)( SCREEN( npTTYInfo ) + nRow * MAXCOLS + nCol ), ! 624: nCount, NULL ) ; ! 625: } ! 626: SelectObject( hDC, hOldFont ) ; ! 627: EndPaint( hWnd, &ps ) ; ! 628: MoveTTYCursor( hWnd ) ; ! 629: return ( TRUE ) ; ! 630: ! 631: } // end of PaintTTY() ! 632: ! 633: //--------------------------------------------------------------------------- ! 634: // BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize ) ! 635: // ! 636: // Description: ! 637: // Sizes TTY and sets up scrolling regions. ! 638: // ! 639: // Parameters: ! 640: // HWND hWnd ! 641: // handle to TTY window ! 642: // ! 643: // WORD wVertSize ! 644: // new vertical size ! 645: // ! 646: // WORD wHorzSize ! 647: // new horizontal size ! 648: // ! 649: // History: Date Author Comment ! 650: // 5/ 8/ 91 BryanW Wrote it ! 651: // ! 652: //--------------------------------------------------------------------------- ! 653: ! 654: BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize ) ! 655: { ! 656: int nScrollAmt ; ! 657: NPTTYINFO npTTYInfo ; ! 658: ! 659: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 660: return ( FALSE ) ; ! 661: ! 662: YSIZE( npTTYInfo ) = (int) wVertSize ; ! 663: YSCROLL( npTTYInfo ) = max( 0, (MAXROWS * YCHAR( npTTYInfo )) - ! 664: YSIZE( npTTYInfo ) ) ; ! 665: nScrollAmt = min( YSCROLL( npTTYInfo ), YOFFSET( npTTYInfo ) ) - ! 666: YOFFSET( npTTYInfo ) ; ! 667: ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ; ! 668: ! 669: YOFFSET( npTTYInfo ) = YOFFSET( npTTYInfo ) + nScrollAmt ; ! 670: SetScrollPos( hWnd, SB_VERT, YOFFSET( npTTYInfo ), FALSE ) ; ! 671: SetScrollRange( hWnd, SB_VERT, 0, YSCROLL( npTTYInfo ), TRUE ) ; ! 672: ! 673: XSIZE( npTTYInfo ) = (int) wHorzSize ; ! 674: XSCROLL( npTTYInfo ) = max( 0, (MAXCOLS * XCHAR( npTTYInfo )) - ! 675: XSIZE( npTTYInfo ) ) ; ! 676: nScrollAmt = min( XSCROLL( npTTYInfo ), XOFFSET( npTTYInfo )) - ! 677: XOFFSET( npTTYInfo ) ; ! 678: ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ; ! 679: XOFFSET( npTTYInfo ) = XOFFSET( npTTYInfo ) + nScrollAmt ; ! 680: SetScrollPos( hWnd, SB_HORZ, XOFFSET( npTTYInfo ), FALSE ) ; ! 681: SetScrollRange( hWnd, SB_HORZ, 0, XSCROLL( npTTYInfo ), TRUE ) ; ! 682: ! 683: InvalidateRect( hWnd, NULL, TRUE ) ; ! 684: ! 685: return ( TRUE ) ; ! 686: ! 687: } // end of SizeTTY() ! 688: ! 689: //--------------------------------------------------------------------------- ! 690: // BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos ) ! 691: // ! 692: // Description: ! 693: // Scrolls TTY window vertically. ! 694: // ! 695: // Parameters: ! 696: // HWND hWnd ! 697: // handle to TTY window ! 698: // ! 699: // WORD wScrollCmd ! 700: // type of scrolling we're doing ! 701: // ! 702: // WORD wScrollPos ! 703: // scroll position ! 704: // ! 705: // History: Date Author Comment ! 706: // 5/ 8/91 BryanW Wrote it. ! 707: // ! 708: //--------------------------------------------------------------------------- ! 709: ! 710: BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos ) ! 711: { ! 712: int nScrollAmt ; ! 713: NPTTYINFO npTTYInfo ; ! 714: ! 715: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 716: return ( FALSE ) ; ! 717: ! 718: switch (wScrollCmd) ! 719: { ! 720: case SB_TOP: ! 721: nScrollAmt = -YOFFSET( npTTYInfo ) ; ! 722: break ; ! 723: ! 724: case SB_BOTTOM: ! 725: nScrollAmt = YSCROLL( npTTYInfo ) - YOFFSET( npTTYInfo ) ; ! 726: break ; ! 727: ! 728: case SB_PAGEUP: ! 729: nScrollAmt = -YSIZE( npTTYInfo ) ; ! 730: break ; ! 731: ! 732: case SB_PAGEDOWN: ! 733: nScrollAmt = YSIZE( npTTYInfo ) ; ! 734: break ; ! 735: ! 736: case SB_LINEUP: ! 737: nScrollAmt = -YCHAR( npTTYInfo ) ; ! 738: break ; ! 739: ! 740: case SB_LINEDOWN: ! 741: nScrollAmt = YCHAR( npTTYInfo ) ; ! 742: break ; ! 743: ! 744: case SB_THUMBPOSITION: ! 745: nScrollAmt = wScrollPos - YOFFSET( npTTYInfo ) ; ! 746: break ; ! 747: ! 748: default: ! 749: return ( FALSE ) ; ! 750: } ! 751: if ((YOFFSET( npTTYInfo ) + nScrollAmt) > YSCROLL( npTTYInfo )) ! 752: nScrollAmt = YSCROLL( npTTYInfo ) - YOFFSET( npTTYInfo ) ; ! 753: if ((YOFFSET( npTTYInfo ) + nScrollAmt) < 0) ! 754: nScrollAmt = -YOFFSET( npTTYInfo ) ; ! 755: ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ; ! 756: YOFFSET( npTTYInfo ) = YOFFSET( npTTYInfo ) + nScrollAmt ; ! 757: SetScrollPos( hWnd, SB_VERT, YOFFSET( npTTYInfo ), TRUE ) ; ! 758: ! 759: return ( TRUE ) ; ! 760: ! 761: } // end of ScrollTTYVert() ! 762: ! 763: //--------------------------------------------------------------------------- ! 764: // BOOL NEAR ScrollTTYHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos ) ! 765: // ! 766: // Description: ! 767: // Scrolls TTY window horizontally. ! 768: // ! 769: // Parameters: ! 770: // HWND hWnd ! 771: // handle to TTY window ! 772: // ! 773: // WORD wScrollCmd ! 774: // type of scrolling we're doing ! 775: // ! 776: // WORD wScrollPos ! 777: // scroll position ! 778: // ! 779: // History: Date Author Comment ! 780: // 5/ 8/91 BryanW Wrote it. ! 781: // ! 782: //--------------------------------------------------------------------------- ! 783: ! 784: BOOL NEAR ScrollTTYHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos ) ! 785: { ! 786: int nScrollAmt ; ! 787: NPTTYINFO npTTYInfo ; ! 788: ! 789: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 790: return ( FALSE ) ; ! 791: ! 792: switch (wScrollCmd) ! 793: { ! 794: case SB_TOP: ! 795: nScrollAmt = -XOFFSET( npTTYInfo ) ; ! 796: break ; ! 797: ! 798: case SB_BOTTOM: ! 799: nScrollAmt = XSCROLL( npTTYInfo ) - XOFFSET( npTTYInfo ) ; ! 800: break ; ! 801: ! 802: case SB_PAGEUP: ! 803: nScrollAmt = -XSIZE( npTTYInfo ) ; ! 804: break ; ! 805: ! 806: case SB_PAGEDOWN: ! 807: nScrollAmt = XSIZE( npTTYInfo ) ; ! 808: break ; ! 809: ! 810: case SB_LINEUP: ! 811: nScrollAmt = -XCHAR( npTTYInfo ) ; ! 812: break ; ! 813: ! 814: case SB_LINEDOWN: ! 815: nScrollAmt = XCHAR( npTTYInfo ) ; ! 816: break ; ! 817: ! 818: case SB_THUMBPOSITION: ! 819: nScrollAmt = wScrollPos - XOFFSET( npTTYInfo ) ; ! 820: break ; ! 821: ! 822: default: ! 823: return ( FALSE ) ; ! 824: } ! 825: if ((XOFFSET( npTTYInfo ) + nScrollAmt) > XSCROLL( npTTYInfo )) ! 826: nScrollAmt = XSCROLL( npTTYInfo ) - XOFFSET( npTTYInfo ) ; ! 827: if ((XOFFSET( npTTYInfo ) + nScrollAmt) < 0) ! 828: nScrollAmt = -XOFFSET( npTTYInfo ) ; ! 829: ScrollWindow( hWnd, -nScrollAmt, 0, NULL, NULL ) ; ! 830: XOFFSET( npTTYInfo ) = XOFFSET( npTTYInfo ) + nScrollAmt ; ! 831: SetScrollPos( hWnd, SB_HORZ, XOFFSET( npTTYInfo ), TRUE ) ; ! 832: ! 833: return ( TRUE ) ; ! 834: ! 835: } // end of ScrollTTYHorz() ! 836: ! 837: //--------------------------------------------------------------------------- ! 838: // BOOL NEAR SetTTYFocus( HWND hWnd ) ! 839: // ! 840: // Description: ! 841: // Sets the focus to the TTY window also creates caret. ! 842: // ! 843: // Parameters: ! 844: // HWND hWnd ! 845: // handle to TTY window ! 846: // ! 847: // History: Date Author Comment ! 848: // 5/ 9/91 BryanW Wrote it. ! 849: // ! 850: //--------------------------------------------------------------------------- ! 851: ! 852: BOOL NEAR SetTTYFocus( HWND hWnd ) ! 853: { ! 854: NPTTYINFO npTTYInfo ; ! 855: ! 856: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 857: return ( FALSE ) ; ! 858: ! 859: if (CONNECTED( npTTYInfo ) && (CURSORSTATE( npTTYInfo ) != CS_SHOW)) ! 860: { ! 861: CreateCaret( hWnd, NULL, XCHAR( npTTYInfo ), YCHAR( npTTYInfo ) ) ; ! 862: ShowCaret( hWnd ) ; ! 863: CURSORSTATE( npTTYInfo ) = CS_SHOW ; ! 864: } ! 865: MoveTTYCursor( hWnd ) ; ! 866: return ( TRUE ) ; ! 867: ! 868: } // end of SetTTYFocus() ! 869: ! 870: //--------------------------------------------------------------------------- ! 871: // BOOL NEAR KillTTYFocus( HWND hWnd ) ! 872: // ! 873: // Description: ! 874: // Kills TTY focus and destroys the caret. ! 875: // ! 876: // Parameters: ! 877: // HWND hWnd ! 878: // handle to TTY window ! 879: // ! 880: // History: Date Author Comment ! 881: // 5/ 9/91 BryanW Wrote it. ! 882: // ! 883: //--------------------------------------------------------------------------- ! 884: ! 885: BOOL NEAR KillTTYFocus( HWND hWnd ) ! 886: { ! 887: NPTTYINFO npTTYInfo ; ! 888: ! 889: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 890: return ( FALSE ) ; ! 891: ! 892: if (CONNECTED( npTTYInfo ) && (CURSORSTATE( npTTYInfo ) != CS_HIDE)) ! 893: { ! 894: HideCaret( hWnd ) ; ! 895: DestroyCaret() ; ! 896: CURSORSTATE( npTTYInfo ) = CS_HIDE ; ! 897: } ! 898: return ( TRUE ) ; ! 899: ! 900: } // end of KillTTYFocus() ! 901: ! 902: //--------------------------------------------------------------------------- ! 903: // BOOL NEAR MoveTTYCursor( HWND hWnd ) ! 904: // ! 905: // Description: ! 906: // Moves caret to current position. ! 907: // ! 908: // Parameters: ! 909: // HWND hWnd ! 910: // handle to TTY window ! 911: // ! 912: // History: Date Author Comment ! 913: // 5/ 9/91 BryanW Wrote it. ! 914: // ! 915: //--------------------------------------------------------------------------- ! 916: ! 917: BOOL NEAR MoveTTYCursor( HWND hWnd ) ! 918: { ! 919: NPTTYINFO npTTYInfo ; ! 920: ! 921: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 922: return ( FALSE ) ; ! 923: ! 924: if (CONNECTED( npTTYInfo ) && (CURSORSTATE( npTTYInfo ) & CS_SHOW)) ! 925: SetCaretPos( (COLUMN( npTTYInfo ) * XCHAR( npTTYInfo )) - ! 926: XOFFSET( npTTYInfo ), ! 927: (ROW( npTTYInfo ) * YCHAR( npTTYInfo )) - ! 928: YOFFSET( npTTYInfo ) ) ; ! 929: ! 930: return ( TRUE ) ; ! 931: ! 932: } // end of MoveTTYCursor() ! 933: ! 934: //--------------------------------------------------------------------------- ! 935: // BOOL NEAR ProcessCOMMNotification( HWND hWnd, ! 936: // WPARAM wParam, LPARAM lParam ) ; ! 937: // ! 938: // Description: ! 939: // Processes the WM_COMMNOTIFY message from the COMM.DRV. ! 940: // ! 941: // Parameters: ! 942: // HWND hWnd ! 943: // handle to TTY window ! 944: // ! 945: // WPARAM wParam ! 946: // specifes the device (nCid) ! 947: // ! 948: // LPARAM lParam ! 949: // LOWORD contains event trigger ! 950: // HIWORD is NULL ! 951: // ! 952: // Win-32 Porting Issues: ! 953: // - Function was constrained by WORD and LONG declarations. ! 954: // - Processing under Win-32 is much simpler and additionally ! 955: // requires the "posted message" flag to be cleared. ! 956: // ! 957: // History: Date Author Comment ! 958: // 5/10/91 BryanW Wrote it. ! 959: // 10/18/91 BryanW Updated to verify the event. ! 960: // 6/15/92 BryanW Removed WORD and LONG constraints. ! 961: // 6/15/92 BryanW Ported to Win-32. ! 962: // ! 963: //--------------------------------------------------------------------------- ! 964: ! 965: BOOL NEAR ProcessCOMMNotification( HWND hWnd, WPARAM wParam, LPARAM lParam ) ! 966: { ! 967: int nLength ; ! 968: BYTE abIn[ MAXBLOCK + 1] ; ! 969: NPTTYINFO npTTYInfo ; ! 970: MSG msg ; ! 971: ! 972: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 973: return ( FALSE ) ; ! 974: ! 975: #ifdef WIN32 ! 976: // verify that it is a COMM event sent by our thread ! 977: ! 978: if (CN_EVENT & LOWORD( lParam ) != CN_EVENT) ! 979: return ( FALSE ) ; ! 980: ! 981: // We loop here since it is highly likely that the buffer ! 982: // can been filled while we are reading this block. This ! 983: // is especially true when operating at high baud rates ! 984: // (e.g. >= 9600 baud). ! 985: ! 986: do ! 987: { ! 988: if (nLength = ReadCommBlock( hWnd, (LPSTR) abIn, MAXBLOCK )) ! 989: { ! 990: WriteTTYBlock( hWnd, (LPSTR) abIn, nLength ) ; ! 991: ! 992: // force a paint ! 993: ! 994: UpdateWindow( hWnd ) ; ! 995: } ! 996: } ! 997: while (!PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE) || (nLength > 0)) ; ! 998: ! 999: // clear our "posted notification" flag ! 1000: ! 1001: SetEvent( POSTEVENT( npTTYInfo ) ) ; ! 1002: #else ! 1003: if (!USECNRECEIVE( npTTYInfo )) ! 1004: { ! 1005: // verify that it is a COMM event specified by our mask ! 1006: ! 1007: if (CN_EVENT & LOWORD( lParam ) != CN_EVENT) ! 1008: return ( FALSE ) ; ! 1009: ! 1010: // For Windows 3.1, rested reset the event word so we are notified ! 1011: // when the next event occurs ! 1012: ! 1013: GetCommEventMask( COMDEV( npTTYInfo ), EV_RXCHAR ) ; ! 1014: ! 1015: // We loop here since it is highly likely that the buffer ! 1016: // can been filled while we are reading this block. This ! 1017: // is especially true when operating at high baud rates ! 1018: // (e.g. >= 9600 baud). ! 1019: ! 1020: do ! 1021: { ! 1022: if (nLength = ReadCommBlock( hWnd, (LPSTR) abIn, MAXBLOCK )) ! 1023: { ! 1024: WriteTTYBlock( hWnd, (LPSTR) abIn, nLength ) ; ! 1025: ! 1026: // force a paint ! 1027: ! 1028: UpdateWindow( hWnd ) ; ! 1029: } ! 1030: } ! 1031: while (!PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE) || (nLength > 0)) ; ! 1032: } ! 1033: else ! 1034: { ! 1035: // verify that it is a receive event ! 1036: ! 1037: if (CN_RECEIVE & LOWORD( lParam ) != CN_RECEIVE) ! 1038: return ( FALSE ) ; ! 1039: ! 1040: do ! 1041: { ! 1042: if (nLength = ReadCommBlock( hWnd, (LPSTR) abIn, MAXBLOCK )) ! 1043: { ! 1044: WriteTTYBlock( hWnd, (LPSTR) abIn, nLength ) ; ! 1045: ! 1046: // force a paint ! 1047: ! 1048: UpdateWindow( hWnd ) ; ! 1049: } ! 1050: } ! 1051: while ((!PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE )) || ! 1052: (ComStat.cbInQue >= MAXBLOCK)) ; ! 1053: } ! 1054: #endif ! 1055: ! 1056: return ( TRUE ) ; ! 1057: ! 1058: } // end of ProcessCOMMNotification() ! 1059: ! 1060: //--------------------------------------------------------------------------- ! 1061: // BOOL NEAR ProcessTTYCharacter( HWND hWnd, BYTE bOut ) ! 1062: // ! 1063: // Description: ! 1064: // This simply writes a character to the port and echos it ! 1065: // to the TTY screen if fLocalEcho is set. Some minor ! 1066: // keyboard mapping could be performed here. ! 1067: // ! 1068: // Parameters: ! 1069: // HWND hWnd ! 1070: // handle to TTY window ! 1071: // ! 1072: // BYTE bOut ! 1073: // byte from keyboard ! 1074: // ! 1075: // History: Date Author Comment ! 1076: // 5/11/91 BryanW Wrote it. ! 1077: // ! 1078: //--------------------------------------------------------------------------- ! 1079: ! 1080: BOOL NEAR ProcessTTYCharacter( HWND hWnd, BYTE bOut ) ! 1081: { ! 1082: NPTTYINFO npTTYInfo ; ! 1083: ! 1084: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1085: return ( FALSE ) ; ! 1086: ! 1087: if (!CONNECTED( npTTYInfo )) ! 1088: return ( FALSE ) ; ! 1089: ! 1090: WriteCommByte( hWnd, bOut ) ; ! 1091: if (LOCALECHO( npTTYInfo )) ! 1092: WriteTTYBlock( hWnd, &bOut, 1 ) ; ! 1093: ! 1094: return ( TRUE ) ; ! 1095: ! 1096: } // end of ProcessTTYCharacter() ! 1097: ! 1098: //--------------------------------------------------------------------------- ! 1099: // BOOL NEAR OpenConnection( HWND hWnd ) ! 1100: // ! 1101: // Description: ! 1102: // Opens communication port specified in the TTYINFO struct. ! 1103: // It also sets the CommState and notifies the window via ! 1104: // the fConnected flag in the TTYINFO struct. ! 1105: // ! 1106: // Parameters: ! 1107: // HWND hWnd ! 1108: // handle to TTY window ! 1109: // ! 1110: // Win-32 Porting Issues: ! 1111: // - OpenComm() is not supported under Win-32. Use OpenFile() ! 1112: // and setup for OVERLAPPED_IO. ! 1113: // - Win-32 has specific communication timeout parameters. ! 1114: // - Created the secondary thread for event notification. ! 1115: // ! 1116: // History: Date Author Comment ! 1117: // 5/ 9/91 BryanW Wrote it. ! 1118: // ! 1119: //--------------------------------------------------------------------------- ! 1120: ! 1121: BOOL NEAR OpenConnection( HWND hWnd ) ! 1122: { ! 1123: char szPort[ 10 ], szTemp[ 10 ] ; ! 1124: BOOL fRetVal ; ! 1125: HCURSOR hOldCursor, hWaitCursor ; ! 1126: HMENU hMenu ; ! 1127: NPTTYINFO npTTYInfo ; ! 1128: ! 1129: #ifdef WIN32 ! 1130: HANDLE hCommWatchThread ; ! 1131: DWORD dwThreadID ; ! 1132: COMMTIMEOUTS CommTimeOuts ; ! 1133: #endif ! 1134: ! 1135: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1136: return ( FALSE ) ; ! 1137: ! 1138: // show the hourglass cursor ! 1139: hWaitCursor = LoadCursor( NULL, IDC_WAIT ) ; ! 1140: hOldCursor = SetCursor( hWaitCursor ) ; ! 1141: ! 1142: // load the COM prefix string and append port number ! 1143: ! 1144: LoadString( GETHINST( hWnd ), IDS_COMPREFIX, szTemp, sizeof( szTemp ) ) ; ! 1145: wsprintf( szPort, "%s%d", (LPSTR) szTemp, PORT( npTTYInfo ) ) ; ! 1146: ! 1147: // open COMM device ! 1148: ! 1149: #ifdef WIN32 ! 1150: if ((COMDEV( npTTYInfo ) = ! 1151: CreateFile( szPort, GENERIC_READ | GENERIC_WRITE, ! 1152: 0, // exclusive access ! 1153: NULL, // no security attrs ! 1154: OPEN_EXISTING, ! 1155: FILE_FLAG_OVERLAPPED, // overlapped I/O ! 1156: NULL )) == (HANDLE) -1 ) ! 1157: return ( FALSE ) ; ! 1158: else ! 1159: { ! 1160: // purge any information in the buffer ! 1161: ! 1162: PurgeComm( COMDEV( npTTYInfo ), PURGE_TXABORT | PURGE_RXABORT | ! 1163: PURGE_TXCLEAR | PURGE_RXCLEAR ) ; ! 1164: ! 1165: // set up for overlapped non-blocking I/O ! 1166: ! 1167: CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF ; ! 1168: CommTimeOuts.ReadTotalTimeoutMultiplier = 0 ; ! 1169: CommTimeOuts.ReadTotalTimeoutConstant = 0 ; ! 1170: CommTimeOuts.WriteTotalTimeoutMultiplier = 0 ; ! 1171: CommTimeOuts.WriteTotalTimeoutConstant = 0 ; ! 1172: SetCommTimeouts( COMDEV( npTTYInfo ), &CommTimeOuts ) ; ! 1173: } ! 1174: #else ! 1175: if ((COMDEV( npTTYInfo ) = OpenComm( szPort, RXQUEUE, TXQUEUE )) < 0) ! 1176: return ( FALSE ) ; ! 1177: #endif ! 1178: ! 1179: fRetVal = SetupConnection( hWnd ) ; ! 1180: ! 1181: if (fRetVal) ! 1182: { ! 1183: CONNECTED( npTTYInfo ) = TRUE ; ! 1184: ! 1185: #ifdef WIN32 ! 1186: // In the case of Win32, we create a secondary thread ! 1187: // to watch for an event. ! 1188: ! 1189: if (NULL == (hCommWatchThread = ! 1190: CreateThread( (LPSECURITY_ATTRIBUTES) NULL, ! 1191: 0, ! 1192: (LPTHREAD_START_ROUTINE) CommWatchProc, ! 1193: (LPVOID) npTTYInfo, ! 1194: NULL, &dwThreadID ))) ! 1195: { ! 1196: CONNECTED( npTTYInfo ) = FALSE ; ! 1197: CloseHandle( COMDEV( npTTYInfo ) ) ; ! 1198: fRetVal = FALSE ; ! 1199: } ! 1200: else ! 1201: { ! 1202: THREADID( npTTYInfo ) = dwThreadID ; ! 1203: HTHREAD( npTTYInfo ) = hCommWatchThread ; ! 1204: ! 1205: // assert DTR ! 1206: ! 1207: EscapeCommFunction( COMDEV( npTTYInfo ), SETDTR ) ; ! 1208: ! 1209: ! 1210: SetTTYFocus( hWnd ) ; ! 1211: ! 1212: hMenu = GetMenu( hWnd ) ; ! 1213: EnableMenuItem( hMenu, IDM_DISCONNECT, ! 1214: MF_ENABLED | MF_BYCOMMAND ) ; ! 1215: EnableMenuItem( hMenu, IDM_CONNECT, ! 1216: MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ; ! 1217: } ! 1218: #else ! 1219: // Under Windows 3.1, we set up notifications from COMM.DRV ! 1220: ! 1221: if (!USECNRECEIVE( npTTYInfo )) ! 1222: { ! 1223: // In this case we really are only using the notifications ! 1224: // for the received characters - it could be expanded to ! 1225: // cover the changes in CD or other status lines. ! 1226: ! 1227: SetCommEventMask( COMDEV( npTTYInfo ), EV_RXCHAR ) ; ! 1228: ! 1229: // Enable notifications for events only. ! 1230: ! 1231: // NB: This method does not use the specific ! 1232: // in/out queue triggers. ! 1233: ! 1234: EnableCommNotification( COMDEV( npTTYInfo ), hWnd, -1, -1 ) ; ! 1235: } ! 1236: else ! 1237: { ! 1238: // Enable notification for CN_RECEIVE events. ! 1239: ! 1240: EnableCommNotification( COMDEV( npTTYInfo ), hWnd, MAXBLOCK, -1 ) ; ! 1241: } ! 1242: ! 1243: // assert DTR ! 1244: ! 1245: EscapeCommFunction( COMDEV( npTTYInfo ), SETDTR ) ; ! 1246: ! 1247: ! 1248: SetTTYFocus( hWnd ) ; ! 1249: ! 1250: hMenu = GetMenu( hWnd ) ; ! 1251: EnableMenuItem( hMenu, IDM_DISCONNECT, ! 1252: MF_ENABLED | MF_BYCOMMAND ) ; ! 1253: EnableMenuItem( hMenu, IDM_CONNECT, ! 1254: MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ; ! 1255: #endif ! 1256: } ! 1257: else ! 1258: { ! 1259: CONNECTED( npTTYInfo ) = FALSE ; ! 1260: ! 1261: #ifdef WIN32 ! 1262: CloseHandle( COMDEV( npTTYInfo ) ) ; ! 1263: #else ! 1264: CloseComm( COMDEV( npTTYInfo ) ) ; ! 1265: #endif ! 1266: } ! 1267: ! 1268: // restore cursor ! 1269: ! 1270: SetCursor( hOldCursor ) ; ! 1271: ! 1272: return ( fRetVal ) ; ! 1273: ! 1274: } // end of OpenConnection() ! 1275: ! 1276: //--------------------------------------------------------------------------- ! 1277: // BOOL NEAR SetupConnection( HWND hWnd ) ! 1278: // ! 1279: // Description: ! 1280: // This routines sets up the DCB based on settings in the ! 1281: // TTY info structure and performs a SetCommState(). ! 1282: // ! 1283: // Parameters: ! 1284: // HWND hWnd ! 1285: // handle to TTY window ! 1286: // ! 1287: // Win-32 Porting Issues: ! 1288: // - Win-32 requires a slightly different processing of the DCB. ! 1289: // Changes were made for configuration of the hardware handshaking ! 1290: // lines. ! 1291: // ! 1292: // History: Date Author Comment ! 1293: // 5/ 9/91 BryanW Wrote it. ! 1294: // ! 1295: //--------------------------------------------------------------------------- ! 1296: ! 1297: BOOL NEAR SetupConnection( HWND hWnd ) ! 1298: { ! 1299: BOOL fRetVal ; ! 1300: BYTE bSet ; ! 1301: DCB dcb ; ! 1302: NPTTYINFO npTTYInfo ; ! 1303: ! 1304: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1305: return ( FALSE ) ; ! 1306: ! 1307: #ifdef WIN32 ! 1308: dcb.DCBlength = sizeof( DCB ) ; ! 1309: #endif ! 1310: ! 1311: GetCommState( COMDEV( npTTYInfo ), &dcb ) ; ! 1312: ! 1313: dcb.BaudRate = BAUDRATE( npTTYInfo ) ; ! 1314: dcb.ByteSize = BYTESIZE( npTTYInfo ) ; ! 1315: dcb.Parity = PARITY( npTTYInfo ) ; ! 1316: dcb.StopBits = STOPBITS( npTTYInfo ) ; ! 1317: ! 1318: // setup hardware flow control ! 1319: ! 1320: bSet = (BYTE) ((FLOWCTRL( npTTYInfo ) & FC_DTRDSR) != 0) ; ! 1321: #ifdef WIN32 ! 1322: dcb.fOutxDsrFlow = bSet ; ! 1323: if (bSet) ! 1324: dcb.fDtrControl = DTR_CONTROL_HANDSHAKE ; ! 1325: else ! 1326: dcb.fDtrControl = DTR_CONTROL_ENABLE ; ! 1327: #else ! 1328: dcb.fOutxDsrFlow = dcb.fDtrflow = bSet ; ! 1329: dcb.DsrTimeout = (bSet) ? 30 : 0 ; ! 1330: #endif ! 1331: ! 1332: bSet = (BYTE) ((FLOWCTRL( npTTYInfo ) & FC_RTSCTS) != 0) ; ! 1333: #ifdef WIN32 ! 1334: dcb.fOutxCtsFlow = bSet ; ! 1335: if (bSet) ! 1336: dcb.fRtsControl = RTS_CONTROL_HANDSHAKE ; ! 1337: else ! 1338: dcb.fRtsControl = RTS_CONTROL_ENABLE ; ! 1339: #else ! 1340: dcb.fOutxCtsFlow = dcb.fRtsflow = bSet ; ! 1341: dcb.CtsTimeout = (bSet) ? 30 : 0 ; ! 1342: #endif ! 1343: ! 1344: // setup software flow control ! 1345: ! 1346: bSet = (BYTE) ((FLOWCTRL( npTTYInfo ) & FC_XONXOFF) != 0) ; ! 1347: ! 1348: dcb.fInX = dcb.fOutX = bSet ; ! 1349: dcb.XonChar = ASCII_XON ; ! 1350: dcb.XoffChar = ASCII_XOFF ; ! 1351: dcb.XonLim = 100 ; ! 1352: dcb.XoffLim = 100 ; ! 1353: ! 1354: // other various settings ! 1355: ! 1356: dcb.fBinary = TRUE ; ! 1357: dcb.fParity = TRUE ; ! 1358: ! 1359: #ifndef WIN32 ! 1360: dcb.fRtsDisable = FALSE ; ! 1361: dcb.fDtrDisable = FALSE ; ! 1362: fRetVal = !(SetCommState( &dcb ) < 0) ; ! 1363: #else ! 1364: fRetVal = SetCommState( COMDEV( npTTYInfo ), &dcb ) ; ! 1365: #endif ! 1366: ! 1367: return ( fRetVal ) ; ! 1368: ! 1369: } // end of SetupConnection() ! 1370: ! 1371: //--------------------------------------------------------------------------- ! 1372: // BOOL NEAR CloseConnection( HWND hWnd ) ! 1373: // ! 1374: // Description: ! 1375: // Closes the connection to the port. Resets the connect flag ! 1376: // in the TTYINFO struct. ! 1377: // ! 1378: // Parameters: ! 1379: // HWND hWnd ! 1380: // handle to TTY window ! 1381: // ! 1382: // Win-32 Porting Issues: ! 1383: // - Needed to stop secondary thread. SetCommMask() will signal the ! 1384: // WaitCommEvent() event and the thread will halt when the ! 1385: // CONNECTED() flag is clear. ! 1386: // - Use new PurgeComm() API to clear communications driver before ! 1387: // closing device. ! 1388: // ! 1389: // History: Date Author Comment ! 1390: // 5/ 9/91 BryanW Wrote it. ! 1391: // 6/15/92 BryanW Ported to Win-32. ! 1392: // ! 1393: //--------------------------------------------------------------------------- ! 1394: ! 1395: BOOL NEAR CloseConnection( HWND hWnd ) ! 1396: { ! 1397: HMENU hMenu ; ! 1398: NPTTYINFO npTTYInfo ; ! 1399: ! 1400: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1401: return ( FALSE ) ; ! 1402: ! 1403: // set connected flag to FALSE ! 1404: ! 1405: CONNECTED( npTTYInfo ) = FALSE ; ! 1406: ! 1407: #ifdef WIN32 ! 1408: // disable event notification and wait for thread ! 1409: // to halt ! 1410: ! 1411: SetCommMask( COMDEV( npTTYInfo ), NULL ) ; ! 1412: ! 1413: // block until thread has been halted ! 1414: ! 1415: while (THREADID( npTTYInfo ) != NULL) ; ! 1416: #else ! 1417: // Disable event notification. Using a NULL hWnd tells ! 1418: // the COMM.DRV to disable future notifications. ! 1419: ! 1420: EnableCommNotification( COMDEV( npTTYInfo ), NULL, -1, -1 ) ; ! 1421: #endif ! 1422: ! 1423: // kill the focus ! 1424: ! 1425: KillTTYFocus( hWnd ) ; ! 1426: ! 1427: // drop DTR ! 1428: ! 1429: EscapeCommFunction( COMDEV( npTTYInfo ), CLRDTR ) ; ! 1430: ! 1431: #ifdef WIN32 ! 1432: // purge any outstanding reads/writes and close device handle ! 1433: ! 1434: PurgeComm( COMDEV( npTTYInfo ), PURGE_TXABORT | PURGE_RXABORT | ! 1435: PURGE_TXCLEAR | PURGE_RXCLEAR ) ; ! 1436: CloseHandle( COMDEV( npTTYInfo ) ) ; ! 1437: #else ! 1438: // close comm connection ! 1439: ! 1440: CloseComm( COMDEV( npTTYInfo ) ) ; ! 1441: #endif ! 1442: ! 1443: // change the selectable items in the menu ! 1444: ! 1445: hMenu = GetMenu( hWnd ) ; ! 1446: EnableMenuItem( hMenu, IDM_DISCONNECT, ! 1447: MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ; ! 1448: EnableMenuItem( hMenu, IDM_CONNECT, ! 1449: MF_ENABLED | MF_BYCOMMAND ) ; ! 1450: ! 1451: return ( TRUE ) ; ! 1452: ! 1453: } // end of CloseConnection() ! 1454: ! 1455: //--------------------------------------------------------------------------- ! 1456: // int NEAR ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength ) ! 1457: // ! 1458: // Description: ! 1459: // Reads a block from the COM port and stuffs it into ! 1460: // the provided block. ! 1461: // ! 1462: // Parameters: ! 1463: // HWND hWnd ! 1464: // handle to TTY window ! 1465: // ! 1466: // LPSTR lpszBlock ! 1467: // block used for storage ! 1468: // ! 1469: // int nMaxLength ! 1470: // max length of block to read ! 1471: // ! 1472: // Win-32 Porting Issues: ! 1473: // - ReadComm() has been replaced by ReadFile() in Win-32. ! 1474: // - Overlapped I/O has been implemented. ! 1475: // ! 1476: // History: Date Author Comment ! 1477: // 5/10/91 BryanW Wrote it. ! 1478: // ! 1479: //--------------------------------------------------------------------------- ! 1480: ! 1481: int NEAR ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength ) ! 1482: { ! 1483: #ifdef WIN32 ! 1484: DWORD nLength ; ! 1485: BOOL fReadStat ; ! 1486: COMSTAT ComStat ; ! 1487: DWORD dwErrorFlags ; ! 1488: #else ! 1489: int nLength, nError ; ! 1490: #endif ! 1491: ! 1492: char szError[ 10 ] ; ! 1493: NPTTYINFO npTTYInfo ; ! 1494: ! 1495: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1496: return ( FALSE ) ; ! 1497: ! 1498: #ifdef WIN32 ! 1499: ClearCommError( COMDEV( npTTYInfo ), &dwErrorFlags, &ComStat ) ; ! 1500: if ((dwErrorFlags > 0) && DISPLAYERRORS( npTTYInfo )) ! 1501: { ! 1502: wsprintf( szError, "<CE-%u>", dwErrorFlags ) ; ! 1503: WriteTTYBlock( hWnd, szError, lstrlen( szError ) ) ; ! 1504: } ! 1505: nLength = min( (DWORD) nMaxLength, ComStat.cbInQue ) ; ! 1506: if (nLength > 0) ! 1507: { ! 1508: fReadStat = ReadFile( COMDEV( npTTYInfo ), lpszBlock, ! 1509: nLength, &nLength, &READ_OS( npTTYInfo ) ) ; ! 1510: if (!fReadStat) ! 1511: { ! 1512: if (GetLastError() == ERROR_IO_PENDING) ! 1513: { ! 1514: OutputDebugString( "ReadCommBlock: I/O Pending.\r\n" ) ; ! 1515: ! 1516: // wait for a second for this transmission to complete ! 1517: ! 1518: if (WaitForSingleObject( READ_OS( npTTYInfo ).hEvent, 1000 )) ! 1519: nLength = 0 ; ! 1520: else ! 1521: { ! 1522: GetOverlappedResult( COMDEV( npTTYInfo ), ! 1523: &READ_OS( npTTYInfo ), ! 1524: &nLength, FALSE ) ; ! 1525: READ_OS( npTTYInfo ).Offset += nLength ; ! 1526: } ! 1527: } ! 1528: else ! 1529: // some other error occurred ! 1530: ! 1531: nLength = 0 ; ! 1532: } ! 1533: } ! 1534: #else ! 1535: nLength = ReadComm( COMDEV( npTTYInfo ), lpszBlock, nMaxLength ) ; ! 1536: ! 1537: if (nLength < 0) ! 1538: { ! 1539: nLength *= -1 ; ! 1540: while (nError = GetCommError( COMDEV( npTTYInfo ), NULL )) ! 1541: { ! 1542: if (DISPLAYERRORS( npTTYInfo )) ! 1543: { ! 1544: wsprintf( szError, "<CE-%d>", nError ) ; ! 1545: WriteTTYBlock( hWnd, szError, lstrlen( szError ) ) ; ! 1546: } ! 1547: } ! 1548: } ! 1549: #endif ! 1550: ! 1551: return ( nLength ) ; ! 1552: ! 1553: } // end of ReadCommBlock() ! 1554: ! 1555: //--------------------------------------------------------------------------- ! 1556: // BOOL NEAR WriteCommByte( HWND hWnd, BYTE bByte ) ! 1557: // ! 1558: // Description: ! 1559: // Writes a byte to the COM port specified in the associated ! 1560: // TTY info structure. ! 1561: // ! 1562: // Parameters: ! 1563: // HWND hWnd ! 1564: // handle to TTY window ! 1565: // ! 1566: // BYTE bByte ! 1567: // byte to write to port ! 1568: // ! 1569: // Win-32 Porting Issues: ! 1570: // - WriteComm() has been replaced by WriteFile() in Win-32. ! 1571: // - Overlapped I/O has been implemented. ! 1572: // ! 1573: // History: Date Author Comment ! 1574: // 5/10/91 BryanW Wrote it. ! 1575: // ! 1576: //--------------------------------------------------------------------------- ! 1577: ! 1578: BOOL NEAR WriteCommByte( HWND hWnd, BYTE bByte ) ! 1579: { ! 1580: #ifdef WIN32 ! 1581: BOOL fWriteStat ; ! 1582: DWORD dwBytesWritten ; ! 1583: #endif ! 1584: NPTTYINFO npTTYInfo ; ! 1585: ! 1586: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1587: return ( FALSE ) ; ! 1588: ! 1589: #ifdef WIN32 ! 1590: fWriteStat = WriteFile( COMDEV( npTTYInfo ), (LPSTR) &bByte, 1, ! 1591: &dwBytesWritten, &WRITE_OS( npTTYInfo ) ) ; ! 1592: if (!fWriteStat && (GetLastError() == ERROR_IO_PENDING)) ! 1593: { ! 1594: OutputDebugString( "WriteCommByte: I/O Pending.\r\n" ) ; ! 1595: ! 1596: // wait for a second for this transmission to complete ! 1597: ! 1598: if (WaitForSingleObject( WRITE_OS( npTTYInfo ).hEvent, 1000 )) ! 1599: dwBytesWritten = 0 ; ! 1600: else ! 1601: { ! 1602: GetOverlappedResult( COMDEV( npTTYInfo ), ! 1603: &WRITE_OS( npTTYInfo ), ! 1604: &dwBytesWritten, FALSE ) ; ! 1605: WRITE_OS( npTTYInfo ).Offset += dwBytesWritten ; ! 1606: } ! 1607: } ! 1608: #else ! 1609: WriteComm( COMDEV( npTTYInfo ), (LPSTR) &bByte, 1 ) ; ! 1610: #endif ! 1611: return ( TRUE ) ; ! 1612: ! 1613: } // end of WriteCommByte() ! 1614: ! 1615: //--------------------------------------------------------------------------- ! 1616: // BOOL NEAR WriteTTYBlock( HWND hWnd, LPSTR lpBlock, int nLength ) ! 1617: // ! 1618: // Description: ! 1619: // Writes block to TTY screen. Nothing fancy - just ! 1620: // straight TTY. ! 1621: // ! 1622: // Parameters: ! 1623: // HWND hWnd ! 1624: // handle to TTY window ! 1625: // ! 1626: // LPSTR lpBlock ! 1627: // far pointer to block of data ! 1628: // ! 1629: // int nLength ! 1630: // length of block ! 1631: // ! 1632: // History: Date Author Comment ! 1633: // 5/ 9/91 BryanW Wrote it. ! 1634: // 5/20/91 BryanW Modified... not character based, ! 1635: // block based now. It was processing ! 1636: // per char. ! 1637: // ! 1638: //--------------------------------------------------------------------------- ! 1639: ! 1640: BOOL NEAR WriteTTYBlock( HWND hWnd, LPSTR lpBlock, int nLength ) ! 1641: { ! 1642: int i ; ! 1643: NPTTYINFO npTTYInfo ; ! 1644: RECT rect ; ! 1645: ! 1646: if (NULL == (npTTYInfo = GETNPTTYINFO( hWnd ))) ! 1647: return ( FALSE ) ; ! 1648: ! 1649: for (i = 0 ; i < nLength; i++) ! 1650: { ! 1651: switch (lpBlock[ i ]) ! 1652: { ! 1653: case ASCII_BEL: ! 1654: // Bell ! 1655: MessageBeep( 0 ) ; ! 1656: break ; ! 1657: ! 1658: case ASCII_BS: ! 1659: // Backspace ! 1660: if (COLUMN( npTTYInfo ) > 0) ! 1661: COLUMN( npTTYInfo ) -- ; ! 1662: MoveTTYCursor( hWnd ) ; ! 1663: break ; ! 1664: ! 1665: case ASCII_CR: ! 1666: // Carriage return ! 1667: COLUMN( npTTYInfo ) = 0 ; ! 1668: MoveTTYCursor( hWnd ) ; ! 1669: if (!NEWLINE( npTTYInfo )) ! 1670: break; ! 1671: ! 1672: // fall through ! 1673: ! 1674: case ASCII_LF: ! 1675: // Line feed ! 1676: if (ROW( npTTYInfo )++ == MAXROWS - 1) ! 1677: { ! 1678: _fmemmove( (LPSTR) (SCREEN( npTTYInfo )), ! 1679: (LPSTR) (SCREEN( npTTYInfo ) + MAXCOLS), ! 1680: (MAXROWS - 1) * MAXCOLS ) ; ! 1681: _fmemset( (LPSTR) (SCREEN( npTTYInfo ) + (MAXROWS - 1) * MAXCOLS), ! 1682: ' ', MAXCOLS ) ; ! 1683: InvalidateRect( hWnd, NULL, FALSE ) ; ! 1684: ROW( npTTYInfo )-- ; ! 1685: } ! 1686: MoveTTYCursor( hWnd ) ; ! 1687: break ; ! 1688: ! 1689: default: ! 1690: *(SCREEN( npTTYInfo ) + ROW( npTTYInfo ) * MAXCOLS + ! 1691: COLUMN( npTTYInfo )) = lpBlock[ i ] ; ! 1692: rect.left = (COLUMN( npTTYInfo ) * XCHAR( npTTYInfo )) - ! 1693: XOFFSET( npTTYInfo ) ; ! 1694: rect.right = rect.left + XCHAR( npTTYInfo ) ; ! 1695: rect.top = (ROW( npTTYInfo ) * YCHAR( npTTYInfo )) - ! 1696: YOFFSET( npTTYInfo ) ; ! 1697: rect.bottom = rect.top + YCHAR( npTTYInfo ) ; ! 1698: InvalidateRect( hWnd, &rect, FALSE ) ; ! 1699: ! 1700: // Line wrap ! 1701: if (COLUMN( npTTYInfo ) < MAXCOLS - 1) ! 1702: COLUMN( npTTYInfo )++ ; ! 1703: else if (AUTOWRAP( npTTYInfo )) ! 1704: WriteTTYBlock( hWnd, "\r\n", 2 ) ; ! 1705: break; ! 1706: } ! 1707: } ! 1708: return ( TRUE ) ; ! 1709: ! 1710: } // end of WriteTTYBlock() ! 1711: ! 1712: //--------------------------------------------------------------------------- ! 1713: // VOID NEAR GoModalDialogBoxParam( HINSTANCE hInstance, ! 1714: // LPCSTR lpszTemplate, HWND hWnd, ! 1715: // DLGPROC lpDlgProc, LPARAM lParam ) ! 1716: // ! 1717: // Description: ! 1718: // It is a simple utility function that simply performs the ! 1719: // MPI and invokes the dialog box with a DWORD paramter. ! 1720: // ! 1721: // Parameters: ! 1722: // similar to that of DialogBoxParam() with the exception ! 1723: // that the lpDlgProc is not a procedure instance ! 1724: // ! 1725: // History: Date Author Comment ! 1726: // 5/10/91 BryanW Wrote it. ! 1727: // ! 1728: //--------------------------------------------------------------------------- ! 1729: ! 1730: VOID NEAR GoModalDialogBoxParam( HINSTANCE hInstance, LPCSTR lpszTemplate, ! 1731: HWND hWnd, DLGPROC lpDlgProc, LPARAM lParam ) ! 1732: { ! 1733: DLGPROC lpProcInstance ; ! 1734: ! 1735: lpProcInstance = (DLGPROC) MakeProcInstance( (FARPROC) lpDlgProc, ! 1736: hInstance ) ; ! 1737: DialogBoxParam( hInstance, lpszTemplate, hWnd, lpProcInstance, lParam ) ; ! 1738: FreeProcInstance( (FARPROC) lpProcInstance ) ; ! 1739: ! 1740: } // end of GoModalDialogBoxParam() ! 1741: ! 1742: //--------------------------------------------------------------------------- ! 1743: // BOOL FAR PASCAL AboutDlgProc( HWND hDlg, UINT uMsg, ! 1744: // WPARAM wParam, LPARAM lParam ) ! 1745: // ! 1746: // Description: ! 1747: // Simulates the Windows System Dialog Box. ! 1748: // ! 1749: // Parameters: ! 1750: // Same as standard dialog procedures. ! 1751: // ! 1752: // History: Date Author Comment ! 1753: // 10/19/91 BryanW Added this little extra. ! 1754: // ! 1755: //--------------------------------------------------------------------------- ! 1756: ! 1757: BOOL FAR PASCAL AboutDlgProc( HWND hDlg, UINT uMsg, ! 1758: WPARAM wParam, LPARAM lParam ) ! 1759: { ! 1760: switch (uMsg) ! 1761: { ! 1762: case WM_INITDIALOG: ! 1763: { ! 1764: #ifdef WIN32 ! 1765: char szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ]; ! 1766: DWORD dwFreeMemory ; ! 1767: WORD wRevision, wVersion ; ! 1768: #else ! 1769: int idModeString ; ! 1770: char szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ] ; ! 1771: DWORD dwFreeMemory, dwWinFlags ; ! 1772: WORD wFreeResources, wRevision, wVersion ; ! 1773: #endif ! 1774: ! 1775: #ifdef ABOUTDLG_USEBITMAP ! 1776: // if we are using the bitmap, hide the icon ! 1777: ! 1778: ShowWindow( GetDlgItem( hDlg, IDD_ABOUTICON ), SW_HIDE ) ; ! 1779: #endif ! 1780: // sets up the version number for Windows ! 1781: ! 1782: wVersion = LOWORD( GetVersion() ) ; ! 1783: wRevision = HIBYTE( wVersion ) ; ! 1784: wVersion = LOBYTE( wVersion ) ; ! 1785: ! 1786: GetDlgItemText( hDlg, IDD_TITLELINE, szTemp, sizeof( szTemp ) ) ; ! 1787: wsprintf( szBuffer, szTemp, wVersion, wRevision ) ; ! 1788: SetDlgItemText( hDlg, IDD_TITLELINE, szBuffer ) ; ! 1789: ! 1790: // sets up version number for TTY ! 1791: ! 1792: GetDlgItemText( hDlg, IDD_VERSION, szTemp, sizeof( szTemp ) ) ; ! 1793: wsprintf( szBuffer, szTemp, VER_MAJOR, VER_MINOR, VER_BUILD ) ; ! 1794: SetDlgItemText( hDlg, IDD_VERSION, (LPSTR) szBuffer ) ; ! 1795: ! 1796: // get by-line ! 1797: ! 1798: LoadString( GETHINST( hDlg ), IDS_BYLINE, szBuffer, ! 1799: sizeof( szBuffer ) ) ; ! 1800: SetDlgItemText( hDlg, IDD_BYLINE, szBuffer ) ; ! 1801: ! 1802: #ifndef WIN32 ! 1803: // set windows mode information ! 1804: ! 1805: dwWinFlags = GetWinFlags() ; ! 1806: if (dwWinFlags & WF_ENHANCED) ! 1807: idModeString = IDS_MODE_ENHANCED ; ! 1808: else if (dwWinFlags & WF_STANDARD) ! 1809: idModeString = IDS_MODE_STANDARD ; ! 1810: else if (dwWinFlags & WF_WLO) ! 1811: idModeString = IDS_MODE_WLO ; ! 1812: else ! 1813: idModeString = IDS_MODE_UNDEF ; ! 1814: ! 1815: LoadString( GETHINST( hDlg ), idModeString, szBuffer, ! 1816: sizeof( szBuffer ) ) ; ! 1817: SetDlgItemText( hDlg, IDD_WINDOWSMODE, szBuffer ) ; ! 1818: #else ! 1819: SetDlgItemText( hDlg, IDD_WINDOWSMODE, "NT Mode" ) ; ! 1820: #endif ! 1821: ! 1822: // get free memory information ! 1823: ! 1824: dwFreeMemory = GetFreeSpace( 0 ) / 1024L ; ! 1825: GetDlgItemText( hDlg, IDD_FREEMEM, szTemp, sizeof( szTemp ) ) ; ! 1826: wsprintf( szBuffer, szTemp, dwFreeMemory ) ; ! 1827: SetDlgItemText( hDlg, IDD_FREEMEM, (LPSTR) szBuffer ) ; ! 1828: ! 1829: #ifndef WIN32 ! 1830: // get free resources information ! 1831: ! 1832: wFreeResources = GetFreeSystemResources( 0 ) ; ! 1833: GetDlgItemText( hDlg, IDD_RESOURCES, szTemp, sizeof( szTemp ) ) ; ! 1834: wsprintf( szBuffer, szTemp, wFreeResources ) ; ! 1835: SetDlgItemText( hDlg, IDD_RESOURCES, (LPSTR) szBuffer ) ; ! 1836: #endif ! 1837: } ! 1838: return ( TRUE ) ; ! 1839: ! 1840: #ifdef ABOUTDLG_USEBITMAP ! 1841: // used to paint the bitmap ! 1842: ! 1843: case WM_PAINT: ! 1844: { ! 1845: HBITMAP hBitMap ; ! 1846: HDC hDC, hMemDC ; ! 1847: PAINTSTRUCT ps ; ! 1848: ! 1849: // load bitmap and display it ! 1850: ! 1851: hDC = BeginPaint( hDlg, &ps ) ; ! 1852: if (NULL != (hMemDC = CreateCompatibleDC( hDC ))) ! 1853: { ! 1854: hBitMap = LoadBitmap( GETHINST( hDlg ), ! 1855: MAKEINTRESOURCE( TTYBITMAP ) ) ; ! 1856: hBitMap = SelectObject( hMemDC, hBitMap ) ; ! 1857: BitBlt( hDC, 10, 10, 64, 64, hMemDC, 0, 0, SRCCOPY ) ; ! 1858: DeleteObject( SelectObject( hMemDC, hBitMap ) ) ; ! 1859: DeleteDC( hMemDC ) ; ! 1860: } ! 1861: EndPaint( hDlg, &ps ) ; ! 1862: } ! 1863: break ; ! 1864: #endif ! 1865: ! 1866: case WM_COMMAND: ! 1867: if (LOWORD( wParam ) == IDD_OK) ! 1868: { ! 1869: EndDialog( hDlg, TRUE ) ; ! 1870: return ( TRUE ) ; ! 1871: } ! 1872: break; ! 1873: } ! 1874: return ( FALSE ) ; ! 1875: ! 1876: } // end of AboutDlgProc() ! 1877: ! 1878: //--------------------------------------------------------------------------- ! 1879: // VOID NEAR FillComboBox( HINSTANCE hInstance, HWND hCtrlWnd, int nIDString, ! 1880: // WORD NEAR *npTable, WORD wTableLen, ! 1881: // WORD wCurrentSetting ) ! 1882: // ! 1883: // Description: ! 1884: // Fills the given combo box with strings from the resource ! 1885: // table starting at nIDString. Associated items are ! 1886: // added from given table. The combo box is notified of ! 1887: // the current setting. ! 1888: // ! 1889: // Parameters: ! 1890: // HINSTANCE hInstance ! 1891: // handle to application instance ! 1892: // ! 1893: // HWND hCtrlWnd ! 1894: // handle to combo box control ! 1895: // ! 1896: // int nIDString ! 1897: // first resource string id ! 1898: // ! 1899: // DWORD NEAR *npTable ! 1900: // near point to table of associated values ! 1901: // ! 1902: // WORD wTableLen ! 1903: // length of table ! 1904: // ! 1905: // DWORD dwCurrentSetting ! 1906: // current setting (for combo box selection) ! 1907: // ! 1908: // History: Date Author Comment ! 1909: // 10/20/91 BryanW Pulled from the init procedure. ! 1910: // ! 1911: //--------------------------------------------------------------------------- ! 1912: ! 1913: VOID NEAR FillComboBox( HINSTANCE hInstance, HWND hCtrlWnd, int nIDString, ! 1914: DWORD NEAR *npTable, WORD wTableLen, ! 1915: DWORD dwCurrentSetting ) ! 1916: { ! 1917: char szBuffer[ MAXLEN_TEMPSTR ] ; ! 1918: WORD wCount, wPosition ; ! 1919: ! 1920: for (wCount = 0; wCount < wTableLen; wCount++) ! 1921: { ! 1922: // load the string from the string resources and ! 1923: // add it to the combo box ! 1924: ! 1925: LoadString( hInstance, nIDString + wCount, szBuffer, sizeof( szBuffer ) ) ; ! 1926: wPosition = LOWORD( SendMessage( hCtrlWnd, CB_ADDSTRING, NULL, ! 1927: (LPARAM) (LPSTR) szBuffer ) ) ; ! 1928: ! 1929: // use item data to store the actual table value ! 1930: ! 1931: SendMessage( hCtrlWnd, CB_SETITEMDATA, (WPARAM) wPosition, ! 1932: (LPARAM) *(npTable + wCount) ) ; ! 1933: ! 1934: // if this is our current setting, select it ! 1935: ! 1936: if (*(npTable + wCount) == dwCurrentSetting) ! 1937: SendMessage( hCtrlWnd, CB_SETCURSEL, (WPARAM) wPosition, NULL ) ; ! 1938: } ! 1939: ! 1940: } // end of FillComboBox() ! 1941: ! 1942: //--------------------------------------------------------------------------- ! 1943: // BOOL NEAR SettingsDlgInit( HWND hDlg ) ! 1944: // ! 1945: // Description: ! 1946: // Puts current settings into dialog box (via CheckRadioButton() etc.) ! 1947: // ! 1948: // Parameters: ! 1949: // HWND hDlg ! 1950: // handle to dialog box ! 1951: // ! 1952: // Win-32 Porting Issues: ! 1953: // - Constants require DWORD arrays for baud rate table, etc. ! 1954: // - There is no "MAXCOM" function in Win-32. Number of COM ports ! 1955: // is assumed to be 4. ! 1956: // ! 1957: // History: Date Author Comment ! 1958: // 5/11/91 BryanW Wrote it. ! 1959: // 10/20/91 BryanW Dialog revision. ! 1960: // 10/24/91 BryanW Fixed bug with EscapeCommFunction(). ! 1961: // 6/15/92 BryanW Ported to Win-32. ! 1962: // ! 1963: //--------------------------------------------------------------------------- ! 1964: ! 1965: BOOL NEAR SettingsDlgInit( HWND hDlg ) ! 1966: { ! 1967: char szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ] ; ! 1968: NPTTYINFO npTTYInfo ; ! 1969: WORD wCount, wMaxCOM, wPosition ; ! 1970: ! 1971: if (NULL == (npTTYInfo = (NPTTYINFO) GET_PROP( hDlg, ATOM_TTYINFO ))) ! 1972: return ( FALSE ) ; ! 1973: ! 1974: #ifdef WIN32 ! 1975: wMaxCOM = 4 ; ! 1976: #else ! 1977: wMaxCOM = LOWORD( EscapeCommFunction( NULL, GETMAXCOM ) ) + 1 ; ! 1978: #endif ! 1979: ! 1980: // load the COM prefix from resources ! 1981: ! 1982: LoadString( GETHINST( hDlg ), IDS_COMPREFIX, szTemp, sizeof( szTemp ) ) ; ! 1983: ! 1984: // fill port combo box and make initial selection ! 1985: ! 1986: for (wCount = 0; wCount < wMaxCOM; wCount++) ! 1987: { ! 1988: wsprintf( szBuffer, "%s%d", (LPSTR) szTemp, wCount + 1 ) ; ! 1989: SendDlgItemMessage( hDlg, IDD_PORTCB, CB_ADDSTRING, NULL, ! 1990: (LPARAM) (LPSTR) szBuffer ) ; ! 1991: } ! 1992: SendDlgItemMessage( hDlg, IDD_PORTCB, CB_SETCURSEL, ! 1993: (WPARAM) (PORT( npTTYInfo ) - 1), NULL ) ; ! 1994: ! 1995: // disable COM port combo box if connection has already been ! 1996: // established (e.g. OpenComm() already successful) ! 1997: ! 1998: EnableWindow( GetDlgItem( hDlg, IDD_PORTCB ), !CONNECTED( npTTYInfo ) ) ; ! 1999: ! 2000: // fill baud combo box and make initial selection ! 2001: ! 2002: FillComboBox( GETHINST( hDlg ), GetDlgItem( hDlg, IDD_BAUDCB ), ! 2003: IDS_BAUD110, BaudTable, ! 2004: sizeof( BaudTable ) / sizeof( BaudTable[ 0 ] ), ! 2005: BAUDRATE( npTTYInfo ) ) ; ! 2006: ! 2007: // fill data bits combo box and make initial selection ! 2008: ! 2009: for (wCount = 5; wCount < 9; wCount++) ! 2010: { ! 2011: wsprintf( szBuffer, "%d", wCount ) ; ! 2012: wPosition = LOWORD( SendDlgItemMessage( hDlg, IDD_DATABITSCB, ! 2013: CB_ADDSTRING, NULL, ! 2014: (LPARAM) (LPSTR) szBuffer ) ) ; ! 2015: ! 2016: // if current selection, tell the combo box ! 2017: ! 2018: if (wCount == BYTESIZE( npTTYInfo )) ! 2019: SendDlgItemMessage( hDlg, IDD_DATABITSCB, CB_SETCURSEL, ! 2020: (WPARAM) wPosition, NULL ) ; ! 2021: } ! 2022: ! 2023: // fill parity combo box and make initial selection ! 2024: ! 2025: FillComboBox( GETHINST( hDlg ), GetDlgItem( hDlg, IDD_PARITYCB ), ! 2026: IDS_PARITYNONE, ParityTable, ! 2027: sizeof( ParityTable ) / sizeof( ParityTable[ 0 ] ), ! 2028: PARITY( npTTYInfo ) ) ; ! 2029: ! 2030: // fill stop bits combo box and make initial selection ! 2031: ! 2032: FillComboBox( GETHINST( hDlg ), GetDlgItem( hDlg, IDD_STOPBITSCB ), ! 2033: IDS_ONESTOPBIT, StopBitsTable, ! 2034: sizeof( StopBitsTable ) / sizeof ( StopBitsTable ), ! 2035: STOPBITS( npTTYInfo ) ) ; ! 2036: ! 2037: // initalize the flow control settings ! 2038: ! 2039: CheckDlgButton( hDlg, IDD_DTRDSR, ! 2040: (FLOWCTRL( npTTYInfo ) & FC_DTRDSR) > 0 ) ; ! 2041: CheckDlgButton( hDlg, IDD_RTSCTS, ! 2042: (FLOWCTRL( npTTYInfo ) & FC_RTSCTS) > 0 ) ; ! 2043: CheckDlgButton( hDlg, IDD_XONXOFF, ! 2044: (FLOWCTRL( npTTYInfo ) & FC_XONXOFF) > 0 ) ; ! 2045: ! 2046: // other TTY settings ! 2047: ! 2048: CheckDlgButton( hDlg, IDD_AUTOWRAP, AUTOWRAP( npTTYInfo ) ) ; ! 2049: CheckDlgButton( hDlg, IDD_NEWLINE, NEWLINE( npTTYInfo ) ) ; ! 2050: CheckDlgButton( hDlg, IDD_LOCALECHO, LOCALECHO( npTTYInfo ) ) ; ! 2051: ! 2052: // control options ! 2053: ! 2054: #ifdef WIN32 ! 2055: // "Use CN_RECEIVE" is not valid under Win-32 ! 2056: ! 2057: EnableWindow( GetDlgItem( hDlg, IDD_USECNRECEIVE ), FALSE ) ; ! 2058: #else ! 2059: CheckDlgButton( hDlg, IDD_USECNRECEIVE, USECNRECEIVE( npTTYInfo ) ) ; ! 2060: ! 2061: // disable Use CN_RECEIVE option if connection has already been ! 2062: // established (e.g. OpenComm() already successful) ! 2063: ! 2064: EnableWindow( GetDlgItem( hDlg, IDD_USECNRECEIVE ), ! 2065: !CONNECTED( npTTYInfo ) ) ; ! 2066: #endif ! 2067: ! 2068: CheckDlgButton( hDlg, IDD_DISPLAYERRORS, DISPLAYERRORS( npTTYInfo ) ) ; ! 2069: ! 2070: return ( TRUE ) ; ! 2071: ! 2072: } // end of SettingsDlgInit() ! 2073: ! 2074: //--------------------------------------------------------------------------- ! 2075: // BOOL NEAR SelectTTYFont( HWND hDlg ) ! 2076: // ! 2077: // Description: ! 2078: // Selects the current font for the TTY screen. ! 2079: // Uses the Common Dialog ChooseFont() API. ! 2080: // ! 2081: // Parameters: ! 2082: // HWND hDlg ! 2083: // handle to settings dialog ! 2084: // ! 2085: // History: Date Author Comment ! 2086: // 10/20/91 BryanW Wrote it. ! 2087: // ! 2088: //--------------------------------------------------------------------------- ! 2089: ! 2090: BOOL NEAR SelectTTYFont( HWND hDlg ) ! 2091: { ! 2092: CHOOSEFONT cfTTYFont ; ! 2093: NPTTYINFO npTTYInfo ; ! 2094: ! 2095: if (NULL == (npTTYInfo = (NPTTYINFO) GET_PROP( hDlg, ATOM_TTYINFO ))) ! 2096: return ( FALSE ) ; ! 2097: ! 2098: cfTTYFont.lStructSize = sizeof( CHOOSEFONT ) ; ! 2099: cfTTYFont.hwndOwner = hDlg ; ! 2100: cfTTYFont.hDC = NULL ; ! 2101: cfTTYFont.rgbColors = FGCOLOR( npTTYInfo ) ; ! 2102: cfTTYFont.lpLogFont = &LFTTYFONT( npTTYInfo ) ; ! 2103: cfTTYFont.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | ! 2104: CF_EFFECTS | CF_INITTOLOGFONTSTRUCT ; ! 2105: cfTTYFont.lCustData = NULL ; ! 2106: cfTTYFont.lpfnHook = NULL ; ! 2107: cfTTYFont.lpTemplateName = NULL ; ! 2108: cfTTYFont.hInstance = GETHINST( hDlg ) ; ! 2109: ! 2110: if (ChooseFont( &cfTTYFont )) ! 2111: { ! 2112: FGCOLOR( npTTYInfo ) = cfTTYFont.rgbColors ; ! 2113: ResetTTYScreen( GetParent( hDlg ), npTTYInfo ) ; ! 2114: } ! 2115: ! 2116: return ( TRUE ) ; ! 2117: ! 2118: } // end of SelectTTYFont() ! 2119: ! 2120: //--------------------------------------------------------------------------- ! 2121: // BOOL NEAR SettingsDlgTerm( HWND hDlg ) ! 2122: // ! 2123: // Description: ! 2124: // Puts dialog contents into TTY info structure. ! 2125: // ! 2126: // Parameters: ! 2127: // HWND hDlg ! 2128: // handle to settings dialog ! 2129: // ! 2130: // Win-32 Porting Issues: ! 2131: // - Baud rate requires DWORD values. ! 2132: // ! 2133: // History: Date Author Comment ! 2134: // 5/11/91 BryanW Wrote it. ! 2135: // 6/15/92 BryanW Ported to Win-32. ! 2136: // ! 2137: //--------------------------------------------------------------------------- ! 2138: ! 2139: BOOL NEAR SettingsDlgTerm( HWND hDlg ) ! 2140: { ! 2141: NPTTYINFO npTTYInfo ; ! 2142: WORD wSelection ; ! 2143: ! 2144: if (NULL == (npTTYInfo = (NPTTYINFO) GET_PROP( hDlg, ATOM_TTYINFO ))) ! 2145: return ( FALSE ) ; ! 2146: ! 2147: // get port selection ! 2148: ! 2149: PORT( npTTYInfo ) = ! 2150: LOBYTE( LOWORD( SendDlgItemMessage( hDlg, IDD_PORTCB, ! 2151: CB_GETCURSEL, ! 2152: NULL, NULL ) ) + 1 ) ; ! 2153: // get baud rate selection ! 2154: ! 2155: wSelection = ! 2156: LOWORD( SendDlgItemMessage( hDlg, IDD_BAUDCB, CB_GETCURSEL, ! 2157: NULL, NULL ) ) ; ! 2158: #ifdef WIN32 ! 2159: BAUDRATE( npTTYInfo ) = ! 2160: SendDlgItemMessage( hDlg, IDD_BAUDCB, CB_GETITEMDATA, ! 2161: (WPARAM) wSelection, NULL ) ; ! 2162: #else ! 2163: BAUDRATE( npTTYInfo ) = ! 2164: LOWORD( SendDlgItemMessage( hDlg, IDD_BAUDCB, CB_GETITEMDATA, ! 2165: (WPARAM) wSelection, NULL ) ) ; ! 2166: #endif ! 2167: ! 2168: // get data bits selection ! 2169: ! 2170: BYTESIZE( npTTYInfo ) = ! 2171: LOBYTE( LOWORD( SendDlgItemMessage( hDlg, IDD_DATABITSCB, ! 2172: CB_GETCURSEL, ! 2173: NULL, NULL ) ) + 5 ) ; ! 2174: ! 2175: // get parity selection ! 2176: ! 2177: wSelection = ! 2178: LOWORD( SendDlgItemMessage( hDlg, IDD_PARITYCB, CB_GETCURSEL, ! 2179: NULL, NULL ) ) ; ! 2180: PARITY( npTTYInfo ) = ! 2181: LOBYTE( LOWORD( SendDlgItemMessage( hDlg, IDD_PARITYCB, ! 2182: CB_GETITEMDATA, ! 2183: (WPARAM) wSelection, ! 2184: NULL ) ) ) ; ! 2185: ! 2186: // get stop bits selection ! 2187: ! 2188: wSelection = ! 2189: LOWORD( SendDlgItemMessage( hDlg, IDD_STOPBITSCB, CB_GETCURSEL, ! 2190: NULL, NULL ) ) ; ! 2191: STOPBITS( npTTYInfo ) = ! 2192: LOBYTE( LOWORD( SendDlgItemMessage( hDlg, IDD_STOPBITSCB, ! 2193: CB_GETITEMDATA, ! 2194: (WPARAM) wSelection, NULL ) ) ) ; ! 2195: ! 2196: // get flow control settings ! 2197: ! 2198: FLOWCTRL( npTTYInfo ) = 0 ; ! 2199: if (IsDlgButtonChecked( hDlg, IDD_DTRDSR )) ! 2200: FLOWCTRL( npTTYInfo ) |= FC_DTRDSR ; ! 2201: if (IsDlgButtonChecked( hDlg, IDD_RTSCTS )) ! 2202: FLOWCTRL( npTTYInfo ) |= FC_RTSCTS ; ! 2203: if (IsDlgButtonChecked( hDlg, IDD_XONXOFF )) ! 2204: FLOWCTRL( npTTYInfo ) |= FC_XONXOFF ; ! 2205: ! 2206: // get other various settings ! 2207: ! 2208: AUTOWRAP( npTTYInfo ) = IsDlgButtonChecked( hDlg, IDD_AUTOWRAP ) ; ! 2209: NEWLINE( npTTYInfo ) = IsDlgButtonChecked( hDlg, IDD_NEWLINE ) ; ! 2210: LOCALECHO( npTTYInfo ) = IsDlgButtonChecked( hDlg, IDD_LOCALECHO ) ; ! 2211: ! 2212: // control options ! 2213: ! 2214: USECNRECEIVE( npTTYInfo ) = IsDlgButtonChecked( hDlg, IDD_USECNRECEIVE ) ; ! 2215: DISPLAYERRORS( npTTYInfo ) = IsDlgButtonChecked( hDlg, IDD_DISPLAYERRORS ) ; ! 2216: ! 2217: return ( TRUE ) ; ! 2218: ! 2219: } // end of SettingsDlgTerm() ! 2220: ! 2221: //--------------------------------------------------------------------------- ! 2222: // BOOL FAR PASCAL SettingsDlgProc( HWND hDlg, UINT uMsg, ! 2223: // WPARAM wParam, LPARAM lParam ) ! 2224: // ! 2225: // Description: ! 2226: // This handles all of the user preference settings for ! 2227: // the TTY. ! 2228: // ! 2229: // Parameters: ! 2230: // same as all dialog procedures ! 2231: // ! 2232: // Win-32 Porting Issues: ! 2233: // - npTTYInfo is a DWORD in Win-32. ! 2234: // ! 2235: // History: Date Author Comment ! 2236: // 5/10/91 BryanW Wrote it. ! 2237: // 10/20/91 BryanW Now uses window properties to ! 2238: // store TTYInfo handle. Also added ! 2239: // font selection. ! 2240: // 6/15/92 BryanW Ported to Win-32. ! 2241: // ! 2242: //--------------------------------------------------------------------------- ! 2243: ! 2244: BOOL FAR PASCAL SettingsDlgProc( HWND hDlg, UINT uMsg, ! 2245: WPARAM wParam, LPARAM lParam ) ! 2246: { ! 2247: switch (uMsg) ! 2248: { ! 2249: case WM_INITDIALOG: ! 2250: { ! 2251: NPTTYINFO npTTYInfo ; ! 2252: ! 2253: // get & save pointer to TTY info structure ! 2254: ! 2255: #ifdef WIN32 ! 2256: npTTYInfo = (NPTTYINFO) lParam ; ! 2257: #else ! 2258: npTTYInfo = (NPTTYINFO) LOWORD( lParam ) ; ! 2259: #endif ! 2260: ! 2261: SET_PROP( hDlg, ATOM_TTYINFO, (HANDLE) npTTYInfo ) ; ! 2262: ! 2263: return ( SettingsDlgInit( hDlg ) ) ; ! 2264: } ! 2265: ! 2266: case WM_COMMAND: ! 2267: switch ( LOWORD( wParam )) ! 2268: { ! 2269: case IDD_FONT: ! 2270: return ( SelectTTYFont( hDlg ) ) ; ! 2271: ! 2272: case IDD_OK: ! 2273: // Copy stuff into structure ! 2274: SettingsDlgTerm( hDlg ) ; ! 2275: EndDialog( hDlg, TRUE ) ; ! 2276: return ( TRUE ) ; ! 2277: ! 2278: case IDD_CANCEL: ! 2279: // Just end ! 2280: EndDialog( hDlg, TRUE ) ; ! 2281: return ( TRUE ) ; ! 2282: } ! 2283: break; ! 2284: ! 2285: case WM_DESTROY: ! 2286: REMOVE_PROP( hDlg, ATOM_TTYINFO ) ; ! 2287: break ; ! 2288: } ! 2289: return ( FALSE ) ; ! 2290: ! 2291: } // end of SettingsDlgProc() ! 2292: ! 2293: #ifdef WIN32 ! 2294: ! 2295: //************************************************************************ ! 2296: // DWORD FAR PASCAL CommWatchProc( LPSTR lpData ) ! 2297: // ! 2298: // Description: ! 2299: // A secondary thread that will watch for COMM events. ! 2300: // ! 2301: // Parameters: ! 2302: // LPSTR lpData ! 2303: // 32-bit pointer argument ! 2304: // ! 2305: // Win-32 Porting Issues: ! 2306: // - Added this thread to watch the communications device and ! 2307: // post notifications to the associated window. ! 2308: // ! 2309: // History: Date Author Comment ! 2310: // 12/31/91 BryanW Wrote it. ! 2311: // 6/12/92 BryanW CommWaitEvent() now uses ! 2312: // an overlapped structure. ! 2313: // ! 2314: //************************************************************************ ! 2315: ! 2316: DWORD FAR PASCAL CommWatchProc( LPSTR lpData ) ! 2317: { ! 2318: DWORD cbTransfer ; ! 2319: DWORD dwEvtMask ; ! 2320: NPTTYINFO npTTYInfo = (NPTTYINFO) lpData ; ! 2321: OVERLAPPED os ; ! 2322: ! 2323: memset( &os, 0, sizeof( OVERLAPPED ) ) ; ! 2324: ! 2325: // create I/O event used for overlapped read ! 2326: ! 2327: os.hEvent = CreateEvent( NULL, // no security ! 2328: TRUE, // explicit reset req ! 2329: FALSE, // initial event reset ! 2330: NULL ) ; // no name ! 2331: if (os.hEvent == NULL) ! 2332: { ! 2333: MessageBox( NULL, "Failed to create event for thread!", "TTY Error!", ! 2334: MB_ICONEXCLAMATION | MB_OK ) ; ! 2335: return ( FALSE ) ; ! 2336: } ! 2337: ! 2338: if (!SetCommMask( COMDEV( npTTYInfo ), EV_RXCHAR )) ! 2339: return ( FALSE ) ; ! 2340: ! 2341: while ( CONNECTED( npTTYInfo ) ) ! 2342: { ! 2343: dwEvtMask = NULL ; ! 2344: ! 2345: if (!WaitCommEvent( COMDEV( npTTYInfo ), &dwEvtMask, &os )) ! 2346: { ! 2347: if (ERROR_IO_PENDING == GetLastError()) ! 2348: { ! 2349: GetOverlappedResult( COMDEV( npTTYInfo ), &os, &cbTransfer, TRUE ) ; ! 2350: os.Offset += cbTransfer ; ! 2351: } ! 2352: } ! 2353: ! 2354: if ((dwEvtMask & EV_RXCHAR) == EV_RXCHAR) ! 2355: { ! 2356: // wait for "posted notification" flag to clear ! 2357: ! 2358: WaitForSingleObject( POSTEVENT( npTTYInfo ), 0xFFFFFFFF ) ; ! 2359: ! 2360: // reset event ! 2361: ! 2362: ResetEvent( POSTEVENT( npTTYInfo ) ) ; ! 2363: ! 2364: // last message was processed, O.K. to post ! 2365: ! 2366: PostMessage( TERMWND( npTTYInfo ), WM_COMMNOTIFY, ! 2367: (WPARAM) COMDEV( npTTYInfo ), ! 2368: MAKELONG( CN_EVENT, 0 ) ) ; ! 2369: } ! 2370: } ! 2371: ! 2372: // get rid of event handle ! 2373: ! 2374: CloseHandle( os.hEvent ) ; ! 2375: ! 2376: // clear information in structure (kind of a "we're done flag") ! 2377: ! 2378: THREADID( npTTYInfo ) = NULL ; ! 2379: HTHREAD( npTTYInfo ) = NULL ; ! 2380: ! 2381: return( TRUE ) ; ! 2382: ! 2383: } // end of CommWatchProc() ! 2384: ! 2385: #endif ! 2386: ! 2387: //--------------------------------------------------------------------------- ! 2388: // End of File: tty.c ! 2389: //---------------------------------------------------------------------------
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.