Winconsio.h: A personal library for replacing Conio.h on the Windows platform

Source: Internet
Author: User

1 #ifndef Win_cons_io_h2 #defineWin_cons_io_h3 4#include <windows.h>5 6 #defineSetconscolor (ColorIndex) Setconsoletextattribute (GetStdHandle (std_output_handle), ColorIndex)7 #defineBeginfgred Setconscolor (foreground_red)8 #defineBeginfgblue Setconscolor (Foreground_blue)9 #defineBeginfggreen Setconscolor (Foreground_green)Ten #defineBeginfgauto Setconscolor (foreground_intensity) One #defineBeginbgred Setconscolor (background_red) A #defineBeginbgblue Setconscolor (Background_blue) - #defineBeginbggreen Setconscolor (Background_green) - #defineBeginbgauto Setconscolor (background_intensity) the  - voidCLsvoid) - { -    //Get the handle to the current output buffer ... +HANDLE hStdOut =GetStdHandle (std_output_handle); -    //This was used to reset the Carat/cursor to the top left. +COORD COORD = {0,0}; A    //A return value ... indicating how many chars were written at    //Not used but we need-capture this since it 'll be -    //written anyway (passing NULL causes an access violation). - DWORD count; -    //This was a structure containing all of the console info -    //It is used here to find the size of the console. - Console_screen_buffer_info Csbi; in    //Here we'll set the current color -    if(Getconsolescreenbufferinfo (hStdOut, &csbi)) to    { +       //This fills, the buffer with a given character (in this case 32=space). -Fillconsoleoutputcharacter (hStdOut, (TCHAR) +, csbi.dwsize.x * csbi.dwsize.y, coord, &count); theFillconsoleoutputattribute (hStdOut, Csbi.wattributes, csbi.dwsize.x * csbi.dwsize.y, coord, &count); *       //This would set our cursor position for the next print statement. $ setconsolecursorposition (hStdOut, coord);Panax Notoginseng    } - } the  + #defineGotoxy (x, y) setconsolecursorposition (GetStdHandle (Std_output_handle), {x, y}) A  the voidHidecur (void) + { - Console_cursor_info ccicursor; $HANDLE hStdOut =GetStdHandle (std_output_handle); $   -    if(Getconsolecursorinfo (hStdOut, &ccicursor)) -    { theCcicursor.bvisible =FALSE; -Setconsolecursorinfo (hStdOut, &ccicursor);Wuyi    } the } -   Wu  - voidShowcur (void) About { $ Console_cursor_info ccicursor; -HANDLE hStdOut =GetStdHandle (std_output_handle); -   -    if(Getconsolecursorinfo (hStdOut, &ccicursor)) A    { +Ccicursor.bvisible =TRUE; theSetconsolecursorinfo (hStdOut, &ccicursor); -    } $ } the  the  the CharGetch (void) the { -HANDLE hStdIn =GetStdHandle (std_input_handle); in Input_record Irinputrecord; the DWORD Dweventsread; the   CharCChar; About  the    while(Readconsoleinputa (hStdIn, &irinputrecord,1, &dweventsread))/*Read Key Press*/ the     if(Irinputrecord.eventtype = =key_event the&&irinputrecord.event.keyevent.wvirtualkeycode! =Vk_shift +&&irinputrecord.event.keyevent.wvirtualkeycode! =Vk_menu -&&irinputrecord.event.keyevent.wvirtualkeycode! =Vk_control) the     {BayiCChar =IrInputRecord.Event.KeyEvent.uChar.AsciiChar; theReadconsoleinputa (hStdIn, &irinputrecord,1, &dweventsread);/*Read Key Release*/ the     returnCChar; -     } -   returnEOF; the } the  thetypedefstructPOS {intXinty;} PosT; the #defineUppos (POS) {pos.x-1, pos.y} - #defineDownpos (POS) {pos.x + 1, pos.y} the #defineLeftPos (POS) {pos.x, pos.y-1} the #defineRightpos (POS) {pos.x, Pos.y + 1} the 94 #endif

Winconsio.h: A personal library for replacing Conio.h on the Windows platform

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.