Click here to Skip to main content
Licence 
First Posted 25 Jul 2005
Views 150,201
Downloads 3,520
Bookmarked 57 times

Turn on/off monitor

By Dalibor Drzik | 25 Jul 2005
Sets the state of the display.
3 votes, 8.8%
1

2
3 votes, 8.8%
3
2 votes, 5.9%
4
26 votes, 76.5%
5
4.75/5 - 34 votes
3 removed
μ 4.47, σa 2.16 [?]

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
QuestionReally Turn Off Monitor Pinmembernano2k4:08 20 Oct '11  
GeneralThank you so much! PinmemberMember 211670615:52 21 May '09  
Questionhow to calculate the time between monitor off and on Pinmembersrinag4918:37 11 Sep '08  
GeneralMonitior control--in Windows xp Pinmembernnuurraa20:56 29 Feb '08  
QuestionShall it stay countinously? Pinmemberthamizhinpan8:57 15 Oct '07  
AnswerRe: Shall it stay countinously? PinmemberDalibor Drzik2:39 16 Oct '07  
GeneralRe: Shall it stay countinously? Pinmemberkingmax_00721:09 18 Nov '07  
GeneralKeeping the Monitor Turned ON PinmemberSukhjinder_K7:40 6 Sep '07  
AnswerRe: Keeping the Monitor Turned ON PinmemberDalibor Drzik12:22 6 Sep '07  
GeneralRe: Keeping the Monitor Turned ON PinmemberSukhjinder_K1:33 7 Sep '07  
Generalkeeping the monitor turned off Pinmemberauldthief23:36 13 Jun '07  
Generalplz help!!! Pinmembermisha2dope22:51 3 Apr '07  
AnswerRe: plz help!!! PinmemberDalibor Drzik8:50 4 Apr '07  
QuestionDifference between standby and off? Pinmemberoeriksen13:01 11 Oct '06  
AnswerRe: Difference between standby and off? PinmemberDalibor Drzik8:37 4 Apr '07  
Questioncan't keep blank when mediaplayer playing next song Pinmemberaftcast8:18 6 Jul '06  
AnswerRe: can't keep blank when mediaplayer playing next song PinmemberDalibor Drzik8:38 4 Apr '07  
GeneralControl your monitor by software PinmemberRobsori22:25 13 Jun '06  
GeneralRe: Control your monitor by software PinmemberMember 472880419:12 2 Jun '08  
GeneralRe: Control your monitor by software PinmemberMember 472880423:08 2 Jun '08  
GeneralFYI PinsitebuilderMichael Dunn9:07 13 Jun '06  
AnswerRe: FYI PinmemberDalibor Drzik8:29 4 Apr '07  
QuestionAnd how to turn off harddisk? Pinmemberandreasm822:26 11 Jun '06  
QuestionDetect monitor changes? PinmemberJudge429:43 3 Apr '06  
AnswerRe: Detect monitor changes? PinmemberDalibor Drzik4:11 24 Apr '06  

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.120209.1 | Last Updated 25 Jul 2005
Article Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid