C Language Console window graphical interface programming two API functions for console window operations

Source: Internet
Author: User
Tags include printf reset

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, &AMP;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, &AMP;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.

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.