Skip to content

Instantly share code, notes, and snippets.

@sgqy
Last active September 22, 2021 14:00
Show Gist options
  • Save sgqy/37653e1c50fefe20d34852348397e2fc to your computer and use it in GitHub Desktop.
Save sgqy/37653e1c50fefe20d34852348397e2fc to your computer and use it in GitHub Desktop.
Keep Windows screen on, no mater what weird-and-hidden power configs it uses.
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#ifdef MB_DEBUG
#define INTERVAL (500)
#else
#define INTERVAL (30 * 1000)
#endif
#ifdef MB_DEBUG
void __cdecl popup_num(const DWORD val)
{
wchar_t msg[300] = { 0 };
wsprintfW(msg, L"%08X", val);
MessageBoxW(0, msg, L"", MB_OK);
}
#endif
int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int cmdShow)
{
while(TRUE)
{
EXECUTION_STATE esRet = SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_AWAYMODE_REQUIRED);
#ifdef MB_DEBUG
popup_num(esRet);
#endif
Sleep(INTERVAL);
}
SetThreadExecutionState(ES_CONTINUOUS);
return 0;
}
#CC_DEFS = /DMB_DEBUG
CC_ARGS = /nologo /utf-8 /c /W3 /Ox /Zo- /GL /MT
LD_ARGS = /nologo /ltcg
LD_LIBS = user32.lib
all: awake.exe
awake.exe: awake.obj
link $(LD_ARGS) /out:$@ $** $(LD_LIBS)
awake.obj: awake.c
cl $(CC_ARGS) $(CC_DEFS) /Fo$@ $**
.PHONY: run
run: awake.exe
start "" /d C: /low $**
.PHONY: clean
clean:
del /f awake.obj
del /f awake.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment