Turn on/off monitor






4.77/5 (40 votes)
Jul 25, 2005

357388

14982
Sets the state of the display.
Introduction
The SendMessage
function is useful to handle monitor states - the display is going to low power, the display is being shut off and the display is turned on.
Code explanation
While using SendMessage
function, you have to set four parameters:
hWnd
Handle to the window whose window procedure will receive the message. If you don't want to bother creating a window to send the message to, you can send the message to all top level windows (
HWND_BROADCAST
) or you can useGetDesktopWindow
function sending the message to the desktop window.Msg
Specifies the message to be sent (
WM_SYSCOMMAND
).wParam
Specifies additional message-specific information (
SC_MONITORPOWER
).lParam
- 1 - the display is going to low power.
- 2 - the display is being shut off.
- -1 - the display is being turned on (undocumented value).
// Turn off monitor Sleep(500); // Eliminate user's interaction for 500 ms SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2); // Turn on monitor SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1); // Low power monitor Sleep(500); // Eliminate user's interaction for 500 ms SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 1);