Advertisement
AbsoluteGamer

System Colour Picker

Aug 6th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <Windows.h>
  5.  
  6. std::string GetHexCode(unsigned char c) {
  7.     std::stringstream ss;
  8.     ss << std::uppercase << std::setw(2) << std::setfill('0') << std::hex;
  9.     ss << +c;
  10.     return ss.str();
  11. }
  12.  
  13. std::string GetHexVal(COLORREF col) {
  14.     return GetHexCode(GetRValue(col)) + GetHexCode(GetGValue(col)) + GetHexCode(GetBValue(col));
  15. }
  16.  
  17. int main()
  18. {
  19.     std::cout << "System Colour Picker" << std::endl;
  20.  
  21.     ///// variables for getting the pixel colour from the mouse position /////
  22.     POINT cursor;
  23.     HDC hDc = GetDC(NULL);
  24.     COLORREF col;
  25.  
  26.     ///// hiding the console cursor /////
  27.     CONSOLE_CURSOR_INFO cursorInfo;
  28.     GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
  29.     cursorInfo.bVisible = false;
  30.     SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
  31.  
  32.     while (1) {
  33.         GetCursorPos(&cursor);
  34.         col = GetPixel(hDc, cursor.x, cursor.y);
  35.         std::cout << std::hex << "\r#" << GetHexVal(col);
  36.         Sleep(0);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement