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

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

unix.superglobalmegacorp.com

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