Skip to content

Instantly share code, notes, and snippets.

@itsTyrion
Last active May 7, 2026 04:46
Show Gist options
  • Select an option

  • Save itsTyrion/86988c20319b69b280d7f8cbfaa83aa3 to your computer and use it in GitHub Desktop.

Select an option

Save itsTyrion/86988c20319b69b280d7f8cbfaa83aa3 to your computer and use it in GitHub Desktop.
1x1 black pixel overlay to workaround my issue of HDR video briefly flickering when cursor auto-hides/reappears or leaves/enters main screen
#include <windows.h>
#define IDM_EXIT 1001
#define WM_TRAYICON (WM_USER + 1)
static NOTIFYICONDATA nid;
static HMENU tray_menu;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)GetStockObject(BLACK_BRUSH));
EndPaint(hwnd, &ps);
return 0;
}
case WM_TRAYICON:
if (lp == WM_RBUTTONUP) {
POINT pt;
GetCursorPos(&pt);
SetForegroundWindow(hwnd);
TrackPopupMenu(tray_menu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);
}
return 0;
case WM_COMMAND:
if (LOWORD(wp) == IDM_EXIT) {
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
}
return 0;
case WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) {
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInst;
wc.lpszClassName = "HDRFix";
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
WS_EX_TOPMOST | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE,
"HDRFix", NULL, WS_POPUP,
0, 0, 1, 1,
NULL, NULL, hInst, NULL
);
ShowWindow(hwnd, SW_SHOWNOACTIVATE);
UpdateWindow(hwnd);
/* Tray icon */
tray_menu = CreatePopupMenu();
AppendMenu(tray_menu, MF_STRING, IDM_EXIT, "Exit HDRFix");
nid.cbSize = sizeof(nid);
nid.hWnd = hwnd;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid.uCallbackMessage = WM_TRAYICON;
nid.hIcon = LoadIcon(NULL, IDI_APPLICATION);
lstrcpy(nid.szTip, "HDRFix - right-click to exit");
Shell_NotifyIcon(NIM_ADD, &nid);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
@itsTyrion

itsTyrion commented May 7, 2026

Copy link
Copy Markdown
Author

compiled with
cl hdrfix.c /O2 /Fe:HDRFix.exe /link user32.lib gdi32.lib shell32.lib or
x86_64-w64-mingw32-gcc -O2 -mwindows -o HDRFix.exe hdrfix.c -lshell32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment