Here are a few API functions for console window operations, as follows:
Gets the console window information
getconsolescreenbufferinfo ();
Gets the console window title
getconsoletitle ();
Change the specified buffer size
setconsolescreenbuffersize ();
Set the console window title
setconsoletitle ();
Set the console window information
setconsolewindowinfo ();
The following example program is used to illustrate the use of this type of function:
#include <stdio.h> #include <stdlib.h> #include <Windows.h> #include <conio.h> #d Efine N 255 int main () {HANDLE handle_out; Define a handle console_screen_buffer_info SCBI; Defines a window buffer information structure body COORD size = {80, 25};
Defines a coordinate structure body char strtitle[n]; Handle_out = GetStdHandle (Std_output_handle); Obtain the standard output device handle Getconsolescreenbufferinfo (Handle_out, &SCBI); Gets the window buffer information Getconsoletitle (strtitle, N);
Gets the current window title printf ("Current window title:%s\n", strtitle);
_getch (); Setconsoletitle ("console window operation"); Sets the window title to "console window operation" Getconsoletitle (Strtitle, N);
Gets the current window title printf ("Current window title:%s\n", strtitle);
_getch (); Setconsolescreenbuffersize (handle_out, size);
Reset buffer size _getch (); Small_rect rc = {0, 0, 80-1, 25-1};
Reset window position and size Setconsolewindowinfo (handle_out, 1, &RC); CloseHandle (handle_out); Turn off the standard output device handle return 0; }
Where the Setconsolescreenbuffersize function specifies the size of the new console screen buffer to character columns and behavior units. The width and height specified cannot be less than the width and height of the console screen buffer window. The specified size cannot be smaller than the minimum allowable size of the system. This minimum depends on the current font size of the console (selected by the user).
In addition, the implementation of the Getconsoletitle function specifies whether the macro defines Unicode (which is related to the file encoding form), so it is possible for this example to compile in some of the Ides without using a different compiler or IDE. This sample is compiled by Code::Blocks 13.12.