Skip to content

Instantly share code, notes, and snippets.

@davidglezz
Last active December 27, 2015 10:19
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 davidglezz/7310089 to your computer and use it in GitHub Desktop.
Save davidglezz/7310089 to your computer and use it in GitHub Desktop.
Windows Console color & position examples
#include <windows.h>
void write(HANDLE hStdout, const char* message)
{
DWORD t;
WriteConsole(hStdout, (const void*)message, lstrlen(message), &t, NULL);
}
bool gotoxy(HANDLE hStdout, unsigned short x, unsigned short y)
{
return SetConsoleCursorPosition(hStdout, (COORD){x,y});
}
int main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(hStdout, 23,10);
write(hStdout, "blog.davidxl.es");
gotoxy(hStdout, 20,23);
return 0;
}
#include <windows.h>
HANDLE hstdout;
void write(const char* message)
{
DWORD t;
WriteConsole(hstdout, (const void*)message, lstrlen(message), &t, NULL);
}
int main()
{
hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
write("\n");
SetConsoleTextAttribute(hstdout, FOREGROUND_INTENSITY | FOREGROUND_RED | BACKGROUND_INTENSITY
| BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE );
for (int i = 0; i< 40; i++)
write(" ");
write("\n blog.davidxl.es \n");
for (int i = 0; i< 40; i++)
write(" ");
SetConsoleTextAttribute(hstdout, FOREGROUND_INTENSITY);
write("\n\n");
for (int i = 0; i<256; i++)
{
SetConsoleTextAttribute(hstdout, i);
write("?");
}
SetConsoleTextAttribute(hstdout,FOREGROUND_INTENSITY);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment