Graphical interface programming in the C Console window (V ).

Source: Internet
Author: User

Controlling text movement is an important function of console window interface programming. With this function, we can implement Page scrolling. Next we will introduce a function for controlling text movement, as shown below: BOOL ScrollConsoleScreenBuffer (// HANDLE hConsoleOutput, // HANDLE const SMALL_RECT * lpScrollRectangle, // move the const SMALL_RECT * lpClipRectangle, // specifies the cropping area. If it is NULL, it indicates the COORD dwDestinationOrigin of the entire screen buffer. // The position to be moved, this point will become the top left vertex of the moving area const CHAR_INFO * lpFill // fill character of the empty out area). The following is a sample program for moving text, as shown below # include <stdio. h> # include <conio. h> # include <Windows. h> # include <stdlib. h> int main () {H ANDLE handle_out = GetStdHandle (STD_OUTPUT_HANDLE); // gets the standard output device handle lele_screen_buffer_info csbi; // defines the window buffer information structure SMALL_RECT scroll; // defines the moving area COORD pos = {0, 5}; // move the location CHAR_INFO chFill; // define the fill character GetConsoleScreenBufferInfo (handle_out, & csbi ); // obtain window buffer information // define parameters and attributes of the filled characters chFill. char. asciiChar = ''; chFill. attributes = csbi. wAttributes; // output text printf ("00000000000000000000000000000 \ n"); printf ("1111 1111111111111111111111111 \ n "); printf (" 22222222222222222222222222222 \ n "); printf (" 33333333333333333333333333333 \ n "); // determine the region scroll. left = 1; scroll. top = 1; scroll. right = 10; scroll. bottom = 2; ScrollConsoleScreenBuffer (handle_out, & scroll, NULL, pos, & chFill); // move the text return 0;} in the preceding example, the cropping area is the screen buffer of the entire Console window. Now, if we set the cropping area to the same as the moving area, that is to say, the third parameter of the ScrollConsoleScreenBuffer function is also changed to & scroll, what will happen? Why does this happen? Obviously, due to the problem of setting the cropping area, we still set the cropping area as the moving area, but we only move the moving area down one line instead of another, see what happens? Now we should be able to guess the conclusion. Don't worry. Let's try another experiment. Now we will change the area to the entire screen buffer to see what will happen? In the last experiment, we reduced the area to the upper part of the moving area and continued to move down the row to see what the final result would be like? Now, we can draw a few conclusions through induction, that is, the area outside the cut-off area will not be affected by text movement. Specifically: 1. the area outside the cut-off area will not be covered by the moved area; 2. the area outside the cut-off area will not change after it is moved to another place, therefore, you do not need to fill in characters. In general, that is, what the original text looks like, and what it looks like after the text is moved, it will not change. 2. the area within the cut-off area is affected by text movement. Specifically: 1. When the area within the cut-off area is moved to another place, this area will be filled with the set characters, 2, the area within the cut-off area will be covered by the moved area. In general, it is completely affected by text movement. When moved, it will be overwritten. When moved, it will be filled by the set characters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.