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