📄 ttychic.c
字号:
//---------------------------------------------------------------------------
// LRESULT NEAR CreateTTYInfo( HWND hWnd )
//
// Description:
// Creates the tty information structure and sets
// menu option availability. Returns -1 if unsuccessful.
//
// Parameters:
// HWND hWnd
// Handle to main window.
//
//---------------------------------------------------------------------------
LRESULT NEAR CreateTTYInfo( HWND hWnd )
{
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo =
(PTTYINFO) LocalAlloc( LPTR, sizeof( TTYINFO ) )))
return ( (LRESULT) -1 ) ;
// initialize TTY info structure
COMDEV( pTTYInfo ) = 0 ;
CONNECTED( pTTYInfo ) = FALSE ;
CURSORSTATE( pTTYInfo ) = CS_HIDE ;
LOCALECHO( pTTYInfo ) = TRUE ;
AUTOWRAP( pTTYInfo ) = TRUE ;
PORT( pTTYInfo ) = 1 ;
BAUDRATE( pTTYInfo ) = CBR_9600 ;
BYTESIZE( pTTYInfo ) = 8 ;
FLOWCTRL( pTTYInfo ) = FC_RTSCTS ;
PARITY( pTTYInfo ) = NOPARITY ;
STOPBITS( pTTYInfo ) = ONESTOPBIT ;
XONXOFF( pTTYInfo ) = FALSE ;
XSIZE( pTTYInfo ) = 0 ;
YSIZE( pTTYInfo ) = 0 ;
XSCROLL( pTTYInfo ) = 0 ;
YSCROLL( pTTYInfo ) = 0 ;
XOFFSET( pTTYInfo ) = 0 ;
YOFFSET( pTTYInfo ) = 0 ;
COLUMN( pTTYInfo ) = 0 ;
ROW( pTTYInfo ) = 0 ;
HTTYFONT( pTTYInfo ) = NULL ;
FGCOLOR( pTTYInfo ) = RGB( 0, 0, 0 ) ;
USECNRECEIVE( pTTYInfo ) = TRUE ;
DISPLAYERRORS( pTTYInfo ) = TRUE ;
NEWLINE(pTTYInfo) = TRUE ;
// clear screen space
memset( SCREEN( pTTYInfo ), ' ', MAXROWS * MAXCOLS ) ;
// setup default font information
LFTTYFONT( pTTYInfo ).lfHeight = 12 ;
LFTTYFONT( pTTYInfo ).lfWidth = 0 ;
LFTTYFONT( pTTYInfo ).lfEscapement = 0 ;
LFTTYFONT( pTTYInfo ).lfOrientation = 0 ;
LFTTYFONT( pTTYInfo ).lfWeight = 0 ;
LFTTYFONT( pTTYInfo ).lfItalic = 0 ;
LFTTYFONT( pTTYInfo ).lfUnderline = 0 ;
LFTTYFONT( pTTYInfo ).lfStrikeOut = 0 ;
LFTTYFONT( pTTYInfo ).lfCharSet = OEM_CHARSET ;
LFTTYFONT( pTTYInfo ).lfOutPrecision = OUT_DEFAULT_PRECIS ;
LFTTYFONT( pTTYInfo ).lfClipPrecision = CLIP_DEFAULT_PRECIS ;
LFTTYFONT( pTTYInfo ).lfQuality = DEFAULT_QUALITY ;
LFTTYFONT( pTTYInfo ).lfPitchAndFamily = FIXED_PITCH | FF_MODERN ;
LFTTYFONT( pTTYInfo ).lfFaceName[0] = 0;
// set TTYInfo handle before any further message processing.
SetWindowLong( hWnd, GWL_PTTYINFO, (WPARAM) pTTYInfo ) ;
// reset the character information, etc.
ResetTTYScreen( hWnd, pTTYInfo ) ;
return ( (LRESULT) TRUE ) ;
} // end of CreateTTYInfo()
//---------------------------------------------------------------------------
// BOOL NEAR DestroyTTYInfo( HWND hWnd )
//
// Description:
// Destroys block associated with TTY window handle.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
//---------------------------------------------------------------------------
BOOL NEAR DestroyTTYInfo( HWND hWnd )
{
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
DeleteObject( HTTYFONT( pTTYInfo ) ) ;
LocalFree( pTTYInfo ) ;
return ( TRUE ) ;
} // end of DestroyTTYInfo()
//---------------------------------------------------------------------------
// BOOL NEAR ResetTTYScreen( HWND hWnd, PTTYINFO pTTYInfo )
//
// Description:
// Resets the TTY character information and causes the
// screen to resize to update the scroll information.
//
// Parameters:
// PTTYINFO pTTYInfo
// pointer to TTY info structure
//
//---------------------------------------------------------------------------
BOOL NEAR ResetTTYScreen( HWND hWnd, PTTYINFO pTTYInfo )
{
HDC hDC ;
TEXTMETRIC tm ;
RECT rcWindow ;
if (NULL == pTTYInfo)
return ( FALSE ) ;
if (NULL != HTTYFONT( pTTYInfo ))
DeleteObject( HTTYFONT( pTTYInfo ) ) ;
HTTYFONT( pTTYInfo ) = CreateFontIndirect( &LFTTYFONT( pTTYInfo ) ) ;
hDC = GetDC( hWnd ) ;
SelectObject( hDC, HTTYFONT( pTTYInfo ) ) ;
GetTextMetrics( hDC, &tm ) ;
ReleaseDC( hWnd, hDC ) ;
XCHAR( pTTYInfo ) = tm.tmAveCharWidth ;
YCHAR( pTTYInfo ) = tm.tmHeight + tm.tmExternalLeading ;
// a slimy hack to force the scroll position, region to
// be recalculated based on the new character sizes
GetWindowRect( hWnd, &rcWindow ) ;
SendMessage( hWnd, WM_SIZE, SIZENORMAL,
(LPARAM) MAKELONG( rcWindow.right - rcWindow.left,
rcWindow.bottom - rcWindow.top ) ) ;
return ( TRUE ) ;
} // end of ResetTTYScreen()
//---------------------------------------------------------------------------
// BOOL NEAR PaintTTY( HWND hWnd )
//
// Description:
// Paints the rectangle determined by the paint struct of
// the DC.
//
// Parameters:
// HWND hWnd
// handle to TTY window (as always)
//
//---------------------------------------------------------------------------
BOOL NEAR PaintTTY( HWND hWnd )
{
int nRow, nCol, nEndRow, nEndCol, nCount, nHorzPos, nVertPos ;
HDC hDC ;
HFONT hOldFont ;
PTTYINFO pTTYInfo ;
PAINTSTRUCT ps ;
RECT rect ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
hDC = BeginPaint( hWnd, &ps ) ;
hOldFont = SelectObject( hDC, HTTYFONT( pTTYInfo ) ) ;
SetTextColor( hDC, FGCOLOR( pTTYInfo ) ) ;
SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) ) ;
rect = ps.rcPaint ;
nRow =
min( MAXROWS - 1,
max( 0, (rect.top + YOFFSET( pTTYInfo )) / YCHAR( pTTYInfo ) ) ) ;
nEndRow =
min( MAXROWS - 1,
((rect.bottom + YOFFSET( pTTYInfo ) - 1) / YCHAR( pTTYInfo ) ) ) ;
nCol =
min( MAXCOLS - 1,
max( 0, (rect.left + XOFFSET( pTTYInfo )) / XCHAR( pTTYInfo ) ) ) ;
nEndCol =
min( MAXCOLS - 1,
((rect.right + XOFFSET( pTTYInfo ) - 1) / XCHAR( pTTYInfo ) ) ) ;
nCount = nEndCol - nCol + 1 ;
for (; nRow <= nEndRow; nRow++)
{
nVertPos = (nRow * YCHAR( pTTYInfo )) - YOFFSET( pTTYInfo ) ;
nHorzPos = (nCol * XCHAR( pTTYInfo )) - XOFFSET( pTTYInfo ) ;
rect.top = nVertPos ;
rect.bottom = nVertPos + YCHAR( pTTYInfo ) ;
rect.left = nHorzPos ;
rect.right = nHorzPos + XCHAR( pTTYInfo ) * nCount ;
SetBkMode( hDC, OPAQUE ) ;
ExtTextOut( hDC, nHorzPos, nVertPos, ETO_OPAQUE | ETO_CLIPPED, &rect,
(LPSTR)( SCREEN( pTTYInfo ) + nRow * MAXCOLS + nCol ),
nCount, NULL ) ;
}
SelectObject( hDC, hOldFont ) ;
EndPaint( hWnd, &ps ) ;
MoveTTYCursor( hWnd ) ;
return ( TRUE ) ;
} // end of PaintTTY()
//---------------------------------------------------------------------------
// BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize )
//
// Description:
// Sizes TTY and sets up scrolling regions.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
// WORD wVertSize
// new vertical size
//
// WORD wHorzSize
// new horizontal size
//
//---------------------------------------------------------------------------
BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize )
{
int nScrollAmt ;
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
YSIZE( pTTYInfo ) = (int) wVertSize ;
YSCROLL( pTTYInfo ) = max( 0, (MAXROWS * YCHAR( pTTYInfo )) -
YSIZE( pTTYInfo ) ) ;
nScrollAmt = min( YSCROLL( pTTYInfo ), YOFFSET( pTTYInfo ) ) -
YOFFSET( pTTYInfo ) ;
ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ;
YOFFSET( pTTYInfo ) = YOFFSET( pTTYInfo ) + nScrollAmt ;
SetScrollPos( hWnd, SB_VERT, YOFFSET( pTTYInfo ), FALSE ) ;
SetScrollRange( hWnd, SB_VERT, 0, YSCROLL( pTTYInfo ), TRUE ) ;
XSIZE( pTTYInfo ) = (int) wHorzSize ;
XSCROLL( pTTYInfo ) = max( 0, (MAXCOLS * XCHAR( pTTYInfo )) -
XSIZE( pTTYInfo ) ) ;
nScrollAmt = min( XSCROLL( pTTYInfo ), XOFFSET( pTTYInfo )) -
XOFFSET( pTTYInfo ) ;
ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ;
XOFFSET( pTTYInfo ) = XOFFSET( pTTYInfo ) + nScrollAmt ;
SetScrollPos( hWnd, SB_HORZ, XOFFSET( pTTYInfo ), FALSE ) ;
SetScrollRange( hWnd, SB_HORZ, 0, XSCROLL( pTTYInfo ), TRUE ) ;
InvalidateRect( hWnd, NULL, TRUE ) ;
return ( TRUE ) ;
} // end of SizeTTY()
//---------------------------------------------------------------------------
// BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
//
// Description:
// Scrolls TTY window vertically.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
// WORD wScrollCmd
// type of scrolling we're doing
//
// WORD wScrollPos
// scroll position
//
//---------------------------------------------------------------------------
BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
{
int nScrollAmt ;
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
switch (wScrollCmd)
{
case SB_TOP:
nScrollAmt = -YOFFSET( pTTYInfo ) ;
break ;
case SB_BOTTOM:
nScrollAmt = YSCROLL( pTTYInfo ) - YOFFSET( pTTYInfo ) ;
break ;
case SB_PAGEUP:
nScrollAmt = -YSIZE( pTTYInfo ) ;
break ;
case SB_PAGEDOWN:
nScrollAmt = YSIZE( pTTYInfo ) ;
break ;
case SB_LINEUP:
nScrollAmt = -YCHAR( pTTYInfo ) ;
break ;
case SB_LINEDOWN:
nScrollAmt = YCHAR( pTTYInfo ) ;
break ;
case SB_THUMBPOSITION:
nScrollAmt = wScrollPos - YOFFSET( pTTYInfo ) ;
break ;
default:
return ( FALSE ) ;
}
if ((YOFFSET( pTTYInfo ) + nScrollAmt) > YSCROLL( pTTYInfo ))
nScrollAmt = YSCROLL( pTTYInfo ) - YOFFSET( pTTYInfo ) ;
if ((YOFFSET( pTTYInfo ) + nScrollAmt) < 0)
nScrollAmt = -YOFFSET( pTTYInfo ) ;
ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ;
YOFFSET( pTTYInfo ) = YOFFSET( pTTYInfo ) + nScrollAmt ;
SetScrollPos( hWnd, SB_VERT, YOFFSET( pTTYInfo ), TRUE ) ;
return ( TRUE ) ;
} // end of ScrollTTYVert()
//---------------------------------------------------------------------------
// BOOL NEAR ScrollTTYHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
//
// Description:
// Scrolls TTY window horizontally.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
// WORD wScrollCmd
// type of scrolling we're doing
//
// WORD wScrollPos
// scroll position
//
//---------------------------------------------------------------------------
BOOL NEAR ScrollTTYHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
{
int nScrollAmt ;
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
switch (wScrollCmd)
{
case SB_TOP:
nScrollAmt = -XOFFSET( pTTYInfo ) ;
break ;
case SB_BOTTOM:
nScrollAmt = XSCROLL( pTTYInfo ) - XOFFSET( pTTYInfo ) ;
break ;
case SB_PAGEUP:
nScrollAmt = -XSIZE( pTTYInfo ) ;
break ;
case SB_PAGEDOWN:
nScrollAmt = XSIZE( pTTYInfo ) ;
break ;
case SB_LINEUP:
nScrollAmt = -XCHAR( pTTYInfo ) ;
break ;
case SB_LINEDOWN:
nScrollAmt = XCHAR( pTTYInfo ) ;
break ;
case SB_THUMBPOSITION:
nScrollAmt = wScrollPos - XOFFSET( pTTYInfo ) ;
break ;
default:
return ( FALSE ) ;
}
if ((XOFFSET( pTTYInfo ) + nScrollAmt) > XSCROLL( pTTYInfo ))
nScrollAmt = XSCROLL( pTTYInfo ) - XOFFSET( pTTYInfo ) ;
if ((XOFFSET( pTTYInfo ) + nScrollAmt) < 0)
nScrollAmt = -XOFFSET( pTTYInfo ) ;
ScrollWindow( hWnd, -nScrollAmt, 0, NULL, NULL ) ;
XOFFSET( pTTYInfo ) = XOFFSET( pTTYInfo ) + nScrollAmt ;
SetScrollPos( hWnd, SB_HORZ, XOFFSET( pTTYInfo ), TRUE ) ;
return ( TRUE ) ;
} // end of ScrollTTYHorz()
//---------------------------------------------------------------------------
// BOOL NEAR SetTTYFocus( HWND hWnd )
//
// Description:
// Sets the focus to the TTY window also creates caret.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -