I’m a user who plays Overwatch. My natural viewing angle is narrow, so when I focus on the am in the middle, I never see the fitness bar. So I created a program that makes the fitness bar in the lower left side of the center positioned on the left side of the ultimate mark so that I can see the fitness bar better than before. But this is only supported in window mode. How can I run it in full screen?
#include <windows.h>
#include <dwmapi.h>
#include <gdiplus.h>
#include <string>
#include <iostream>
#include <thread>
#include <chrono>
#pragma comment (lib, "dwmapi.lib")
#pragma comment (lib, "gdiplus.lib")
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void RealTimeDisplay(HWND hwnd);
void UpdateCaptureBox(RECT& box, int left, int top, int right, int bottom);
// Global variables
RECT captureBox = { 160, 875, 425, 969 };
ULONG_PTR gdiplusToken;
HWND editBox;
POINT clickOffset;
bool running = true;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = L"SimpleDisplayClass";
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TOPMOST,
L"SimpleDisplayClass",
L"Simple Display",
WS_POPUP,
captureBox.left, captureBox.top,
captureBox.right - captureBox.left,
captureBox.bottom - captureBox.top,
nullptr, nullptr, hInstance, nullptr
);
if (!hwnd) {
std::cerr << "Failed to create window." << std::endl;
return -1;
}
// Ensure the window is topmost and transparent
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 255, LWA_ALPHA);
ShowWindow(hwnd, nCmdShow);
std::thread displayThread(RealTimeDisplay, hwnd);
MSG msg = {};
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
running = false;
displayThread.join();
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static bool dragging = false;
static POINT startPoint = {};
switch (uMsg) {
case WM_LBUTTONDOWN:
dragging = true;
SetCapture(hwnd);
GetCursorPos(&startPoint);
ScreenToClient(hwnd, &startPoint);
break;
case WM_MOUSEMOVE:
if (dragging) {
POINT cursorPos;
GetCursorPos(&cursorPos);
RECT windowRect;
GetWindowRect(hwnd, &windowRect);
int dx = cursorPos.x - (windowRect.left + startPoint.x);
int dy = cursorPos.y - (windowRect.top + startPoint.y);
MoveWindow(hwnd, windowRect.left + dx, windowRect.top + dy,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top, TRUE);
}
break;
case WM_LBUTTONUP:
dragging = false;
ReleaseCapture();
break;
case WM_DESTROY:
running = false;
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
void RealTimeDisplay(HWND hwnd) {
while (running) {
HDC hdc = GetDC(hwnd);
HDC screenDC = GetDC(nullptr);
HDC memDC = CreateCompatibleDC(screenDC);
int width = captureBox.right - captureBox.left;
int height = captureBox.bottom - captureBox.top;
HBITMAP hBitmap = CreateCompatibleBitmap(screenDC, width, height);
SelectObject(memDC, hBitmap);
BitBlt(memDC, 0, 0, width, height, screenDC, captureBox.left, captureBox.top, SRCCOPY);
Gdiplus::Graphics graphics(hdc);
Gdiplus::Bitmap bitmap(hBitmap, nullptr);
graphics.DrawImage(&bitmap, 0, 0, width, height);
DeleteObject(hBitmap);
DeleteDC(memDC);
ReleaseDC(nullptr, screenDC);
ReleaseDC(hwnd, hdc);
// Adjust sleep time for 500fps
std::this_thread::sleep_for(std::chrono::microseconds(2000)); // 500fps = 1 frame every 2ms
}
}
void UpdateCaptureBox(RECT& box, int left, int top, int right, int bottom) {
box.left = left;
box.top = top;
box.right = right;
box.bottom = bottom;
}
int main() {
HINSTANCE hInstance = GetModuleHandle(nullptr);
return WinMain(hInstance, nullptr, nullptr, SW_SHOW);
}
user28869872 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4