Last active
December 27, 2015 10:19
-
-
Save davidglezz/7310089 to your computer and use it in GitHub Desktop.
Windows Console color & position examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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