Turn the Monitor Screen off in Windows

2013 年 06 月 29 日

Sometimes we would like to turn off the screeen immediately. But it seems that there is not a very convenient command or tool to do it under windows.

This should be a very simple operation and a search from google shows that it could be accomplished by broadcasting a WM_SYSCOMMAND message:

PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

Here is a project with Makefile and compiled with MinGW.

https://github.com/xianghuzhao/mirror

The -mwindows link option is used to hide the console window.