Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // Code by: Justin (Code Monkey)
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <string>
  5.  
  6.  
  7. // This is our function that will change the text color of the text passed in
  8. void g_ColorText(std::string, WORD);
  9.  
  10. int main() {
  11.  
  12. g_ColorText("Hello World", FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
  13.  
  14. return 0;
  15. }
  16.  
  17. // This is our function that will change the text color of the text passed in
  18. void g_ColorText(std::string text_message, WORD text_color) {
  19. // This is our handle to our output device (monitor)
  20. // But before we use the output_handle we need to initialize it,
  21. // so we get the standard handle and set it to the standard output
  22. // handled device
  23. HANDLE output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
  24.  
  25. // This is our default color so that after the we change the text
  26. // we can change it back to the default dos console color
  27. WORD default_dos_color = FOREGROUND_RED |
  28. FOREGROUND_GREEN |
  29. FOREGROUND_BLUE |
  30. FOREGROUND_INTENSITY;
  31.  
  32. // Here we pass in the output_handle and the text_color that we want
  33. // the text to look like. This function changes the dos text colors.
  34. // Its like as if yoou went to the DOS properties and change the colors
  35. // mannualy. But this function lets you set the text attributes for the
  36. // program so you don't have to tell the player/user of it to change
  37. // the colors. = ]
  38. SetConsoleTextAttribute(output_handle, text_color);
  39.  
  40. std::cout << text_message << std::endl;
  41.  
  42. // Simply sets every thing back to normal
  43. SetConsoleTextAttribute(output_handle, default_dos_color);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement