Use the C language to implement output at a specified position in the Win console.

Source: Internet
Author: User

Use the C language to implement output at a specified position in the Win console.

There is a GotoXY in the ancient Turbo C that allows you to output text in the specified coordinates. What is hateful is the C language books I have read, and half of them are about it. I am using a Windows system. It is impossible for me to write DOS programs. At least I have to start with the Windows console program. So I collected more information and finally found a Windows console program API to jump to a specified location for output.

# Include <stdio. h> # include <Windows. h> # include <conio. h> # include <stdlib. h> int main () {int I; HANDLE hOut; COORD pos = {0, 0}; hOut = GetStdHandle (STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; // defines the struct GetConsoleCursorInfo (hOut, & cci); // obtain the cursor information cci. dwSize = 1; // set the cursor size cci. bVisible = 0; // set the cursor to invisible FALSE SetConsoleCursorInfo (hOut, & cci); // set (Application) The cursor information SetConsoleTextAttribute (hOut, 0x0004 | 0x0008 | 0x8000 ); // set the font attribute pos. X = 5; pos. Y = 5; SetConsoleCursorPosition (hOut, pos); // set the cursor coordinate printf ("Here % 2d %", 0); pos. X = 13; pos. Y = 5; SetConsoleCursorPosition (hOut, pos); getch (); for (I = 0; I <= 100; I ++) {SetConsoleCursorPosition (hOut, pos ); printf ("% 2d %", I); Sleep (500);} return 0 ;}

 

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.