Click here to Skip to main content
Licence 
First Posted 24 Jul 2005
Views 154,611
Bookmarked 58 times

Turn on/off monitor

By | 24 Jul 2005 | Article
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

About the Author

Dalibor Drzik

Web Developer

Slovakia Slovakia

Member

Wink | ;-)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralRe: Control your monitor by software PinmemberMember 472880418:12 2 Jun '08  
GeneralRe: Control your monitor by software PinmemberMember 472880422:08 2 Jun '08  
GeneralFYI PinsitebuilderMichael Dunn8:07 13 Jun '06  
AnswerRe: FYI PinmemberDalibor Drzik7:29 4 Apr '07  
QuestionAnd how to turn off harddisk? Pinmemberandreasm821:26 11 Jun '06  
QuestionDetect monitor changes? PinmemberJudge428:43 3 Apr '06  
AnswerRe: Detect monitor changes? PinmemberDalibor Drzik3:11 24 Apr '06  
WM_POWERBROADCAST
GeneralGood Job! PinmemberJohn R. Shaw16:46 16 Mar '06  
AnswerRe: Good Job! PinmemberDalibor Drzik2:08 17 Mar '06  
QuestionHow to turn off monitor Pinmemberuyencpham10:56 16 Dec '05  
AnswerRe: How to turn off monitor PinmemberDalibor Drzik4:05 18 Dec '05  
GeneralI tried using C# but it wont work , where i am missing PinmemberLalit N Dubey1:38 16 Aug '05  
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberOMalleyW3:12 16 Aug '05  
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberLalit N Dubey18:48 16 Aug '05  
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberDalibor Drzik2:29 18 Aug '05  
GeneralExcellent - but i need it in VB PinsussAnonymous5:59 4 Aug '05  
GeneralRe: Excellent - but i need it in VB PinsussAnonymous6:21 4 Aug '05  
GeneralRe: Excellent - but i need it in VB PinsussAnonymous14:02 4 Aug '05  
GeneralRe: Excellent - but i need it in VB PinsussAnonymous14:36 4 Aug '05  
GeneralRe: Excellent - but i need it in VB Pinsusscodephoenix17:29 1 Oct '05  
GeneralRe: Excellent - but i need it in VB Pinmemberuyencpham11:13 16 Dec '05  
GeneralI had no idea... PinmemberTom Archer6:35 25 Jul '05  
GeneralRe: I had no idea... PinmemberTed Ferenc12:33 25 Jul '05  
GeneralRe: I had no idea... PinmemberTom Archer13:07 25 Jul '05  
GeneralRe: I had no idea... PinmemberDalibor Drzik5:35 26 Jul '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 25 Jul 2005
Article Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid