#include <windows.h>
const char CLASS_NAME[] = "OverlayWindow";
HBITMAP hBitmap = NULL;
HWND CreateOverlayWindow(HINSTANCE hInstance, int x, int y, int width, int height) {
WNDCLASS wc = {};
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT,
CLASS_NAME,
"Overlay",
WS_POPUP,
x, y,
width, height,
NULL, NULL,
hInstance,
NULL
);
SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
return hwnd;
}
void LoadImageResource() {
hBitmap = (HBITMAP)LoadImage(NULL, "path_to_your_image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
LRESULT CALLBACK OverlayProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
if (hBitmap) {
HDC hMemDC = CreateCompatibleDC(hdc);
SelectObject(hMemDC, hBitmap);
BITMAP bitmap;
GetObject(hBitmap, sizeof(bitmap), &bitmap);
BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight,
hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY:
DeleteObject(hBitmap);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
LoadImageResource();
HWND overlay = CreateOverlayWindow(hInstance, 100, 100, 400, 300);
SetWindowLongPtr(overlay, GWLP_WNDPROC, (LONG_PTR)OverlayProc);
ShowWindow(overlay, SW_SHOW);
UpdateWindow(overlay);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}