Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
enum Colors { blue=1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hred, hpurple, hyellow, hwhite };
void coutc(int color, char* output)
{
HANDLE handle= GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute( handle,color);
cout<< output;
SetConsoleTextAttribute( handle, color);
}
coutc(blue, "test");
/*************************************************/
/* kleur.h & kleur.cpp */
/* created by: Johan Temmerman */
/* based on other code-snippets */
/* */
/* Once a color is set, it remains that way till */
/* anotherone is set, or till the end of your */
/* program. The appearance of your console won't */
/* be affected in other console-programs */
/* */
/* Use: include this header and you can use the */
/* inline defined commands in your program */
/* like this: */
/* */
/* std::cout << clr::fg_red << "red"; */
/* */
/* The 'fg_'-prefix means you're changing the */
/* color of the text. The 'bg_'-names apply to */
/* the background of the console. */
/* */
/* The inline-command names are the original */
/* 16 VGA-names of the colors: */
/* yellow, fuchsia, red, aqua, lime, blue */
/* olive, purple, maroon, teal, green, navy */
/* white, silver, grey, black */
/* */
/*************************************************/
#include <iostream>
#include <iomanip>
#include <windows.h>
#ifndef K_L_E_U_R__H
#define K_L_E_U_R__H
namespace clr
{
//huidige kleuren
static const WORD bgMask( BACKGROUND_BLUE |
BACKGROUND_GREEN |
BACKGROUND_RED |
BACKGROUND_INTENSITY );
static const WORD fgMask( FOREGROUND_BLUE |
FOREGROUND_GREEN |
FOREGROUND_RED |
FOREGROUND_INTENSITY );
//tekstkleur
static const WORD fgBlack ( 0 );
static const WORD fgLoRed ( FOREGROUND_RED );
static const WORD fgLoGreen ( FOREGROUND_GREEN );
static const WORD fgLoBlue ( FOREGROUND_BLUE );
static const WORD fgLoCyan ( fgLoGreen | fgLoBlue );
static const WORD fgLoMagenta( fgLoRed | fgLoBlue );
static const WORD fgLoYellow ( fgLoRed | fgLoGreen );
static const WORD fgLoWhite ( fgLoRed | fgLoGreen | fgLoBlue );
static const WORD fgGrey ( fgBlack | FOREGROUND_INTENSITY );
static const WORD fgHiWhite ( fgLoWhite | FOREGROUND_INTENSITY );
static const WORD fgHiBlue ( fgLoBlue | FOREGROUND_INTENSITY );
static const WORD fgHiGreen ( fgLoGreen | FOREGROUND_INTENSITY );
static const WORD fgHiRed ( fgLoRed | FOREGROUND_INTENSITY );
static const WORD fgHiCyan ( fgLoCyan | FOREGROUND_INTENSITY );
static const WORD fgHiMagenta( fgLoMagenta | FOREGROUND_INTENSITY );
static const WORD fgHiYellow ( fgLoYellow | FOREGROUND_INTENSITY );
//achtergrond
static const WORD bgBlack ( 0 );
static const WORD bgLoRed ( BACKGROUND_RED );
static const WORD bgLoGreen ( BACKGROUND_GREEN );
static const WORD bgLoBlue ( BACKGROUND_BLUE );
static const WORD bgLoCyan ( bgLoGreen | bgLoBlue );
static const WORD bgLoMagenta( bgLoRed | bgLoBlue );
static const WORD bgLoYellow ( bgLoRed | bgLoGreen );
static const WORD bgLoWhite ( bgLoRed | bgLoGreen | bgLoBlue );
static const WORD bgGrey ( bgBlack | BACKGROUND_INTENSITY );
static const WORD bgHiWhite ( bgLoWhite | BACKGROUND_INTENSITY );
static const WORD bgHiBlue ( bgLoBlue | BACKGROUND_INTENSITY );
static const WORD bgHiGreen ( bgLoGreen | BACKGROUND_INTENSITY );
static const WORD bgHiRed ( bgLoRed | BACKGROUND_INTENSITY );
static const WORD bgHiCyan ( bgLoCyan | BACKGROUND_INTENSITY );
static const WORD bgHiMagenta( bgLoMagenta | BACKGROUND_INTENSITY );
static const WORD bgHiYellow ( bgLoYellow | BACKGROUND_INTENSITY );
//klasse om info over de console op te halen en zo aan te passen
static class Kleur
{
private:
HANDLE hCon; //handle van de console
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
void GetInfo();
public:
Kleur();
void SetColor( WORD wRGBI, WORD Mask );
} console;
///////////////////////////////////////////////////
// vereenvoudigde aanroep voor kleurwissel maken //
///////////////////////////////////////////////////
//tekstkleuren
inline std::ostream& fg_yellow( std::ostream& os ){
os.flush();
console.SetColor( fgHiYellow, bgMask );
return os;
}
inline std::ostream& fg_fuchsia( std::ostream& os ){
os.flush();
console.SetColor( fgHiMagenta, bgMask );
return os;
}
inline std::ostream& fg_red( std::ostream& os ){
os.flush();
console.SetColor( fgHiRed, bgMask );
return os;
}
inline std::ostream& fg_aqua( std::ostream& os ){
os.flush();
console.SetColor( fgHiCyan, bgMask );
return os;
}
inline std::ostream& fg_lime( std::ostream& os ){
os.flush();
console.SetColor( fgHiGreen, bgMask );
return os;
}
inline std::ostream& fg_blue( std::ostream& os ){
os.flush();
console.SetColor( fgHiBlue, bgMask );
return os;
}
inline std::ostream& fg_olive( std::ostream& os ){
os.flush();
console.SetColor( fgLoYellow, bgMask );
return os;
}
inline std::ostream& fg_purple( std::ostream& os ){
os.flush();
console.SetColor( fgLoMagenta, bgMask );
return os;
}
inline std::ostream& fg_maroon( std::ostream& os ){
os.flush();
console.SetColor( fgLoRed, bgMask );
return os;
}
inline std::ostream& fg_teal( std::ostream& os ){
os.flush();
console.SetColor( fgLoCyan, bgMask );
return os;
}
inline std::ostream& fg_green( std::ostream& os ){
os.flush();
console.SetColor( fgLoGreen, bgMask );
return os;
}
inline std::ostream& fg_navy( std::ostream& os ){
os.flush();
console.SetColor( fgLoBlue, bgMask );
return os;
}
inline std::ostream& fg_white( std::ostream& os ){
os.flush();
console.SetColor( fgHiWhite, bgMask );
return os;
}
inline std::ostream& fg_silver( std::ostream& os ){
os.flush();
console.SetColor( fgLoWhite, bgMask );
return os;
}
inline std::ostream& fg_grey( std::ostream& os ){
os.flush();
console.SetColor( fgGrey, bgMask );
return os;
}
inline std::ostream& fg_black( std::ostream& os ){
os.flush();
console.SetColor( fgBlack, bgMask );
return os;
}
//achtergrondkleuren
inline std::ostream& bg_yellow( std::ostream& os ){
os.flush();
console.SetColor( bgHiYellow, fgMask );
return os;
}
inline std::ostream& bg_fuchsia( std::ostream& os ){
os.flush();
console.SetColor( bgHiMagenta, fgMask );
return os;
}
inline std::ostream& bg_red( std::ostream& os ){
os.flush();
console.SetColor( bgHiRed, fgMask );
return os;
}
inline std::ostream& bg_aqua( std::ostream& os ){
os.flush();
console.SetColor( bgHiCyan, fgMask );
return os;
}
inline std::ostream& bg_lime( std::ostream& os ){
os.flush();
console.SetColor( bgHiGreen, fgMask );
return os;
}
inline std::ostream& bg_blue( std::ostream& os ){
os.flush();
console.SetColor( bgHiBlue, fgMask );
return os;
}
inline std::ostream& bg_olive( std::ostream& os ){
os.flush();
console.SetColor( bgLoYellow, fgMask );
return os;
}
inline std::ostream& bg_purple( std::ostream& os ){
os.flush();
console.SetColor( bgLoMagenta, fgMask );
return os;
}
inline std::ostream& bg_maroon( std::ostream& os ){
os.flush();
console.SetColor( bgLoRed, fgMask );
return os;
}
inline std::ostream& bg_teal( std::ostream& os ){
os.flush();
console.SetColor( bgLoCyan, fgMask );
return os;
}
inline std::ostream& bg_green( std::ostream& os ){
os.flush();
console.SetColor( bgLoGreen, fgMask );
return os;
}
inline std::ostream& bg_navy( std::ostream& os ){
os.flush();
console.SetColor( bgLoBlue, fgMask );
return os;
}
inline std::ostream& bg_white( std::ostream& os ){
os.flush();
console.SetColor( bgHiWhite, fgMask );
return os;
}
inline std::ostream& bg_silver( std::ostream& os ){
os.flush();
console.SetColor( bgLoWhite, fgMask );
return os;
}
inline std::ostream& bg_grey( std::ostream& os ){
os.flush();
console.SetColor( bgGrey, fgMask );
return os;
}
inline std::ostream& bg_black( std::ostream& os ){
os.flush();
console.SetColor( bgBlack, fgMask );
return os;
}
}
#endif //K_L_E_U_R__H
#include "kleur.h"
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace clr;
/////////////
// PRIVATE //
/////////////
void Kleur::GetInfo(){ //info over de console opvragen
GetConsoleScreenBufferInfo( hCon, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y; //afmetingen
}
////////////
// PUBLIC //
////////////
Kleur::Kleur(){ //constructor zorgt ervoor dat de handle van het consolevenster wordt toegekend
hCon = GetStdHandle( STD_OUTPUT_HANDLE );
}
void Kleur::SetColor( WORD wRGBI, WORD Mask ){ //kleur instellen
GetInfo();
csbi.wAttributes &= Mask;
csbi.wAttributes |= wRGBI;
SetConsoleTextAttribute( hCon, csbi.wAttributes );
}
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.