📄 diag_win.c
字号:
case SB_PAGEDOWN: { cp += WinDialog.NoLines; break; } case SB_PAGEUP: { cp -= WinDialog.NoLines; break; } case SB_THUMBTRACK: { cp = LOWORD(lParam); break; } default: { return (0); } } if (cp >= max) { cp = max; ShowCaret ( hMain ); CaretON = TRUE; } else if ( CaretON ) { HideCaret ( hMain ); CaretON = FALSE; } if (cp < WinDialog.NoLines) cp = WinDialog.NoLines; SetScrollPos (hMain, SB_VERT, cp, TRUE ); InvalidateRect (hMain, NULL, TRUE ); break; } case WM_DESTROY: { /* Shut Down DDE Server. */ ShutDownDDE ( ); /* Free Dialog Window */ DeleteTerminal(); /* Quit Windows */ PostQuitMessage(0); return 0; } /*-------------------------------+ | Used to Update the Module Menu | +-------------------------------*/ case WM_INITMENUPOPUP: { int MenuID = GetMenuItemID((HMENU) wParam, 0); if ( MenuID == IDM_MODULE_ONE ) UpdateModuleMenu ((HMENU)wParam); break; } case WM_CLOSE: PostMessage ( hMain, WM_COMMAND, IDM_FILE_QUIT, NULL); break; default: return (DefWindowProc(hMain, message, wParam, lParam)); } return (TRUE);}/******************************************************************* RedrawTerminal: Draw dialog window based on the min, max* and current position of the thumbnail in the horizontal* & vertical scroll bars.******************************************************************/VOID RedrawTerminal ( hDC ) HDC hDC;{ extern SCREEN WinDialog; int x, max, min, pos, start, sbmax = 0; RECT Rect; char *buffer; /*----------------------------------------------+ | Get current value of the vertical scroll bar. | +----------------------------------------------*/ GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max); pos = GetScrollPos (WinDialog.hWnd, SB_VERT ); /*-----------------------------------------+ | Locate the first visible line to display | +-----------------------------------------*/ start = WinDialog.LastLine - ( max - pos ) - WinDialog.NoLines; if ( start == WinDialog.LastLine ) start ++; /*----------------------------------------------+ | If the start value is negative then check if | | at a 'hard' top or if a wrap around is needed | +----------------------------------------------*/ if ( start < 0 ) { if ( max == DIALOG_SIZE ) start = max + start + 1; else start = 0; } /*------------------------------------------+ | Get Position of the horizontal scroll bar | +------------------------------------------*/ pos = GetScrollPos ( WinDialog.hWnd, SB_HORZ); /*----------------------------------------------------------+ | Loop to display text in the visible portion of the screen | +----------------------------------------------------------*/ for ( x = 0; x<= WinDialog.NoLines && Terminal[start] != NULL; x++ ) { int bufsize; GetClientRect (WinDialog.hWnd, &Rect); Rect.top = x * WinDialog.LineSize; /*------------------------------------+ | Calculate Horizontal Scroll bar Max | | based on what is displayed. | +------------------------------------*/ if (Terminal[start] != NULL) { bufsize = strlen(Terminal[start]); } else { bufsize = 0; } if ( bufsize > sbmax ) sbmax = bufsize; /*-----------------------------------+ | Display each line of text adjusted | | for the horizontal scroll bar. | +-----------------------------------*/ buffer = NULL; if (( pos <= bufsize ) && (Terminal[start] != NULL)) { buffer = Terminal[start]+pos; DrawText ( hDC, buffer, -1, &Rect, DT_LEFT|DT_NOCLIP | DT_NOPREFIX ); } /*-------------------------------+ | Check if wrap around is needed | +-------------------------------*/ start ++; if ( start > DIALOG_SIZE ) start = 0; } /*-------------------------------------+ | Calculate and display caret adjusted | | for horizontal scroll bar. | +-------------------------------------*/ DrawText ( hDC, buffer, -1, &Rect, DT_LEFT|DT_NOCLIP|DT_CALCRECT | DT_NOPREFIX); SetCaretPos (Rect.right, Rect.top); SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, sbmax-1, TRUE );}/*********************************************************************** PrintFunction: Function will allocate memory used to store strings* sent to the Dialog window.**********************************************************************/#if IBM_TBC#pragma argsused#endifint PrintFunction ( char* logicalname, char* buffer ){ extern SCREEN WinDialog; /* Data Structure for the Dialog Window */ int Loc = 0; /* Number of characters until line break */ char *str; /* Subset of the buffer up to the line break */ extern int HorizScroll; int oldsize, size; /*------------------------------------------------------------------------+ | WinDialog.NoLines = Number of text lines that can be displayed per screen. | | WinDialog.LineSize = Number of pixels in height for each line of text. | | WinDialog.LastLine = Virtual location for the bottom of the text area. | +------------------------------------------------------------------------*/ /*------------------------------------------+ | Allocate room for the buffer to be parsed | +------------------------------------------*/ str = (char *)malloc(strlen(buffer)+1); if (str == NULL) ExitToShell(); str[0] = '\0'; /*-----------------------------------------------+ | Loop through each 'part' of the buffer string | | Note: 'part' is text between carriage returns. | +-----------------------------------------------*/ while (Loc < strlen(buffer)) { /*----------------------------------+ | Caputre text up to the line break | +----------------------------------*/ sscanf(&(buffer[Loc]), "%[^\n]",str ); /*----------------------------------------+ | Allocate new memory if new line of text | | or reallocate if appending line of text | +----------------------------------------*/ if (Terminal[WinDialog.LastLine] != NULL)#if WIN_32 { oldsize = strlen( Terminal[WinDialog.LastLine] ); }#else { oldsize = lstrlen( Terminal[WinDialog.LastLine] ); }#endif else { oldsize = 0; }#if WIN_32 size = oldsize + strlen(str)+1;#else size = oldsize + lstrlen(str)+1;#endif if (Terminal[WinDialog.LastLine] != NULL)#if WIN_32 Terminal[WinDialog.LastLine] = (char *) realloc(Terminal[WinDialog.LastLine], size); else Terminal[WinDialog.LastLine] = (char *) malloc(size);#else Terminal[WinDialog.LastLine] = (char *) farrealloc(Terminal[WinDialog.LastLine], size); else Terminal[WinDialog.LastLine] = (char *) farmalloc(size);#endif if (Terminal[WinDialog.LastLine] == NULL) ExitToShell(); /*--------------------------------+ |Copy String to the dialog window | +--------------------------------*/ Terminal[WinDialog.LastLine][oldsize] = '\0';#if WIN_32 strcat (Terminal[WinDialog.LastLine], str);#else lstrcat (Terminal[WinDialog.LastLine], str);#endif Loc += strlen( str ); if (buffer[Loc] == '\n') { int min, max; /*------------------------------+ | Display line before advancing | +------------------------------*/ SendToScreen (); WinDialog.LastLine ++; if (WinDialog.LastLine > DIALOG_SIZE ) WinDialog.LastLine = 0; /*-----------------------+ | Free next line of text | +-----------------------*/ if (Terminal[WinDialog.LastLine] != NULL) {#if WIN_32 free(Terminal[WinDialog.LastLine]);#else farfree (Terminal[WinDialog.LastLine]);#endif Terminal[ WinDialog.LastLine ] = NULL; } /*-------------------+ | Update Scroll Bars | +-------------------*/ GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max ); if ( max < DIALOG_SIZE ) max = WinDialog.LastLine; else max = DIALOG_SIZE; if ( max > WinDialog.NoLines ) SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, max, FALSE ); else SetScrollRange ( WinDialog.hWnd, SB_VERT, 0,1 , FALSE ); SetScrollPos ( WinDialog.hWnd, SB_VERT, max, TRUE ); GetScrollRange ( WinDialog.hWnd, SB_HORZ, &min, &max); if ( max < size ) max = size; SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, max, FALSE); SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE); } SendToScreen (); Loc ++; } free(str); return (TRUE);}/********************************************************************* SendToScreen: Displays the current text line in the Dialog Window.*********************************************************************/void SendToScreen ( void ){ extern SCREEN WinDialog; /* D.S. Holding info about screen */ RECT DRect; /* Client Area of Dialog Window */ RECT Rect; /* Adjusted Area for scrolling */ HDC hDC = GetDC ( WinDialog.hWnd); /* Handle to the device context */ extern int OldLine; /* Previous Line Printed */ int min, max, pos; /* Scroll Bar Values */ int Scroll = 0; /* Scrolling Needed? */ GetClientRect ( WinDialog.hWnd, &Rect ); GetClientRect ( WinDialog.hWnd, &DRect ); HideCaret ( WinDialog.hWnd ); /*------------------------------------------------------+ | Move to the bottom of the screen if not already there | +------------------------------------------------------*/ GetScrollRange ( WinDialog.hWnd, SB_VERT, &min, &max ); pos = GetScrollPos (WinDialog.hWnd, SB_VERT ); if ( pos != max ) { InvalidateRect ( WinDialog.hWnd, NULL, TRUE ); SetScrollPos (WinDialog.hWnd, SB_VERT, max, FALSE ); SendMessage ( WinDialog.hWnd, WM_PAINT, NULL, NULL); } /*--------------------------------------------------------+ | Determine if the screen is full and scrolling is needed | +--------------------------------------------------------*/ if ( max > WinDialog.NoLines ) Scroll = 1; /*-------------------------------------------------------------+ | Scroll Window if newline and text will not fit on the screen | +-------------------------------------------------------------*/ if (Scroll && WinDialog.LastLine != OldLine) { OldLine = WinDialog.LastLine; ScrollDC ( hDC, 0, -WinDialog.LineSize, &DRect, &DRect, NULL, &Rect ); } /*----------------------------------------+ | Calculate when text is to be displayed | +----------------------------------------*/ if ( !Scroll) Rect.top = (WinDialog.LastLine) * WinDialog.LineSize; else Rect.top = (WinDialog.NoLines) * WinDialog.LineSize; /*----------------------------+ | Clear Line to be displayed | +----------------------------*/ { HANDLE OldObject; OldObject = SelectObject (hDC, GetStockObject ( WHITE_PEN ) ); Rectangle (hDC, Rect.left, Rect.top, Rect.right, Rect.bottom); SelectObject (hDC, OldObject); } /*--------------------------+ | Display Text Adjusting | | for the Horizontal scroll | +--------------------------*/ pos = GetScrollPos (WinDialog.hWnd, SB_HORZ ); if (Terminal[WinDialog.LastLine] == NULL) { /* Do Nothing */ } else if ( pos < strlen (Terminal[WinDialog.LastLine]) ) { DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX ); DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX); } else Rect.right = 2; /*-----------+ | Show Caret | +-----------*/ SetCaretPos (Rect.right, Rect.top); ShowCaret ( WinDialog.hWnd ); /*--------------------------------+ | Automatic Horizontal Scrolling | +--------------------------------*/ if (Terminal[WinDialog.LastLine] != NULL) { DrawText ( hDC, Terminal[WinDialog.LastLine]+pos, -1, &Rect, DT_LEFT | DT_NOCLIP | DT_SINGLELINE | DT_NOPREFIX ); } if ( Rect.right > DRect.right && HorizScroll ) { GetScrollRange ( WinDialog.hWnd, SB_HORZ, &min, &max ); pos ++; if ( max < pos) max = pos; SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, max, FALSE ); SetScrollPos ( WinDialog.hWnd, SB_HORZ, pos, TRUE ); InvalidateRect (WinDialog.hWnd, NULL, TRUE); } OldLine = WinDialog.LastLine; ReleaseDC ( WinDialog.hWnd, hDC);}/*************************************************************** ClearDialogWnd: Procedure will clear all text from the dialog* window and free storage in the terminal data structure.**************************************************************/VOID ClearDialogWnd ( VOID ){ extern int OldLine; extern SCREEN WinDialog; /*-----------------------------------------+ | Free all data associated with the screen | +-----------------------------------------*/ FreeTerminalText(); /*-----------------------------+ | Information about the Screen | +-----------------------------*/ WinDialog.LastLine = 0; OldLine = 0; /*-------------------+ | Update Scroll Bars | +-------------------*/ SetScrollRange ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines-1, WinDialog.NoLines, FALSE); SetScrollPos ( WinDialog.hWnd, SB_VERT, WinDialog.NoLines, TRUE); SetScrollRange ( WinDialog.hWnd, SB_HORZ, 0, 1, FALSE); SetScrollPos ( WinDialog.hWnd, SB_HORZ, 0, TRUE); InvalidateRect ( WinDialog.hWnd, NULL, TRUE ); FlushCommandString();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -