This header has been updated here: Click Me
That colour function that I stole is not C. It's windows programming, but since it's making things easier at the moment, at my skill level, let it continue helping.
Also, I heard about a gotoxy() function that lets you move the cursor around the screen and lets you output anywhere in the output window. But it was only for Turbo C. I've found one for Code Blocks, I did not note where I copied it from, but a quick search brings up another site with the gotoxy info:
http://codeincodeblock.blogspot.in/2011/03/gotoxy-in-codeblock.html
I saved both functions into a header file "myconiowin.h", (thus named so that i remember it includes conio.h and windows.h). It's saved in my "include" folder (C:\Program Files\CodeBlocks\MinGW\include).
#include <windows.h>
#include <conio.h>
COORD coord = {0, 0};
void SetColorAndBackground(int ForgC,int BackC);
void gotoxy(int x,int y)
{
coord.X=x;coord.Y=y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void SetColorAndBackground(int ForgC,int BackC)
{
WORD wColor=((BackC&0x0F)<<4)+(ForgC & 0x0F);;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wColor);
return;
}
This way, if I include "myconiowin.h" in my programs, I can use both SetColorAndBackground for colours and gotoxy to move output around the screen.
No comments:
Post a Comment