Click here to Skip to main content
Click here to Skip to main content

Turn on/off monitor

By , 24 Jul 2005
 

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionmonitor blinksmemberSanjeevCharla6 Feb '13 - 15:42 
QuestionCan this work under remote desktop?membergeorge0880722 Dec '12 - 4:56 
GeneralMy vote of 5membersunny_rajwadi23 May '12 - 0:11 
QuestionReally Turn Off Monitormembernano2k20 Oct '11 - 3:08 
GeneralThank you so much!memberMember 211670621 May '09 - 14:52 
Questionhow to calculate the time between monitor off and onmembersrinag4911 Sep '08 - 17:37 
HI
 
I want to turn off the monitor when ever the user comes out of the client system from the server directly. The client monitor should be 'on' when ever the monitor on/off button is pressed. when the monitor is 'on' the desktop icons should be in disabled, and a login button has to appear for the user to click on it, when ever the user clicks on login then the time has to be calculated from then to the monitor off.
 

Can any one give the c# coding for this along with namespaces that are to be used.
GeneralMonitior control--in Windows xpmembernnuurraa29 Feb '08 - 19:56 
QuestionShall it stay countinously?memberthamizhinpan15 Oct '07 - 7:57 
AnswerRe: Shall it stay countinously?memberDalibor Drzik16 Oct '07 - 1:39 
GeneralRe: Shall it stay countinously?memberkingmax_00718 Nov '07 - 20:09 
GeneralKeeping the Monitor Turned ONmemberSukhjinder_K6 Sep '07 - 6:40 
AnswerRe: Keeping the Monitor Turned ONmemberDalibor Drzik6 Sep '07 - 11:22 
GeneralRe: Keeping the Monitor Turned ONmemberSukhjinder_K7 Sep '07 - 0:33 
Generalkeeping the monitor turned offmemberauldthief13 Jun '07 - 22:36 
Generalplz help!!!membermisha2dope3 Apr '07 - 21:51 
AnswerRe: plz help!!!memberDalibor Drzik4 Apr '07 - 7:50 
QuestionDifference between standby and off?memberoeriksen11 Oct '06 - 12:01 
AnswerRe: Difference between standby and off?memberDalibor Drzik4 Apr '07 - 7:37 
Questioncan't keep blank when mediaplayer playing next songmemberaftcast6 Jul '06 - 7:18 
AnswerRe: can't keep blank when mediaplayer playing next songmemberDalibor Drzik4 Apr '07 - 7:38 
GeneralControl your monitor by softwarememberRobsori13 Jun '06 - 21:25 
GeneralRe: Control your monitor by softwarememberMember 47288042 Jun '08 - 18:12 
GeneralRe: Control your monitor by softwarememberMember 47288042 Jun '08 - 22:08 
GeneralFYIsitebuilderMichael Dunn13 Jun '06 - 8:07 
AnswerRe: FYImemberDalibor Drzik4 Apr '07 - 7:29 

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

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