I actually wrote a wrapper class for that that's relatively easy to use...lemme find that.
EDIT: Ok, I found the class, but I also found a bug in it, so I'm just posting the header for now until I fix it.
#ifndef __WINCONIO_CPP_H__
#define __WINCONIO_CPP_H__
#include <windows.h>
#include <tchar.h>
#include <string>
using std::string;
using std::wstring;
typedef struct
{
TCHAR ch;
WORD wAttr;
}ATTRCHAR;
class WinConOut
{
protected:
static DWORD dwRefCount;
static HANDLE hStdOut;
static HANDLE hAccess;
static bool visible;
static CONSOLE_SCREEN_BUFFER_INFO csbi;
static WinConOut * const __inst;
public:
//////////////CONSTANTS////////////////////////////
static const int COLOR_FORE_BLACK = 0x00;
static const int COLOR_FORE_BLUE = 0x10;
static const int COLOR_FORE_GREEN = 0x20;
static const int COLOR_FORE_AQUA = 0x30;
static const int COLOR_FORE_RED = 0x40;
static const int COLOR_FORE_PURPLE = 0x50;
static const int COLOR_FORE_YELLOW = 0x60;
static const int COLOR_FORE_WHITE = 0x70;
static const int COLOR_FORE_GREY = 0x80;
static const int COLOR_FORE_GRAY = 0x80;
static const int COLOR_FORE_LIGHT_BLUE = 0x90;
static const int COLOR_FORE_LIGHT_GREEN = 0xA0;
static const int COLOR_FORE_LIGHT_AQUA = 0xB0;
static const int COLOR_FORE_LIGHT_RED = 0xC0;
static const int COLOR_FORE_LIGHT_PURPLE = 0xD0;
static const int COLOR_FORE_LIGHT_YELLOW = 0xE0;
static const int COLOR_FORE_BRIGHT_WHITE = 0xF0;
static const int COLOR_BACK_BLACK = 0x00;
static const int COLOR_BACK_BLUE = 0x01;
static const int COLOR_BACK_GREEN = 0x02;
static const int COLOR_BACK_AQUA = 0x03;
static const int COLOR_BACK_RED = 0x04;
static const int COLOR_BACK_PURPLE = 0x05;
static const int COLOR_BACK_YELLOW = 0x06;
static const int COLOR_BACK_WHITE = 0x07;
static const int COLOR_BACK_GREY = 0x08;
static const int COLOR_BACK_GRAY = 0x08;
static const int COLOR_BACK_LIGHT_BLUE = 0x09;
static const int COLOR_BACK_LIGHT_GREEN = 0x0A;
static const int COLOR_BACK_LIGHT_AQUA = 0x0B;
static const int COLOR_BACK_LIGHT_RED = 0x0C;
static const int COLOR_BACK_LIGHT_PURPLE = 0x0D;
static const int COLOR_BACK_LIGHT_YELLOW = 0x0E;
static const int COLOR_BACK_BRIGHT_WHITE = 0x0F;
static const int ATTRIB_DEFAULT = 0x07;
static const int ATTRIB_HIGH_INTENSITY = 0x0F;
////////////////////////////////////////////////////
WinConOut(void);
~WinConOut(void);
//hides the console window
void hide(void);
//shows the console window
void show(void);
//sets the default character attributes, i.e. foreground and background
//color. note that unlike Linux this does not allow you to do fancier
//things such as underlining and blinking. that requires loading ANSI.SYS
//at boot time.
bool set_attr(int attr);
//retrieves the current character attributes
int get_attr(void) const;
//moves the cursor to the specified location, returns false on failure
bool move_cursor(int x, int y);
//returns the current x coordinate of the cursor
int get_cursor_x(void) const;
//returns the current y coordinate of the cursor
int get_cursor_y(void) const;
//retrieves information about the console
void get_info(CONSOLE_SCREEN_BUFFER_INFO& buffer) const;
//gets the width, in characters, of the console
int get_width(void) const;
//gets the height, in characters, of the console
int get_height(void) const;
//sets the width and height of the console in characters
bool set_dimensions(int x, int y);
//printf
int printf(LPCTSTR format_string,...);
//printf at a specific coordinate; the cursor does not move from its
//current position.
int printf(int x, int y, LPCTSTR format_string,...);
//printf with attributes - allows you to print to the console using
//character attributes other than the default currently set.
int printfa(LPCTSTR format_string, int attribute,...);
//printf with attributes and coordinates
int printfa(int x, int y, LPCTSTR format_string, int attribute,...);
//retrieves the title string of the console
size_t get_title(LPTSTR buffer,size_t buflen);
//sets the title string of the console
bool set_title(LPCTSTR title);
//clears the entire screen
bool cls(void);
//clears a region of the screen and sets the default attribute for that region
bool clear(int upperx, int uppery, int lowerx, int lowery, int attribute = ATTRIB_DEFAULT);
//fill the screen with a specific character and attribute
bool fill(TCHAR fillch, int attribute);
//fill a region of the screen with a specific character and attribute
bool fill(int upperx, int uppery, int lowerx, int lowery, TCHAR fillch, int attribute);
//copies a region of the screen into a buffer that stores both the character and attribute
bool save_region(int upperx, int uppery, int lowerx, int lowery, ATTRCHAR*& buffer) const;
//copies a char/attr buffer onto the screen.
bool load_region(int upperx, int uppery, int lowerx, int lowery, const ATTRCHAR*& buffer);
//these operators should be used instead of COUT and CERR. Using those will break this.
WinConOut& operator<<(bool data);
WinConOut& operator<<(char data);
WinConOut& operator<<(unsigned char data);
WinConOut& operator<<(short data);
WinConOut& operator<<(unsigned short data);
WinConOut& operator<<(int data);
WinConOut& operator<<(unsigned int data);
WinConOut& operator<<(long data);
WinConOut& operator<<(unsigned long data);
WinConOut& operator<<(double data);
WinConOut& operator<<(float data);
WinConOut& operator<<(long double data);
WinConOut& operator<<(long long data);
WinConOut& operator<<(unsigned long long data);
WinConOut& operator<<(TCHAR data);
WinConOut& operator<<(LPCTSTR str);
WinConOut& operator<<(const string& str);
WinConOut& operator<<(const wstring& str);
};
#endif
Edited by dargueta, 20 August 2009 - 05:04 AM.
Found bug