//-------------------------------------------------------------------------- // TESTVIEW.C // // This module contains the viewport window procedure and support routines. // The viewport is a self-standing DLL which can support the creation and // maintenance of multiple viewport windows. // // Revision history: // // 08-14-91 randyki Modified to conform to the DLL split-out model // // 03-29-91 randyki Completely re-written // // 01-25-91 randyki Modified to be self-standing window "activated" // by WTD or the WTD script command VIEWPORT ON/OFF // // ~~?? tomw Created // //-------------------------------------------------------------------------- #define _WINDOWS #define OEMRESOURCE #include #include #include "testview.h" #include #include #include #define MAXLINES 50 #define MAXLINELEN 80 #define IDM_CLEARVP 42 #define GWW_CURSOR 0 #define GWW_CHARHEIGHT 4 #define GWW_MEMHANDLE 8 #define GWW_COMECHO 12 #define GWW_WINDOWY 16 #define VPEXTRA 20 #define ScrollScrMem(s) _fmemmove(s+MAXLINELEN+1,s,(MAXLINES-1)*(MAXLINELEN+1)) LONG APIENTRY ViewportWndProc (HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam); INT fRegistered = 0; // Class registration flag HANDLE hInst; // DLL instance CHAR szViewPort[] = "RBviewport"; // Class name //-------------------------------------------------------------------------- // CreateViewport // // This is the API which creates a new viewport window. The style and title // of the window is completely user-defined. // // RETURNS: Handle of new viewport window if successful, or NULL if not //-------------------------------------------------------------------------- HWND APIENTRY CreateViewport (LPSTR name, DWORD style, INT x, INT y, INT w, INT h) { HWND hwndvp; // Make sure the style bits sent in do not include "nasty" styles... //----------------------------------------------------------------------- if ((style & WS_CHILD) || (style & WS_POPUP)) return (NULL); // If we're already registered, we don't need to again... //----------------------------------------------------------------------- if (!fRegistered) { WNDCLASS wc; // Register the Viewport window class //------------------------------------------------------------------- wc.style = CS_VREDRAW | CS_HREDRAW | CS_GLOBALCLASS; wc.lpfnWndProc = (WNDPROC)ViewportWndProc; wc.lpszMenuName = NULL; wc.hInstance = hInst; wc.hIcon = LoadIcon (hInst, "IDVP"); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszClassName = szViewPort; wc.cbWndExtra = VPEXTRA; wc.cbClsExtra = 0; if (!RegisterClass (&wc)) return (NULL); fRegistered = 1; } // Create the window //----------------------------------------------------------------------- hwndvp = CreateWindow (szViewPort, name, WS_OVERLAPPED | style, x, y, w, h, NULL, NULL, hInst, NULL); return (hwndvp); } //-------------------------------------------------------------------------- // UpdateViewport // // This routine takes the string from the atom specified in wParam and // "prints" it into the ViewPort "screen" memory. Once the memory screen // has been updated, the viewport's client area is updated, based on the // number of lines "scrolled". // // RETURNS: Nothing //-------------------------------------------------------------------------- VOID APIENTRY UpdateViewport (HWND hwnd, LPSTR strbuf, UINT len) { TEXTMETRIC tm; HANDLE hScreen; RECT ClientRect; CHAR FAR *scr, *crlf = "\r\n"; INT scrolled; UINT x, wHeight; INT echostart, cursor, fComEcho; // Are we being jerked around??? //----------------------------------------------------------------------- if (!IsWindow (hwnd)) return; // Check the length of the input string. If -1, find it with strlen //----------------------------------------------------------------------- if ((INT)len == -1) len = _fstrlen (strbuf); // Update the "screen memory" with the new string. Remember that the // lines of the "screen" are backwards -- so the first line in hScreen is // the BOTTOM line in the viewport. //----------------------------------------------------------------------- cursor = (INT)GetWindowLong (hwnd, GWW_CURSOR); hScreen = (HANDLE)GetWindowLong (hwnd, GWW_MEMHANDLE); fComEcho = (INT)GetWindowLong (hwnd, GWW_COMECHO); scrolled = 0; echostart = cursor; scr = GlobalLock (hScreen); for (x=0; xhdc, &tm); wHeight = tm.tmHeight + tm.tmExternalLeading; SetWindowLong (hwnd, GWW_CHARHEIGHT, (UINT)wHeight); } // Determine the number of lines needed to draw //----------------------------------------------------------------------- if (wHeight && ((INT)WinY > 0)) lines = WinY/wHeight + 1; else lines = 0; // Textout the lines //----------------------------------------------------------------------- hScreen = (HANDLE)GetWindowLong (hwnd, GWW_MEMHANDLE); scr = GlobalLock (hScreen); SetTextColor (ps->hdc, GetSysColor(COLOR_WINDOWTEXT)); SetBkColor (ps->hdc, GetSysColor(COLOR_WINDOW)); for (i=1; i<=lines; i++) TextOut (ps->hdc, 0, WinY-(wHeight*i), (LPSTR) scr + ((i-1) * (MAXLINELEN+1)), lstrlen((LPSTR)(scr + ((i-1) * (MAXLINELEN+1)) ))); GlobalUnlock (hScreen); return; } //--------------------------------------------------------------------------- // ClearViewport // // This routine clears the viewport by setting all the strings in the buffer // to "" and invalidating the viewport's client area // // RETURNS: Nothing //--------------------------------------------------------------------------- VOID APIENTRY ClearViewport (HWND hwnd) { INT i; CHAR FAR *scr; HANDLE hScreen; if (!IsWindow (hwnd)) return; hScreen = (HANDLE)GetWindowLong (hwnd, GWW_MEMHANDLE); scr = GlobalLock (hScreen); for (i=0; i