Annotation of mstools/samples/console/scroll.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
1.1       root       12: #include <windows.h>
                     13: #include "console.h"
                     14: 
1.1.1.2   root       15: /* The following is the sample text that we will place on the lower
                     16: half of the screen to scroll: */
1.1       root       17: 
                     18: static PCHAR szSampTxt =
                     19:   "BOOL�ScrollConsoleScreenBuffer(�hConsoleOutput, lpScrollRectangle,\n"
                     20:   "                               lpClipRectangle, dwDestinationOrigin,\n"
                     21:   "                               lpFill)\n"
                     22:   "HANDLE hConsoleOutput;\n"
                     23:   "PSMALL_RECT lpScrollRectangle;\n"
                     24:   "PSMALL_RECT lpClipRectangle;\n"
                     25:   "COORD dwDestinationOrigin;\n"
                     26:   "PCHAR_INFO lpFill;\n"
                     27:   "\n"
                     28:   "This function may be used to scroll the data in the screen buffer.\n"
                     29:   "\n"
                     30:   "Parameter            Description\n"
                     31:   "����������������������������������������������������������������������������\n"
                     32:   "hConsoleOutput       Supplies an open handle to console output.\n"
                     33:   "lpScrollRectangle    Pointer to region within screen buffer to move.\n"
                     34:   "lpClipRectangle      Pointer to region within screen buffer that may be\n"
                     35:   "                     affected by this scroll. This pointer may be NULL.\n"
                     36:   "dwDestinationOrigin  Upper left corner of new location of ScrollRectangle\n"
                     37:   "                     contents.\n"
                     38:   "lpFill               Pointer to structure containing new contents of\n"
                     39:   "                     ScrollRectangle region.\n"
                     40:   "\n"
                     41:   "Return Value\n"
                     42:   "The return value is TRUE if the function was successful, otherwise it is\n"
                     43:   "FALSE in which case extended error information can be retrieved by calling\n"
                     44:   "the GetLastError function.\n"
                     45:   "\n"
                     46:   "Comments\n"
                     47:   "This function copies the contents of a rectangular region of the screen\n"
                     48:   "buffer, the scroll region, to another area of the screen buffer, the target\n"
                     49:   "region. The target region is defined as a rectangle the same dimensions as\n"
                     50:   "the scroll region with the upper left corner at dwDestinationOrigin. Each\n"
                     51:   "cell in the scroll region is then filled with the contents of Fill. Any\n"
                     52:   "overlap between the scroll region and the target region is not filled. The\n"
                     53:   "clip rectangle applies to changes made in both the ScrollRectangle and the\n"
                     54:   "destination rectangle, i.e. if the clip rectangle does not include the\n"
                     55:   "scroll rectangle, the scroll rectangle will not be updated with the contents";
                     56: 
                     57: 
                     58: /*******************************************************************
                     59: * FUNCTION: demoScrollCon(HANDLE hConOut)                          *
                     60: *                                                                  *
                     61: * PURPOSE: demonstrate ScrollConsoleScreenBuffer. Scroll the lower *
                     62: *          half of the console with each mouse click               *
                     63: *                                                                  *
                     64: * INPUT: the console output handle to scroll                       *
                     65: ********************************************************************/
                     66: 
                     67: void demoScrollCon(HANDLE hConOut)
                     68: {
                     69:   BOOL bSuccess;
                     70:   INPUT_RECORD inputBuffer;
                     71:   DWORD dwStdInMode;
                     72:   HANDLE hStdIn;
                     73:   DWORD dwInputEvents;
                     74:   COORD coordDest; /* destination of scroll movement */
                     75:   BOOL bDragMode = FALSE;
                     76:   CHAR_INFO chiFill; /* char and attributes to fill empty space with */
                     77:   CONSOLE_SCREEN_BUFFER_INFO csbi; /* used to get current attribute */
                     78:   SMALL_RECT srctScrollRect; /* area of the screen to scroll */
                     79: 
                     80:   setConTitle(__FILE__);
                     81:   myPuts(hConOut, "Let's use ScrollConsoleScreenBuffer to scroll the lower");
                     82:   myPuts(hConOut, "half of the screen up with each mouse click. I'll fill the");
                     83:   myPuts(hConOut, "screen with some sample text so you can see the effect.");
                     84:   myPuts(hConOut, "Hit return to continue, and hit ESC at any time to return.\n");
                     85:   myGetchar();
                     86:   myPuts(hConOut, szSampTxt);
                     87:   hStdIn = GetStdHandle(STD_INPUT_HANDLE);
1.1.1.2   root       88:   PERR(hStdIn != INVALID_HANDLE_VALUE, "GetStdHandle");
1.1       root       89:   bSuccess = GetConsoleMode(hStdIn, &dwStdInMode);
                     90:   PERR(bSuccess, "GetConsoleMode");
                     91:   bSuccess = SetConsoleMode(hStdIn, dwStdInMode | ENABLE_MOUSE_INPUT);
                     92:   PERR(bSuccess, "SetConsoleMode");
                     93:   /* define region we want to move */
                     94:   srctScrollRect.Top = getConY(hConOut) / 2;
                     95:   srctScrollRect.Bottom = getConY(hConOut) - 1;
                     96:   srctScrollRect.Left = 0;
                     97:   srctScrollRect.Right = getConX(hConOut) - 1;
                     98:   /* define origin where we want to move the scrolled region */
                     99:   coordDest.X = 0;
                    100:   coordDest.Y = (getConY(hConOut) / 2) - 1;
                    101:   /* get current attributes and fill out CHAR_INFO structure for fill char */
                    102:   bSuccess = GetConsoleScreenBufferInfo(hConOut, &csbi);
                    103:   PERR(bSuccess, "GetConsoleScreenBufferInfo");
                    104:   chiFill.Char.AsciiChar = ' ';
                    105:   chiFill.Attributes = csbi.wAttributes;
                    106:   for(;;)
                    107:     {
                    108:     bSuccess = ReadConsoleInput(hStdIn, &inputBuffer, 1, &dwInputEvents);
                    109:     PERR(bSuccess, "ReadConsoleInput");
                    110:     switch (inputBuffer.EventType)
                    111:       {
                    112:       case KEY_EVENT:
                    113:         if (inputBuffer.Event.KeyEvent.bKeyDown &&
                    114:             inputBuffer.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
                    115:           {
                    116:           /* set input mode back to what it was originally */
                    117:           bSuccess = SetConsoleMode(hStdIn, dwStdInMode);
                    118:           PERR(bSuccess, "SetConsoleMode");
                    119:           return;
                    120:           }
                    121:         break;
                    122:       case MOUSE_EVENT:
                    123:         /* was this was a click or double click event? Is any button down? */
                    124:         if (inputBuffer.Event.MouseEvent.dwEventFlags != MOUSE_MOVED &&
                    125:             inputBuffer.Event.MouseEvent.dwButtonState)
                    126:           {
                    127:           bSuccess = ScrollConsoleScreenBuffer(hConOut,
                    128:               &srctScrollRect,
                    129:               NULL, /* no clipping rectangle */
                    130:               coordDest, /* coordinates of destination */
                    131:               &chiFill); /* attribute to fill empty space with */
                    132:           PERR(bSuccess, "ScrollConsoleScreenBuffer");
                    133:           }
                    134:         break;
                    135:       } /* switch */
                    136:     } /* while */
                    137: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.