Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <vector>
- #include <tuple>
- #include <unordered_map>
- #include <variant>
- #include <optional>
- #include <any>
- #include <memory>
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <random>
- #include <utility>
- #include <chrono>
- #include <thread>
- #include <locale>
- #include <codecvt>
- #include <experimental/filesystem>
- #include <Windows.h>
- #include <ObjIdl.h>
- #include <gdiplus.h>
- #include <TlHelp32.h>
- #include <psapi.h>
- #pragma comment(lib, "Gdiplus.lib")
- #pragma comment(lib, "psapi")
- #undef BACKGROUND_INTENSITY
- // ULIB
- namespace ulib
- {
- using namespace std::experimental::filesystem;
- using namespace std::chrono;
- using string = std::wstring;
- using outfile = std::wofstream;
- using infile = std::wifstream;
- using file = std::wfstream;
- using dir = directory_entry;
- using string_content = std::vector<string>;
- using range = std::pair<int, int>;
- using position = std::pair<int, int>;
- using uposition = std::pair<size_t, size_t>;
- using precise_position = std::pair<float, float>;
- using time_ms = int;
- using time_s = double;
- using time_m = double;
- using time_point = system_clock::time_point;
- using point = std::pair<int, int>;
- enum key
- {
- key_null = -1,
- key_0 = 0x30, key_5 = 0x31,
- key_1 = 0x32, key_6 = 0x33,
- key_2 = 0x34, key_7 = 0x35,
- key_3 = 0x36, key_8 = 0x37,
- key_4 = 0x38, key_9 = 0x39,
- key_enter = 0x0D, key_backspace = 0x08,
- key_shift = 0x10, key_control = 0x11,
- key_alt = 0x12, key_tab = 0x09,
- key_escape = 0x1B, key_pause = 0x13,
- key_caps = 0x14, key_space = 0x20,
- key_screenshot = 0x2C, key_print = 0x2A,
- key_insert = 0x2D, key_up = 0x26,
- key_down = 0x28, key_left = 0x25,
- key_right = 0x27, key_cancel = 0x03,
- key_multiply = 0x6A, key_add = 0x6B,
- key_subtract = 0x6C, key_divide = 0x6F,
- key_decimal = 0x6E, key_left_click = 0x01,
- key_right_click = 0x02, key_middle_click = 0x04,
- key_A = 0x41, key_B = 0x42, key_C = 0x43,
- key_D = 0x44, key_E = 0x45, key_F = 0x46,
- key_G = 0x47, key_H = 0x48, key_I = 0x49,
- key_J = 0x4A, key_K = 0x4B, key_L = 0x4C,
- key_M = 0x4D, key_N = 0x4E, key_O = 0x4F,
- key_P = 0x50, key_Q = 0x51, key_R = 0x52,
- key_S = 0x53, key_T = 0x54, key_U = 0x55,
- key_V = 0x56, key_W = 0x57, key_X = 0x58,
- key_Y = 0x59, key_Z = 0x5A,
- click_RIGHT,
- click_LEFT,
- click_MIDDLE,
- };
- std::unordered_map<ulib::string, key> keys
- {
- {L"0", key_0},
- {L"1", key_1},
- {L"2", key_2},
- {L"3", key_3},
- {L"4", key_4},
- {L"5", key_5},
- {L"6", key_6},
- {L"7", key_7},
- {L"8", key_8},
- {L"9", key_9},
- {L"enter", key_enter},
- {L"backspace", key_backspace},
- {L"shift", key_shift},
- {L"control", key_control},
- {L"alt", key_alt},
- {L"tab", key_tab},
- {L"escape", key_escape},
- };
- enum color
- {
- null_color = -1,
- black = 0,
- blue = 1 | 8,
- green = 2 | 8,
- aqua = 3 | 8,
- red = 4 | 8,
- purple = 5 | 8,
- yellow = 6 | 8,
- white = 7 | 8,
- grey = 8 | 8,
- blue_dark = 1,
- green_dark = 2,
- aqua_dark = 3,
- red_dark = 4,
- purple_dark = 5,
- yellow_dark = 6,
- white_dark = 7,
- grey_dark = 8,
- blue_background = 0x0010 | 0x0080,
- blue_dark_background = 0x0010,
- green_background = 0x0020 | 0x0080,
- green_dark_background = 0x0020,
- red_background = 0x0040 | 0x0080,
- red_dark_background = 0x0040,
- teal_background = 0x0010 | 0x0020 | 0x0080,
- teal_dark_background = 0x0010 | 0x0020,
- pink_background = 0x0010 | 0x0040 | 0x0080,
- pink_dark_background = 0x0010 | 0x0040,
- grey_background = 0x0080,
- };
- std::vector<color> colors
- {
- black,
- blue,
- green,
- aqua,
- red,
- purple,
- yellow,
- white,
- grey,
- blue_dark,
- green_dark,
- aqua_dark,
- red_dark,
- purple_dark,
- yellow_dark,
- white_dark,
- grey_dark
- };
- std::vector<color> background_colors
- {
- blue_background,
- blue_dark_background,
- green_background,
- green_dark_background,
- red_background,
- red_dark_background,
- teal_background,
- teal_dark_background,
- pink_background,
- pink_dark_background,
- grey_background
- };
- // Wait
- void Wait(time_ms wait_time)
- {
- std::chrono::system_clock::time_point epoch = std::chrono::system_clock::now();
- std::chrono::duration<double, std::milli> work_time = epoch - epoch;
- while (work_time.count() < wait_time)
- work_time = std::chrono::system_clock::now() - epoch;
- }
- // RandomInt
- int RandomInt(range range = { 0, 100 })
- {
- std::random_device device;
- std::mt19937 engine(device());
- std::uniform_int_distribution<> distribution(range.first, range.second);
- return distribution(engine);
- }
- }
- // FILES
- namespace ulib::files
- {
- #undef CreateDirectory
- #undef CreateFile
- #undef DeleteFile
- struct File
- {
- ulib::path path;
- ulib::string_content content;
- };
- // CheckDirectory
- bool DirectoryCheck(ulib::path path)
- {
- if (ulib::exists(path) && ulib::is_directory(path))
- return true;
- return false;
- }
- // CheckFile
- bool FileCheck(ulib::path path)
- {
- if (ulib::exists(path) && !is_directory(path))
- {
- ulib::infile file(path);
- if (!file.is_open())
- return false;
- file.close();
- return true;
- }
- return false;
- }
- // CreateDirectory
- bool DirectoryCreate(ulib::path path)
- {
- if (DirectoryCheck(path))
- return false;
- ulib::create_directories(path);
- return true;
- }
- // CreateFile
- bool FileCreate(ulib::path path)
- {
- if (!path.has_extension())
- return false;
- if (!DirectoryCheck(path.parent_path()))
- DirectoryCreate(path.parent_path());
- outfile file(path);
- if (!file.is_open())
- return false;
- file.close();
- return true;
- }
- // DeleteFile
- bool FileDelete(ulib::path path)
- {
- if (!FileCheck(path))
- return false;
- std::remove(path.string().c_str());
- if (FileCheck(path))
- return false;
- return true;
- }
- // ReadFile
- string_content FileRead(const ulib::path& path)
- {
- if (!FileCheck(path))
- return { L"\0" };
- ulib::string_content content;
- ulib::infile file(path);
- ulib::string line;
- while (std::getline(file, line))
- content.emplace_back(line);
- file.close();
- return content;
- }
- // WriteFile
- bool FileWrite(ulib::path path, ulib::string_content content)
- {
- if (!FileCheck(path))
- return false;
- outfile file(path);
- for (auto& line : content)
- file << line << L"\n";
- file.close();
- return true;
- }
- // IterateDirectory
- std::vector<path> DirectoryRead(path path)
- {
- if (!DirectoryCheck(path))
- return {};
- std::vector<ulib::path> dirs;
- for (auto& dir : ulib::directory_iterator(path))
- {
- if (DirectoryCheck(dir))
- for (auto& file : directory_iterator(dir))
- dirs.emplace_back(file);
- else
- dirs.emplace_back(dir);
- }
- return dirs;
- }
- }
- // IO
- namespace ulib::io
- {
- #undef PlaySound
- // Print
- void Print(ulib::string msg)
- {
- std::wcout << msg << L"\n";
- }
- // GetCursorPosition
- point GetCursorPosition()
- {
- POINT cursor_pos;
- GetCursorPos(&cursor_pos);
- return point(cursor_pos.x, cursor_pos.y);
- }
- // SetCursorPosition
- void SetCursorPosition(point pos)
- {
- SetCursorPos(pos.first, pos.second);
- }
- // IsKeyDown
- bool IsKeyDown(ulib::key key, ulib::key modifier)
- {
- if (modifier != ulib::key_null && GetKeyState(key) & 0x8000 && GetAsyncKeyState(modifier) & 0x8000)
- {
- FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
- return true;
- }
- else if (modifier == ulib::key_null && GetKeyState(key) & 0x8000)
- {
- FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
- return true;
- }
- return false;
- }
- // IsKeyUp
- bool IsKeyUp(ulib::key key)
- {
- if (GetKeyState(key) == 0)
- return true;
- return false;
- }
- // KeyPress
- void KeyPress(ulib::key key, HWND window = NULL, time_ms time = 20)
- {
- if (window != NULL)
- switch (key)
- {
- case click_LEFT:
- PostMessage(window, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- Wait((DWORD)time);
- PostMessage(window, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- break;
- case click_RIGHT:
- PostMessage(window, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- Wait((DWORD)time);
- PostMessage(window, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- break;
- case click_MIDDLE:
- PostMessage(window, WM_MBUTTONDOWN, MK_MBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- Wait((DWORD)time);
- PostMessage(window, WM_MBUTTONUP, MK_MBUTTON, MAKELPARAM(GetCursorPosition().first, GetCursorPosition().second));
- break;
- default:
- PostMessage(window, WM_KEYDOWN, key, 0);
- Sleep((DWORD)time);
- PostMessage(window, WM_KEYUP, key, 0);
- break;
- }
- else
- switch (key)
- {
- case click_LEFT:
- mouse_event(MOUSEEVENTF_LEFTDOWN, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- Sleep((DWORD)time);
- mouse_event(MOUSEEVENTF_LEFTUP, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- break;
- case click_RIGHT:
- mouse_event(MOUSEEVENTF_RIGHTDOWN, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- Sleep((DWORD)time);
- mouse_event(MOUSEEVENTF_RIGHTUP, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- break;
- case click_MIDDLE:
- mouse_event(MOUSEEVENTF_MIDDLEDOWN, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- Sleep((DWORD)time);
- mouse_event(MOUSEEVENTF_MIDDLEUP, GetCursorPosition().first, GetCursorPosition().second, 0, 0);
- break;
- default:
- INPUT ip;
- ip.type = INPUT_KEYBOARD;
- ip.ki.wScan = 0;
- ip.ki.time = 0;
- ip.ki.dwExtraInfo = 0;
- ip.ki.wVk = key;
- ip.ki.dwFlags = 0;
- SendInput(1, &ip, sizeof(INPUT));
- Sleep(20);
- ip.ki.dwFlags = KEYEVENTF_KEYUP;
- SendInput(1, &ip, sizeof(INPUT));
- break;
- }
- }
- // KeyDown
- // KeyUp
- // MouseClick
- // MouseDown
- // MouseUp
- }
- // PARSING
- namespace ulib::parsing
- {
- enum parse_flag
- {
- PREFIX,
- POSTFIX,
- INFIX,
- };
- // ParseIndentation
- int ParseIndentation(string line)
- {
- int count = 0;
- for (auto& char_in : line)
- if (char_in == L' ')
- count++;
- return count;
- }
- // Parse
- string Parse(const string& token, const string& line, parse_flag flag = PREFIX)
- {
- switch (flag)
- {
- case PREFIX:
- if (line.find(token) != line.npos)
- return line.substr(line.find(token) + token.length());
- break;
- case POSTFIX:
- if (line.find(token) != line.npos)
- return line.substr(0, line.find(token));
- break;
- case INFIX:
- if (line.find(token) != line.npos && line.substr(line.find(token) + 1).find(token) != line.npos)
- return line.substr(line.find(token) + token.length(), line.substr(line.find(token) + token.length()).find(token));
- break;
- }
- return L"\0";
- }
- // Parse - Overload
- string Parse(const string& token, const string_content& lines)
- {
- for (auto& line : lines)
- if (line.find(token) != line.npos)
- return line.substr(line.find(token) + token.length());
- return L"\0";
- }
- // Parse - Overload
- string_content ParseAll(const string& token, const string_content& lines)
- {
- string_content parsed{};
- for (auto& line : lines)
- if (line.find(token) != line.npos)
- parsed.emplace_back(line.substr(line.find(token) + token.length()));
- return parsed;
- }
- // AsInt
- int AsInt(string text)
- {
- return std::stoi(text);
- }
- // AsFloat
- float AsFloat(string text)
- {
- return std::stof(text);
- }
- }
- // CONSOLE
- namespace ulib::console
- {
- class Console
- {
- private:
- HANDLE write_handle, read_handle, input_handle;
- SMALL_RECT window_size, write_area;
- COORD char_buffer_size, char_position;
- std::vector<CHAR_INFO> buffer;
- public:
- ulib::color foreground_color, background_color;
- COORD buffer_size;
- int line;
- Console(std::string name = "Application", ulib::position size = { 25, 25 }, ulib::color foreground_color = ulib::color::white, ulib::color background_color = ulib::color::black)
- : write_handle(GetStdHandle(STD_OUTPUT_HANDLE))
- , read_handle(GetStdHandle(STD_OUTPUT_HANDLE))
- , input_handle(GetStdHandle(STD_INPUT_HANDLE))
- , window_size({ 0, 0, (SHORT)size.first - 1, (SHORT)size.second - 1 })
- , buffer_size({ (SHORT)size.first, (SHORT)size.second })
- , char_buffer_size({ (SHORT)size.first, (SHORT)size.second })
- , char_position({ 0, 0 })
- , buffer(size.first * size.second)
- , write_area({ 0, 0, (SHORT)size.first - 1, (SHORT)size.second - 1 })
- , foreground_color(foreground_color)
- , background_color(background_color)
- , line(0)
- {
- //HWND console = GetConsoleWindow();
- //ShowWindow(console, 10);
- SetConsoleOutputCP(CP_UTF8);
- SetConsoleCP(CP_UTF8);
- SetConsoleTitle(name.c_str());
- show_cursor(false);
- SetConsoleWindowInfo(write_handle, TRUE, &window_size);
- SetConsoleScreenBufferSize(write_handle, buffer_size);
- clear();
- }
- // Clear
- void clear()
- {
- line = 0;
- for (int y = 0; y < buffer_size.Y; ++y)
- for (int x = 0; x < buffer_size.X; ++x)
- {
- buffer[x + buffer_size.X * y].Char.UnicodeChar = L' ';
- buffer[x + buffer_size.X * y].Char.AsciiChar = ' ';
- buffer[x + buffer_size.X * y].Attributes = background_color;
- }
- }
- // Display
- void display()
- {
- WriteConsoleOutputW(write_handle, buffer.data(), char_buffer_size, char_position, &write_area);
- }
- // Draw
- void draw(wchar_t character, ulib::position pos = { 0, 0 }, ulib::color foreground = ulib::color::null_color, ulib::color background = ulib::color::null_color)
- {
- if (foreground == ulib::color::null_color)
- foreground = foreground_color;
- if (background == ulib::color::null_color)
- background = background_color;
- buffer[pos.first + buffer_size.X * pos.second].Char.UnicodeChar = character;
- buffer[pos.first + buffer_size.X * pos.second].Attributes = foreground | background;
- pos.first++;
- }
- // Draw - Overload
- void draw(const ulib::string& string, ulib::position pos = { 0, 0 }, ulib::color foreground = ulib::color::null_color, ulib::color background = ulib::color::null_color)
- {
- if (foreground == ulib::color::null_color)
- foreground = foreground_color;
- if (background == ulib::color::null_color)
- background = background_color;
- for (const auto& chr : string)
- {
- buffer[pos.first + buffer_size.X * pos.second].Char.UnicodeChar = chr;
- buffer[pos.first + buffer_size.X * pos.second].Attributes = foreground | background;
- pos.first++;
- }
- }
- // Draw - Overload
- void draw(const ulib::string_content& strings, ulib::position pos = { 0, 0 }, unsigned short attributes = 0)
- {
- if (attributes == 0)
- attributes = background_color;
- int default_posx = pos.first;
- for (const auto& str : strings)
- {
- for (const auto chr : str)
- {
- buffer[pos.first + buffer_size.X * pos.second].Char.UnicodeChar = chr;
- buffer[pos.first + buffer_size.X * pos.second].Attributes = attributes;
- pos.first++;
- }
- pos.first = default_posx;
- pos.second++;
- }
- }
- // Print - Overload
- void print(const ulib::string& string = L"", ulib::color foreground = ulib::color::null_color, ulib::color background = ulib::color::null_color, ulib::position pos = { 0, 0 })
- {
- if (foreground == ulib::color::null_color)
- foreground = foreground_color;
- if (background == ulib::color::null_color)
- background = background_color;
- if (pos.second == 0)
- pos.second = line;
- else
- line = pos.second;
- for (auto& chr : string)
- {
- buffer[pos.first + buffer_size.X * pos.second].Char.UnicodeChar = chr;
- buffer[pos.first + buffer_size.X * pos.second].Attributes = foreground | background;
- pos.first++;
- }
- line++;
- display();
- }
- // Print - Overload
- void print(std::string string, ulib::color foreground = ulib::color::null_color, ulib::color background = ulib::color::null_color, ulib::position pos = { 0, 0 })
- {
- if (foreground == ulib::color::null_color)
- foreground = foreground_color;
- if (background == ulib::color::null_color)
- background = background_color;
- if (pos.second == 0)
- pos.second = line;
- else
- line = pos.second;
- for (auto& chr : string)
- {
- buffer[pos.first + buffer_size.X * pos.second].Char.AsciiChar = chr;
- buffer[pos.first + buffer_size.X * pos.second].Attributes = foreground | background;
- pos.first++;
- }
- line++;
- display();
- }
- // SetCursorPos
- void set_cursor(ulib::position pos)
- {
- SetConsoleCursorPosition(write_handle, { (SHORT)pos.first, (SHORT)pos.second });
- }
- // ShowCursorPos
- void show_cursor(bool to_show)
- {
- CONSOLE_CURSOR_INFO cursorInfo;
- GetConsoleCursorInfo(write_handle, &cursorInfo);
- cursorInfo.bVisible = to_show;
- SetConsoleCursorInfo(write_handle, &cursorInfo);
- }
- };
- }
- // SCREEN
- namespace ulib::screen
- {
- struct Color
- {
- int r, g, b;
- const bool operator==(const Color& other) const
- {
- if (r == other.r && g == other.g && b == other.b)
- return true;
- return false;
- }
- bool operator!=(const Color& other) const
- {
- if (r != other.r || g != other.g || b == other.b)
- return true;
- return false;
- }
- };
- struct Pixel
- {
- point pos;
- Color color;
- bool operator==(const Pixel& pixel) const
- {
- if (color == pixel.color && pos == pixel.pos)
- return true;
- return false;
- }
- bool operator!=(const Pixel& pixel) const
- {
- if (color != pixel.color || pos != pixel.pos)
- return true;
- return false;
- }
- };
- class Screen
- {
- private:
- int width, height;
- HDC screen, screen_mem;
- HBITMAP bitmap_handle;
- HGDIOBJ oldbitmap_handle;
- BITMAPINFO bi;
- public:
- Screen(int width = GetSystemMetrics(SM_CXSCREEN), int height = GetSystemMetrics(SM_CYSCREEN))
- : width(width)
- , height(height)
- , screen(GetDC(0))
- , screen_mem(CreateCompatibleDC(screen))
- , bitmap_handle(CreateCompatibleBitmap(screen, width, height))
- , oldbitmap_handle(SelectObject(screen_mem, bitmap_handle))
- , bi({ 0 })
- {
- BitBlt(screen_mem, 0, 0, width, height, screen, 0, 0, SRCCOPY | CAPTUREBLT);
- SelectObject(screen_mem, oldbitmap_handle);
- DeleteDC(screen_mem);
- bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
- bi.bmiHeader.biWidth = width;
- bi.bmiHeader.biHeight = -height;
- bi.bmiHeader.biBitCount = 32;
- bi.bmiHeader.biPlanes = 1;
- bi.bmiHeader.biCompression = BI_RGB;
- }
- ~Screen()
- {
- DeleteObject(bitmap_handle);
- ReleaseDC(NULL, screen);
- }
- void refresh()
- {
- DeleteObject(bitmap_handle);
- ReleaseDC(NULL, screen);
- screen = GetDC(0);
- screen_mem = CreateCompatibleDC(screen);
- bitmap_handle = CreateCompatibleBitmap(screen, width, height);
- oldbitmap_handle = SelectObject(screen_mem, bitmap_handle);
- BitBlt(screen_mem, 0, 0, width, height, screen, 0, 0, SRCCOPY | CAPTUREBLT);
- SelectObject(screen_mem, oldbitmap_handle);
- DeleteDC(screen_mem);
- }
- void set_pixel(point pos, Color color)
- {
- SetPixel(screen, pos.first, pos.second, RGB(color.r, color.g, color.b));
- }
- Pixel get_pixel(point pos) const
- {
- std::vector<BYTE> colormap(height * width * 4);
- BITMAPINFO info = bi;
- if (0 != GetDIBits(screen, bitmap_handle, 0, height, colormap.data(), &info, DIB_RGB_COLORS))
- {
- int index = (pos.second * width + pos.first) * 4;
- Pixel pixel{ pos, Color{std::stoi(std::to_string(colormap.data()[index + 2])), std::stoi(std::to_string(colormap.data()[index + 1])), std::stoi(std::to_string(colormap.data()[index + 0]))} };
- return pixel;
- }
- return Pixel{};
- }
- bool match_pixel(const Pixel& pixel) const
- {
- if (pixel == get_pixel(pixel.pos))
- return true;
- return false;
- }
- };
- }
- // WINDOW
- namespace ulib::window
- {
- class Overlay
- {
- private:
- std::string class_name;
- HWND hwnd;
- WNDCLASSEX wc;
- MSG Msg;
- Gdiplus::GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- public:
- Overlay(std::string name)
- : class_name(name)
- {
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandle(0);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(1, 0, 0)));//(COLOR_WINDOW + 1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = class_name.c_str();
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&wc))
- MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- hwnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST, class_name.c_str(), class_name.c_str(), NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, GetModuleHandle(NULL), NULL);
- SetLayeredWindowAttributes(hwnd, RGB(1, 0, 0), 255, LWA_COLORKEY | LWA_ALPHA);
- if (hwnd == NULL)
- MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- ShowWindow(hwnd, 10);
- UpdateWindow(hwnd);
- while (GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- }
- ~Overlay()
- {
- Gdiplus::GdiplusShutdown(gdiplusToken);
- }
- static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- BOOL draw = false;
- POINT prev{ 0, 0 };
- switch (msg)
- {
- case WM_LBUTTONDOWN:
- draw = true;
- prev.x = LOWORD(lParam);
- prev.y = HIWORD(lParam);
- return 0L;
- break;
- case WM_LBUTTONUP:
- if (draw)
- {
- draw = true;
- prev.x = LOWORD(lParam);
- prev.y = HIWORD(lParam);
- }
- draw = false;
- return 0L;
- break;
- case WM_MOUSEMOVE:
- if (draw)
- {
- hdc = GetDC(hwnd);
- HPEN pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
- HPEN oldPen = (HPEN)SelectObject(hdc, pen);
- MoveToEx(hdc, prev.x, prev.y, NULL);
- LineTo(hdc, prev.x = LOWORD(lParam), prev.y = HIWORD(lParam));
- }
- return 0L;
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
- OnPaint(hdc);
- EndPaint(hwnd, &ps);
- ReleaseDC(hwnd, hdc);
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- static VOID OnPaint(HDC hdc)
- {
- Gdiplus::Graphics graphics(hdc);
- Gdiplus::Pen blackPen(Gdiplus::Color(255, 0, 0, 0), 5);
- Gdiplus::FontFamily fontFamily(L"Times New Roman");
- Gdiplus::SolidBrush blue_brush(Gdiplus::Color(255, 0, 0, 255));
- Gdiplus::SolidBrush green_brush(Gdiplus::Color(255, 0, 255, 0));
- Gdiplus::SolidBrush black_brush(Gdiplus::Color(255, 0, 0, 0));
- Gdiplus::Font header_font(&fontFamily, 20, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
- Gdiplus::Font text_font(&fontFamily, 15, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
- graphics.DrawRectangle(&blackPen, 2, 2, 100, 400);
- graphics.DrawString(L"Action:", -1, &header_font, Gdiplus::PointF{ 05.0f, 05.0f }, &blue_brush);
- graphics.DrawString(L"-", -1, &header_font, Gdiplus::PointF{ 05.0f, 20.0f }, &black_brush);
- graphics.DrawString(L"Mode:", -1, &header_font, Gdiplus::PointF{ 05.0f, 55.0f }, &blue_brush);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement