Click here to Skip to main content
15,883,709 members
Articles / Programming Languages / C++
Article

Turn on/off monitor

Rate me:
Please Sign up or sign in to vote.
4.77/5 (43 votes)
24 Jul 2005 349K   14.9K   75   61
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 use GetDesktopWindow 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);

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Slovakia Slovakia
Wink | ;-)

Comments and Discussions

 
GeneralRe: Excellent - but i need it in VB Pin
Anonymous4-Aug-05 14:36
Anonymous4-Aug-05 14:36 
GeneralRe: Excellent - but i need it in VB Pin
codephoenix1-Oct-05 17:29
codephoenix1-Oct-05 17:29 
GeneralRe: Excellent - but i need it in VB Pin
uyencpham16-Dec-05 11:13
uyencpham16-Dec-05 11:13 
GeneralI had no idea... Pin
Tom Archer25-Jul-05 6:35
Tom Archer25-Jul-05 6:35 
GeneralRe: I had no idea... Pin
Ted Ferenc25-Jul-05 12:33
Ted Ferenc25-Jul-05 12:33 
GeneralRe: I had no idea... Pin
Tom Archer25-Jul-05 13:07
Tom Archer25-Jul-05 13:07 
GeneralRe: I had no idea... Pin
Dalibor Drzik26-Jul-05 5:35
Dalibor Drzik26-Jul-05 5:35 
GeneralRe: I had no idea... Pin
Dalibor Drzik26-Jul-05 5:29
Dalibor Drzik26-Jul-05 5:29 
GeneralGreat Pin
Danila Korablin25-Jul-05 6:09
Danila Korablin25-Jul-05 6:09 
GeneralRe: Great Pin
Dalibor Drzik26-Jul-05 5:25
Dalibor Drzik26-Jul-05 5:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.