Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdio.h>
- #include <conio.h>
- #include <conio2.h>
- #include "windows.h"
- #include <string>
- #include <math.h>
- #include <fstream>
- #include <time.h>
- #include <string>
- using namespace std;
- /* Standard error macro for reporting API errors */
- #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
- #define BLUE 1
- #define GREEN 2
- #define CYAN 3
- #define RED 4
- #define PURPLE 5
- #define BROWN 6
- #define LIGHTGREY 7
- #define DARKGREY 8
- #define LIGHTBLUE 9
- #define LIGHTGREEN 10
- #define LIGHTCYAN 11
- #define PINK 12
- #define LIGHTPURPLE 13
- #define YELLOW 14
- #define WHITE 15
- // use x = 35 and y desired height for center.
- /* void PlaceCursor(const int x, const int y) {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD PlaceCursorHere;
- PlaceCursorHere.X = x;
- PlaceCursorHere.Y = y;
- SetConsoleCursorPosition(hConsole, PlaceCursorHere);
- return;
- } */
- void curpos(int x, int y)
- {
- HANDLE hStdout;
- CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
- hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
- GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
- csbiInfo.dwCursorPosition.X=x;
- csbiInfo.dwCursorPosition.Y=y;
- SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
- }
- /*
- COLOR CODES: // in windows.h
- 1 BLUE
- 2 GREEN
- 3 CYAN
- 4 RED
- 5 MAGENTA
- 6 BROWN
- 7 LIGHTGRAY
- 8 DARKGRAY
- 9 LIGHTBLUE
- 10 LIGHTGREEN
- 11 LIGHTCYAN
- 12 LIGHTRED
- 13 LIGHTMAGENTA
- 14 YELLOW
- 15 WHITE
- */
- void setcolor(unsigned int color)
- {
- if (color >15 || color <=0)
- {
- cout <<"Error" <<endl;
- }
- else
- {
- HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hcon,color);
- }
- }
- int GCD(int a, int b)
- {
- while( 1 )
- {
- a = a % b;
- if( a == 0 )
- return b;
- b = b % a;
- if( b == 0 )
- return a;
- }
- }
- void ClearScreen()
- {
- HANDLE hStdOut;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD count;
- DWORD cellCount;
- COORD homeCoords = { 0, 0 };
- hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
- if (hStdOut == INVALID_HANDLE_VALUE) return;
- /* Get the number of cells in the current buffer */
- if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
- cellCount = csbi.dwSize.X *csbi.dwSize.Y;
- /* Fill the entire buffer with spaces */
- if (!FillConsoleOutputCharacter(
- hStdOut,
- (TCHAR) ' ',
- cellCount,
- homeCoords,
- &count
- )) return;
- /* Fill the entire buffer with the current colors and attributes */
- if (!FillConsoleOutputAttribute(
- hStdOut,
- csbi.wAttributes,
- cellCount,
- homeCoords,
- &count
- )) return;
- /* Move the cursor home */
- SetConsoleCursorPosition( hStdOut, homeCoords );
- }
- void SetBackColor(int backC)
- {
- WORD wColor;
- //We will need this handle to get the current forground attribute
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- //We use csbi for the wAttributes word.
- if (GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
- //Mask out all but the forground attribute, and add in the background color
- wColor = (csbi.wAttributes & 0x0F) + ((backC & 0x0F) << 4);
- SetConsoleTextAttribute(hStdOut, wColor);
- }
- }
Add Comment
Please, Sign In to add comment