C Language Console window graphics interface programming one

Source: Internet
Author: User
Tags function prototype

This series of articles is adapted from the "C Language Console window Interface Programming (revised edition)". This series of articles will discard some parts of the original that are difficult to understand and not commonly used, and modify some of the sample programs. Only to learn more clearly the C language of the console window interface programming. To get a deeper understanding of this series of articles, please read the "C Language Console window interface programming (revised version)."

"C Language Console window interface programming (revised version)" Download Address: http://download.csdn.net/detail/jzqt_t/7471013

The Windows operating system in C language to write the console window interface first to obtain the current standard input and standard output device handle. You can get the current standard input and the handle of the output device by calling the function GetStdHandle. The function prototype is:

HANDLE GetStdHandle (DWORD nstdhandle);    
/*   
where nstdhandle can be   
std_input_handle    standard input device handle   
std_output_handle   standard output device handle   
std_error_ HANDLE    standard error device handle   
* *

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/

It is necessary to note that "handle" is the most common concept of Windows. It is typically used to identify objects such as Windows resources (menus, icons, windows, and so on) and devices. Although the handle can be interpreted as a pointer variable type, it is not the address pointer of the object, but rather is used as the index value of the Windows System internal table. Invokes API functions controlled by the associated text interface. These functions can be grouped into three categories. One is the function for the console window operation (including the window's buffer size, window foreground character and background color, window caption, size, and position), and the second is the function for the console input and output (including the Character property action function), and the other function is the last class. Closes the input output handle by calling the CloseHandle function.

Sample programs:

 #include <stdio.h> #include <windows.h> #include <conio.h> int main (int argc,                              Char *argv[]) {HANDLE handle_out;         Define a handle console_screen_buffer_info screen_info;                             Defines the window buffer information structure COORD pos = {0, 0};   Defines a coordinate structure body handle_out = GetStdHandle (Std_output_handle);   Obtain the standard output device handle Getconsolescreenbufferinfo (Handle_out, &screen_info);   Get window information _getch (); Enter a character that does not appear on the screen/* fills the entire buffer with the character ' A ' where the padding begins with a pos, coordinates {0, 0}, which is the character at the top-left corner of the screen filled with screen_info.dwsi Ze. X (buffer width, which is the horizontal axis) * SCREEN_INFO.DWSIZE.Y (buffer height, which is the ordinate) so you can achieve the effect of filling the entire buffer with the character ' A ' * * fillconsoleoutputcharacte    
    R (handle_out, ' A ', screen_info.dwsize.x * screen_info.dwsize.y, POS, NULL);    CloseHandle (handle_out);    
Turn off the standard output device handle return 0; }
In the program, COORD and console_screen_buffer_ info are wincon.h defined console struct type    
//prototype as follows    
        
//coordinate structure    
typedef struct _COORD    
{short    
    X;    
    Short Y;    
} COORD;    
        
Console window information structure    
typedef struct _CONSOLE_SCREEN_BUFFER_INFO    
{    
    COORD dwsize;               Buffer size    
    COORD dwcursorposition;     The current cursor position    
    WORD wattributes;           Character attribute    
    Small_rect Srwindow;        The size and position of the current window display    
    COORD dwmaximumwindowsize;  Maximum window buffer size    
}console_screen_buffer_info;

It is also necessary to note that, although in C + +, iostream.h defines the standard input and output stream objects for CIN and cout. But they can only achieve basic input and output operations, the Console window interface control is powerless, and can not be friendly with stdio.h and conio.h, because iostream.h and they are C + + two sets of different input and output operation, use special attention.

(

jzqt_t

)

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.