color in win32 console aplication
This code put colors in win32 Console aplication.
AI
Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Zdrojový kód
/************************************************
*The declaration for WORD; COORD; DWORD; HANDLE**
************************************************/
#include <windows.h>
/***************************************************
*The declaration for cout; FOREGROUND_; BACKGROUND_*
***************************************************/
#include <iostream.h>
/************************************************
* The declaration of an objet HANDLE *
************************************************/
HANDLE cxHandle;
/******************************************************************
*It's the function to Set posX, posY, the color And Print the Text*
******************************************************************/
void SetPosXYAndColor(int x, int y, LPSTR Text, WORD Color);
/************************************************
* Macro colors of Text *
************************************************/
#define BLUE FOREGROUND_BLUE
#define LIGHTBLUE FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define RED FOREGROUND_RED
#define LIGHTRED FOREGROUND_RED | FOREGROUND_INTENSITY
#define GREEN FOREGROUND_GREEN
#define LIGHTGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define PURPLE FOREGROUND_BLUE | FOREGROUND_RED
#define LIGHTPURPLE PURPLE | FOREGROUND_INTENSITY
#define BLUEGREEN FOREGROUND_BLUE | FOREGROUND_GREEN
#define LIGHTBLUEGREEN BLUEGREEN | FOREGROUND_INTENSITY
#define ORANGE FOREGROUND_GREEN | FOREGROUND_RED
#define YELLOW ORANGE | FOREGROUND_INTENSITY
#define INTENSITY FOREGROUND_INTENSITY
/************************************************
* Macro colors for background *
************************************************/
#define BBLUE BACKGROUND_BLUE
#define BLIGHTBLUE BACKGROUND_BLUE | BACKGROUND_INTENSITY
#define BRED BACKGROUND_RED
#define BLIGHTRED BACKGROUND_RED | BACKGROUND_INTENSITY
#define BGREEN BACKGROUND_GREEN
#define BLIGHTGREEN BACKGROUND_GREEN | BACKGROUND_INTENSITY
#define BPURPLE BACKGROUND_BLUE | BACKGROUND_RED
#define BLIGHTPURPLE BPURPLE | BACKGROUND_INTENSITY
#define BBLUEGREEN BACKGROUND_BLUE | BACKGROUND_GREEN
#define BLIGHTBLUEGREEN BBLUEGREEN | BACKGROUND_INTENSITY
#define BORANGE BACKGROUND_GREEN | BACKGROUND_RED
#define BYELLOW ORANGE | BACKGROUND_INTENSITY
#define BINTENSITY BACKGROUND_INTENSITY
void main()
{
/************************************************
* cxHandle Take the HANDLE of the win32 Console *
************************************************/
cxHandle = GetStdHandle (STD_OUTPUT_HANDLE);
/****************************************************
*Call the function to setup the posX, posY, color *
*And print the message... *
*****************************************************/
SetPosXYAndColor(5,5, "Hello World!", YELLOW);
}
/******************************************************************
*It's the function to Set posX, posY, the color And Print the Text*
******************************************************************/
void SetPosXYAndColor(int x, int y, LPSTR Text, WORD Color)
{
/************************************************************
* Declaration of an objet to take the return value *
************************************************************/
DWORD Result;
/************************************************************
*Declaration of an objet to take the posX and posY of cursor*
************************************************************/
COORD cxCoord;
cxCoord.X = x;
cxCoord.Y = y;
/**************************************************
* Setup the color on the screen by the HANDLE *
**************************************************/
SetConsoleTextAttribute(cxHandle, Color);
/*****************************************************
*Setup the CursorPosition on the screen by the HANDLE*
*****************************************************/
SetConsoleCursorPosition(cxHandle, cxCoord);
/************************************************************
* Write the text on the screen whit previous settings *
************************************************************/
WriteConsole(cxHandle, Text, strlen(Text), &Result, NULL);
}
Původní komentáře (3)
Obnoveno z Wayback Machine