Controlling the movement of text is a very important function of the interface programming of the console window, we can realize the scrolling of the interface with this function. Here's a function that controls the movement of text, as follows:
BOOL Scrollconsolescreenbuffer ( //text move function
HANDLE hconsoleoutput, //handle
const SMALL_RECT * Lpscrollrectangle, //move Zone
const small_rect *lpcliprectangle, //crop area, if NULL, will represent the entire screen buffer
COORD Dwdestinationorigin, //moving to the position, this point becomes the
padding character of the const char_info *lpfill //vacated region of the upper left vertex of the moving region
;
Let's look at a sample program that moves the text as follows
#include <stdio.h> #include <conio.h> #include <Windows.h> #include <stdlib.h> int main () {HANDLE handle_out = GetStdHandle (Std_output_handle); Obtain the standard output device handle Console_screen_buffer_info csbi; Defines the window buffer information structure body small_rect scroll; Define Mobile Area COORD pos = {0, 5}; Moving position char_info Chfill; Defines the fill character getconsolescreenbufferinfo (handle_out, &CSBI);
Get the window buffer information//define the various parameters and attributes of the fill character ChFill.Char.AsciiChar = ';
Chfill.attributes = csbi.wattributes;
Output text printf ("00000000000000000000000000000\n");
printf ("11111111111111111111111111111\n");
printf ("22222222222222222222222222222\n");
printf ("33333333333333333333333333333\n"); Determine the area scroll.
left = 1; Scroll.
top = 1; Scroll.
right = 10; Scroll.
Bottom = 2; Scrollconsolescreenbuffer (Handle_out, &scroll, NULL, POS, &cHfill);
Move text return 0; }
In the sample program above, the clipping area is the screen buffer of the entire console window, and now if we set the clipping area to be the same as the moving region, that is, the third parameter of the Scrollconsolescreenbuffer function is changed to &scroll, So what's the result?
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/