Thursday, February 26, 2009

Blinking colored text illusion

Everyone likes to add some color and features to their program. This is the easiest way to achieve it, but it uses OS functions and clears the whole screen. There are much more efficient ways to achieve this, but this is a very easy way nevertheless.

Update: CppBuilder2006 found some errors in the code in Borland compilers, and the code was updated to work with VC++ and Borland.

Just compile and run. I am sorry about the indenting problem. This codebox is having issues at the moment.
#include <iostream>
#include <windows.h>

using namespace std;

enum Colors { blue = 1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hred, hpurple, hyellow, hwhite };
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

int main(int argc, char* argv[])
// print, clear, then print again 10 times
for (int i = 0; i < 10; i++)
SetConsoleTextAttribute(handle, hwhite);
cout << "HI!\n";
cout << "This is blinking text =)";
cout << "HI!\n";
return 0;


CppBuilder2006 said...

Thank you
I really needed it!
Good Luck

Post a Comment


C++ Universe - The universe compromised of C++ and C#. Powered By Blogger © 2009.