📄 ttychic.c
字号:
// Parameters:
// HWND hWnd
// handle to TTY window
//
//---------------------------------------------------------------------------
BOOL NEAR SetTTYFocus( HWND hWnd )
{
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
if (CURSORSTATE( pTTYInfo ) != CS_SHOW)
{
CreateCaret( hWnd, NULL, XCHAR( pTTYInfo ), YCHAR( pTTYInfo ) ) ;
ShowCaret( hWnd ) ;
CURSORSTATE( pTTYInfo ) = CS_SHOW ;
}
MoveTTYCursor( hWnd ) ;
return ( TRUE ) ;
} // end of SetTTYFocus()
//---------------------------------------------------------------------------
// BOOL NEAR KillTTYFocus( HWND hWnd )
//
// Description:
// Kills TTY focus and destroys the caret.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
//---------------------------------------------------------------------------
BOOL NEAR KillTTYFocus( HWND hWnd )
{
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
if (CURSORSTATE( pTTYInfo ) != CS_HIDE)
{
HideCaret( hWnd ) ;
DestroyCaret() ;
CURSORSTATE( pTTYInfo ) = CS_HIDE ;
}
return ( TRUE ) ;
} // end of KillTTYFocus()
//---------------------------------------------------------------------------
// BOOL NEAR MoveTTYCursor( HWND hWnd )
//
// Description:
// Moves caret to current position.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
//---------------------------------------------------------------------------
BOOL NEAR MoveTTYCursor( HWND hWnd )
{
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
if (CURSORSTATE( pTTYInfo ) & CS_SHOW)
SetCaretPos( (COLUMN( pTTYInfo ) * XCHAR( pTTYInfo )) -
XOFFSET( pTTYInfo ),
(ROW( pTTYInfo ) * YCHAR( pTTYInfo )) -
YOFFSET( pTTYInfo ) ) ;
return ( TRUE ) ;
} // end of MoveTTYCursor()
//---------------------------------------------------------------------------
// BOOL WriteTTYBlock( HWND hWnd, LPSTR lpBlock, int nLength )
//
// Description:
// Writes block to TTY screen. Nothing fancy - just
// straight TTY.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
// LPSTR lpBlock
// far pointer to block of data
//
// int nLength
// length of block
//
//---------------------------------------------------------------------------
BOOL WriteTTYBlock( HWND hWnd, LPSTR lpBlock, int nLength )
{
int i ;
PTTYINFO pTTYInfo ;
RECT rect ;
if (NULL == (pTTYInfo = (PTTYINFO) GetWindowLong( hWnd, GWL_PTTYINFO )))
return ( FALSE ) ;
for (i = 0 ; i < nLength; i++)
{
switch (lpBlock[ i ])
{
case ASCII_BEL:
// Bell
MessageBeep( 0 ) ;
break ;
case ASCII_BS:
// Backspace
if (COLUMN( pTTYInfo ) > 0)
COLUMN( pTTYInfo ) -- ;
MoveTTYCursor( hWnd ) ;
break ;
case ASCII_CR:
// Carriage return
COLUMN( pTTYInfo ) = 0 ;
MoveTTYCursor( hWnd ) ;
if (!NEWLINE( pTTYInfo ))
break;
// fall through
case ASCII_LF:
// Line feed
if (ROW( pTTYInfo )++ == MAXROWS - 1)
{
memmove( (LPSTR) (SCREEN( pTTYInfo )),
(LPSTR) (SCREEN( pTTYInfo ) + MAXCOLS),
(MAXROWS - 1) * MAXCOLS ) ;
memset( (LPSTR) (SCREEN( pTTYInfo ) + (MAXROWS - 1) * MAXCOLS),
' ', MAXCOLS ) ;
InvalidateRect( hWnd, NULL, FALSE ) ;
ROW( pTTYInfo )-- ;
}
MoveTTYCursor( hWnd ) ;
break ;
default:
*(SCREEN( pTTYInfo ) + ROW( pTTYInfo ) * MAXCOLS +
COLUMN( pTTYInfo )) = lpBlock[ i ] ;
rect.left = (COLUMN( pTTYInfo ) * XCHAR( pTTYInfo )) -
XOFFSET( pTTYInfo ) ;
rect.right = rect.left + XCHAR( pTTYInfo ) ;
rect.top = (ROW( pTTYInfo ) * YCHAR( pTTYInfo )) -
YOFFSET( pTTYInfo ) ;
rect.bottom = rect.top + YCHAR( pTTYInfo ) ;
InvalidateRect( hWnd, &rect, FALSE ) ;
// Line wrap
if (COLUMN( pTTYInfo ) < MAXCOLS - 1)
COLUMN( pTTYInfo )++ ;
else if (AUTOWRAP( pTTYInfo ))
WriteTTYBlock( hWnd, "\r\n", 2 ) ;
break;
}
}
return ( TRUE ) ;
} // end of WriteTTYBlock()
//---------------------------------------------------------------------------
// VOID GoModalDialogBoxParam( HINSTANCE hInstance,
// LPCSTR lpszTemplate, HWND hWnd,
// DLGPROC lpDlgProc, LPARAM lParam )
//
// Description:
// It is a simple utility function that simply performs the
// MPI and invokes the dialog box with a DWORD paramter.
//
// Parameters:
// similar to that of DialogBoxParam() with the exception
// that the lpDlgProc is not a procedure instance
//
//---------------------------------------------------------------------------
VOID GoModalDialogBoxParam( HINSTANCE hInstance, LPCSTR lpszTemplate,
HWND hWnd, DLGPROC lpDlgProc, LPARAM lParam )
{
DLGPROC lpProcInstance ;
lpProcInstance = (DLGPROC) MakeProcInstance( (FARPROC) lpDlgProc,
hInstance ) ;
DialogBoxParam( hInstance, lpszTemplate, hWnd, lpProcInstance, lParam ) ;
FreeProcInstance( (FARPROC) lpProcInstance ) ;
} // end of GoModalDialogBoxParam()
//---------------------------------------------------------------------------
// BOOL FAR PASCAL AboutDlgProc( HWND hDlg, UINT uMsg,
// WPARAM wParam, LPARAM lParam )
//
// Description:
// Simulates the Windows System Dialog Box.
//
// Parameters:
// Same as standard dialog procedures.
//
//---------------------------------------------------------------------------
BOOL FAR PASCAL AboutDlgProc( HWND hDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam )
{
switch (uMsg)
{
case WM_INITDIALOG:
{
int idModeString ;
char szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ] ;
DWORD dwFreeMemory;
WORD wRevision, wVersion ;
#ifdef ABOUTDLG_USEBITMAP
// if we are using the bitmap, hide the icon
ShowWindow( GetDlgItem( hDlg, IDD_ABOUTICON ), SW_HIDE ) ;
#endif
// sets up the version number for Windows
wVersion = LOWORD( GetVersion() ) ;
switch (HIBYTE( wVersion ))
{
case 10:
wRevision = 1 ;
break ;
default:
wRevision = 0 ;
break;
}
wVersion &= 0xFF ;
GetDlgItemText( hDlg, IDD_TITLELINE, szTemp, sizeof( szTemp ) ) ;
wsprintf( szBuffer, szTemp, wVersion, wRevision ) ;
SetDlgItemText( hDlg, IDD_TITLELINE, szBuffer ) ;
// sets up version number for TTY
GetDlgItemText( hDlg, IDD_VERSION, szTemp, sizeof( szTemp ) ) ;
wsprintf( szBuffer, szTemp, VER_MAJOR, VER_MINOR, VER_BUILD ) ;
SetDlgItemText( hDlg, IDD_VERSION, (LPSTR) szBuffer ) ;
// get by-line
LoadString( GETHINST( hDlg ), IDS_BYLINE, szBuffer,
sizeof( szBuffer ) ) ;
SetDlgItemText( hDlg, IDD_BYLINE, szBuffer ) ;
LoadString( GETHINST( hDlg ), idModeString, szBuffer,
sizeof( szBuffer ) ) ;
SetDlgItemText( hDlg, IDD_WINDOWSMODE, szBuffer ) ;
// get free memory information
dwFreeMemory = GetFreeSpace( 0 ) / 1024L ;
GetDlgItemText( hDlg, IDD_FREEMEM, szTemp, sizeof( szTemp ) ) ;
wsprintf( szBuffer, szTemp, dwFreeMemory ) ;
SetDlgItemText( hDlg, IDD_FREEMEM, (LPSTR) szBuffer ) ;
}
return ( TRUE ) ;
#ifdef ABOUTDLG_USEBITMAP
// used to paint the bitmap
case WM_PAINT:
{
HBITMAP hBitMap ;
HDC hDC, hMemDC ;
PAINTSTRUCT ps ;
// load bitmap and display it
hDC = BeginPaint( hDlg, &ps ) ;
if (NULL != (hMemDC = CreateCompatibleDC( hDC )))
{
hBitMap = LoadBitmap( GETHINST( hDlg ),
MAKEINTRESOURCE( TTYBITMAP ) ) ;
hBitMap = SelectObject( hMemDC, hBitMap ) ;
BitBlt( hDC, 10, 10, 64, 64, hMemDC, 0, 0, SRCCOPY ) ;
DeleteObject( SelectObject( hMemDC, hBitMap ) ) ;
DeleteDC( hMemDC ) ;
}
EndPaint( hDlg, &ps ) ;
}
break ;
#endif
case WM_COMMAND:
if ((WORD) wParam == IDD_OK)
{
EndDialog( hDlg, TRUE ) ;
return ( TRUE ) ;
}
break;
}
return ( FALSE ) ;
} // end of AboutDlgProc()
//---------------------------------------------------------------------------
// VOID FillComboBox( HINSTANCE hInstance, HWND hCtrlWnd, int nIDString,
// DWORD *npTable, WORD wTableLen,
// WORD wCurrentSetting )
//
// Description:
// Fills the given combo box with strings from the resource
// table starting at nIDString. Associated items are
// added from given table. The combo box is notified of
// the current setting.
//
// Parameters:
// HINSTANCE hInstance
// handle to application instance
//
// HWND hCtrlWnd
// handle to combo box control
//
// int nIDString
// first resource string id
//
// WORD *npTable
// near point to table of associated values
//
// WORD wTableLen
// length of table
//
// WORD wCurrentSetting
// current setting (for combo box selection)
//
//---------------------------------------------------------------------------
VOID FillComboBox( HINSTANCE hInstance, HWND hCtrlWnd, int nIDString,
DWORD *npTable, WORD wTableLen,
WORD wCurrentSetting )
{
char szBuffer[ MAXLEN_TEMPSTR ] ;
WORD wCount, wPosition ;
for (wCount = 0; wCount < wTableLen; wCount++)
{
// load the string from the string resources and
// add it to the combo box
LoadString( hInstance, nIDString + wCount, szBuffer, sizeof( szBuffer ) ) ;
wPosition = LOWORD( SendMessage( hCtrlWnd, CB_ADDSTRING, 0,
(LPARAM) (LPSTR) szBuffer ) ) ;
// use item data to store the actual table value
SendMessage( hCtrlWnd, CB_SETITEMDATA, (WPARAM) wPosition,
(LPARAM) (LONG) *(npTable + wCount) ) ;
// if this is our current setting, select it
if (*(npTable + wCount) == wCurrentSetting)
SendMessage( hCtrlWnd, CB_SETCURSEL, (WPARAM) wPosition, 0 ) ;
}
} // end of FillComboBox()
//---------------------------------------------------------------------------
// BOOL SelectTTYFont( HWND hDlg )
//
// Description:
// Selects the current font for the TTY screen.
// Uses the Common Dialog ChooseFont() API.
//
// Parameters:
// HWND hDlg
// handle to settings dialog
//
//---------------------------------------------------------------------------
BOOL SelectTTYFont( HWND hDlg )
{
CHOOSEFONT cfTTYFont ;
PTTYINFO pTTYInfo ;
if (NULL == (pTTYInfo = (PTTYINFO) GET_PROP( hDlg, ATOM_TTYINFO )))
return ( FALSE ) ;
cfTTYFont.lStructSize = sizeof( CHOOSEFONT ) ;
cfTTYFont.hwndOwner = hDlg ;
cfTTYFont.hDC = NULL ;
cfTTYFont.rgbColors = FGCOLOR( pTTYInfo ) ;
cfTTYFont.lpLogFont = &LFTTYFONT( pTTYInfo ) ;
cfTTYFont.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY |
CF_EFFECTS | CF_INITTOLOGFONTSTRUCT ;
cfTTYFont.lCustData = 0 ;
cfTTYFont.lpfnHook = NULL ;
cfTTYFont.lpTemplateName = NULL ;
cfTTYFont.hInstance = GETHINST( hDlg ) ;
if (ChooseFont( &cfTTYFont ))
{
FGCOLOR( pTTYInfo ) = cfTTYFont.rgbColors ;
ResetTTYScreen( GetParent( hDlg ), pTTYInfo ) ;
}
return ( TRUE ) ;
} // end of SelectTTYFont()
//---------------------------------------------------------------------------
// End of File: tty.c
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -