How do I get a specific window to float over a full-screen running game?

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);
}

New contributor

user28869872 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật