code
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
CLASS_NAME,
NULL,
WS_POPUP,
0, 0, 0, 0,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == NULL)
{
return 0;
}
// Get the size of each monitor.
std::vector<RECT> vRects;
EnumDisplayMonitors(NULL, NULL, [](HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL
{
RECT rc = *lprcMonitor;
if(lprcMonitor)
{
vRects.push_back(rc);
}
return TRUE;
}, NULL);
// Create the region that spans across all monitors.
HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
for(auto& rc : vRects)
{
CombineRgn(hRgn, hRgn, CreateRectRgnIndirect(&rc), RGN_OR);
}
// Set the layer alpha and color key.
SetLayeredWindowAttributes(hwnd, RGB(255, 255, 255), 0, LWA_COLORKEY | LWA_ALPHA);
// Set the window region to span across all monitors.
SetWindowRgn(hwnd, hRgn, TRUE);
// Show the window.
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;