Guest User

Untitled

a guest
Oct 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <conio2.h>
  6. #include "windows.h"
  7. #include <string>
  8. #include <math.h>
  9. #include <fstream>
  10. #include <time.h>
  11. #include <string>
  12. using namespace std;
  13. /* Standard error macro for reporting API errors */
  14. #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
  15. #define BLUE 1
  16. #define GREEN 2
  17. #define CYAN 3
  18. #define RED 4
  19. #define PURPLE 5
  20. #define BROWN 6
  21. #define LIGHTGREY 7
  22. #define DARKGREY 8
  23. #define LIGHTBLUE 9
  24. #define LIGHTGREEN 10
  25. #define LIGHTCYAN 11
  26. #define PINK 12
  27. #define LIGHTPURPLE 13
  28. #define YELLOW 14
  29. #define WHITE 15
  30.  
  31. // use x = 35 and y desired height for center.
  32. /* void PlaceCursor(const int x, const int y) {
  33.  
  34. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  35.  
  36. COORD PlaceCursorHere;
  37. PlaceCursorHere.X = x;
  38. PlaceCursorHere.Y = y;
  39.  
  40. SetConsoleCursorPosition(hConsole, PlaceCursorHere);
  41. return;
  42. } */
  43.  
  44. void curpos(int x, int y)
  45. {
  46. HANDLE hStdout;
  47. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  48. hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
  49. GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
  50. csbiInfo.dwCursorPosition.X=x;
  51. csbiInfo.dwCursorPosition.Y=y;
  52. SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
  53. }
  54. /*
  55. COLOR CODES: // in windows.h
  56. 1 BLUE
  57. 2 GREEN
  58. 3 CYAN
  59. 4 RED
  60. 5 MAGENTA
  61. 6 BROWN
  62. 7 LIGHTGRAY
  63. 8 DARKGRAY
  64. 9 LIGHTBLUE
  65. 10 LIGHTGREEN
  66. 11 LIGHTCYAN
  67. 12 LIGHTRED
  68. 13 LIGHTMAGENTA
  69. 14 YELLOW
  70. 15 WHITE
  71. */
  72. void setcolor(unsigned int color)
  73. {
  74. if (color >15 || color <=0)
  75. {
  76. cout <<"Error" <<endl;
  77.  
  78. }
  79. else
  80. {
  81. HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  82. SetConsoleTextAttribute(hcon,color);
  83. }
  84. }
  85. int GCD(int a, int b)
  86. {
  87. while( 1 )
  88. {
  89. a = a % b;
  90. if( a == 0 )
  91. return b;
  92. b = b % a;
  93.  
  94. if( b == 0 )
  95. return a;
  96. }
  97. }
  98.  
  99. void ClearScreen()
  100. {
  101. HANDLE hStdOut;
  102. CONSOLE_SCREEN_BUFFER_INFO csbi;
  103. DWORD count;
  104. DWORD cellCount;
  105. COORD homeCoords = { 0, 0 };
  106.  
  107. hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  108. if (hStdOut == INVALID_HANDLE_VALUE) return;
  109.  
  110. /* Get the number of cells in the current buffer */
  111. if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  112. cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  113.  
  114. /* Fill the entire buffer with spaces */
  115. if (!FillConsoleOutputCharacter(
  116. hStdOut,
  117. (TCHAR) ' ',
  118. cellCount,
  119. homeCoords,
  120. &count
  121. )) return;
  122.  
  123. /* Fill the entire buffer with the current colors and attributes */
  124. if (!FillConsoleOutputAttribute(
  125. hStdOut,
  126. csbi.wAttributes,
  127. cellCount,
  128. homeCoords,
  129. &count
  130. )) return;
  131.  
  132. /* Move the cursor home */
  133. SetConsoleCursorPosition( hStdOut, homeCoords );
  134. }
  135.  
  136. void SetBackColor(int backC)
  137. {
  138. WORD wColor;
  139. //We will need this handle to get the current forground attribute
  140. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  141. CONSOLE_SCREEN_BUFFER_INFO csbi;
  142. //We use csbi for the wAttributes word.
  143.  
  144. if (GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
  145. //Mask out all but the forground attribute, and add in the background color
  146. wColor = (csbi.wAttributes & 0x0F) + ((backC & 0x0F) << 4);
  147. SetConsoleTextAttribute(hStdOut, wColor);
  148. }
  149. }
Add Comment
Please, Sign In to add comment