Skip to content

Instantly share code, notes, and snippets.

@qinhanlei
Created April 7, 2012 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qinhanlei/2326023 to your computer and use it in GitHub Desktop.
Save qinhanlei/2326023 to your computer and use it in GitHub Desktop.
windows console programming
void SetCursor(int x, int y)
{
COORD cd = {(short)x, (short)y};
HANDLE g_hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(g_hOutput, cd);
}
void SetColor(unsigned short ForeColor=0xFFFF,unsigned short BackGroundColor=0)
{
HANDLE m_outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(m_outputHandle, ForeColor|BackGroundColor);
//static CONSOLE_SCREEN_BUFFER_INFO csbInfo;
//GetConsoleScreenBufferInfo(m_outputHandle, &csbInfo);
//return SetConsoleTextAttribute(m_outputHandle, ForeColor | (csbInfo.wAttributes & ~0xF));
}
void echo( bool on = true )
{
DWORD mode;
HANDLE hConIn = GetStdHandle( STD_INPUT_HANDLE );
GetConsoleMode( hConIn, &mode );
mode = on
? (mode | ENABLE_ECHO_INPUT )
: (mode & ~(ENABLE_ECHO_INPUT));
SetConsoleMode( hConIn, mode );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment