Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <Windows.h>
- std::string GetHexCode(unsigned char c) {
- std::stringstream ss;
- ss << std::uppercase << std::setw(2) << std::setfill('0') << std::hex;
- ss << +c;
- return ss.str();
- }
- std::string GetHexVal(COLORREF col) {
- return GetHexCode(GetRValue(col)) + GetHexCode(GetGValue(col)) + GetHexCode(GetBValue(col));
- }
- int main()
- {
- std::cout << "System Colour Picker" << std::endl;
- ///// variables for getting the pixel colour from the mouse position /////
- POINT cursor;
- HDC hDc = GetDC(NULL);
- COLORREF col;
- ///// hiding the console cursor /////
- CONSOLE_CURSOR_INFO cursorInfo;
- GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
- cursorInfo.bVisible = false;
- SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
- while (1) {
- GetCursorPos(&cursor);
- col = GetPixel(hDc, cursor.x, cursor.y);
- std::cout << std::hex << "\r#" << GetHexVal(col);
- Sleep(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement