Advertisement
ohusq

Notificaties in c++ console app

Apr 30th, 2024
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #pragma once
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. #define BLACK         0
  7. #define DARK_BLUE     FOREGROUND_BLUE
  8. #define DARK_GREEN    FOREGROUND_GREEN
  9. #define DARK_CYAN     (FOREGROUND_GREEN | FOREGROUND_BLUE)
  10. #define DARK_RED      FOREGROUND_RED
  11. #define DARK_MAGENTA  (FOREGROUND_RED | FOREGROUND_BLUE)
  12. #define DARK_YELLOW   (FOREGROUND_RED | FOREGROUND_GREEN)
  13. #define GRAY          (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
  14. #define DARK_GRAY     (FOREGROUND_INTENSITY)
  15. #define BLUE          (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  16. #define GREEN         (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
  17. #define CYAN          (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  18. #define RED           (FOREGROUND_RED | FOREGROUND_INTENSITY)
  19. #define MAGENTA       (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  20. #define YELLOW        (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY)
  21. #define WHITE         (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
  22.  
  23. void notify(const char* message) {
  24.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  25.     SetConsoleTextAttribute(hConsole, GRAY);
  26.     std::cout << "[?] " << message << std::endl;
  27.     SetConsoleTextAttribute(hConsole, WHITE);
  28. }
  29.  
  30. void alert(const char* message) {
  31.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  32.     SetConsoleTextAttribute(hConsole, RED);
  33.     std::cout << "[!] " << message << std::endl;
  34.     SetConsoleTextAttribute(hConsole, WHITE);
  35. }
  36.  
  37. void success(const char* message) {
  38.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  39.     SetConsoleTextAttribute(hConsole, GREEN);
  40.     std::cout << "[-] " << message << std::endl;
  41.     SetConsoleTextAttribute(hConsole, WHITE);
  42. }
  43.  
  44. void warn(const char* message) {
  45.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  46.     SetConsoleTextAttribute(hConsole, YELLOW);
  47.     std::cout << "[!] " << message << std::endl;
  48.     SetConsoleTextAttribute(hConsole, WHITE);
  49. }
  50.  
  51. const char* userInput(const char* message) {
  52.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  53.     notify(message);
  54.     SetConsoleTextAttribute(hConsole, CYAN);
  55.     std::string input;
  56.     std::getline(std::cin, input);
  57.     SetConsoleTextAttribute(hConsole, WHITE);
  58.     return input.c_str();
  59. }
Tags: cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement