Click here to Skip to main content
Licence 
First Posted 24 Jul 2005
Views 154,669
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
GeneralMy vote of 5 Pinmembersunny_rajwadi0:11 23 May '12  
QuestionReally Turn Off Monitor Pinmembernano2k3:08 20 Oct '11  
GeneralThank you so much! PinmemberMember 211670614:52 21 May '09  
Questionhow to calculate the time between monitor off and on Pinmembersrinag4917:37 11 Sep '08  
GeneralMonitior control--in Windows xp Pinmembernnuurraa19:56 29 Feb '08  
QuestionShall it stay countinously? Pinmemberthamizhinpan7:57 15 Oct '07  
AnswerRe: Shall it stay countinously? PinmemberDalibor Drzik1:39 16 Oct '07  
GeneralRe: Shall it stay countinously? Pinmemberkingmax_00720:09 18 Nov '07  
GeneralKeeping the Monitor Turned ON PinmemberSukhjinder_K6:40 6 Sep '07  
AnswerRe: Keeping the Monitor Turned ON PinmemberDalibor Drzik11:22 6 Sep '07  
GeneralRe: Keeping the Monitor Turned ON PinmemberSukhjinder_K0:33 7 Sep '07  
Generalkeeping the monitor turned off Pinmemberauldthief22:36 13 Jun '07  
THis looks like a VB forum but I'm sure you guys will be able to help me out here.Please do read on.
I made 2 batch files using poweroff3.0 by Jorgen Bosman and Wizmo By Steve Gibson for the following purpose
 
1.mute and turnoff the monitor -mute with wizmo, turnoff with poweroff
2.unmute and power on monitor - unmute with wizmo, turn on with poweroff
 
the code for the two batch files is
 
-----------------------batch file#1--------------------------
:: monoffmute.bat
:: turn off monitor and mutes sound
::
@ECHO OFF
 
C:\poweroff monitor_off
C:\wizmo mute=1
-----------------------batch file #2-------------------------
::mononsoundon.bat
:: turn on monitor and un-mutes sound
::
@ECHO OFF
 
C:\poweroff monitor_on
C:\wizmo mute=0
 
---------------------------------------------------
I then assigned 2 separate keys on my Pinnacle TV tuner (PCTV plus 110i) for running both above batch files.
My problem is that the monitor turns off from the remote(and green light turns to amber on monitor), but turns back on because TV/VIDEO/MUSIC app is playing.any activity on the screen turns on the monitor.So the trick doesn't work as I envisaged.I want the monitor to stay turned off no matter what it is playing.It should turn on only when i press the button that i programmed to do so! Frown | :( br /> 
How do I achieve that?
 
Thanks a lot for your time
Neelesh Bhagwat
If you have a suggestion please post or mail me on bhagwatnp2@gmail.com

 
Neelesh
"wannabe" HTPC enthusiast
Generalplz help!!! Pinmembermisha2dope21:51 3 Apr '07  
AnswerRe: plz help!!! PinmemberDalibor Drzik7:50 4 Apr '07  
QuestionDifference between standby and off? Pinmemberoeriksen12:01 11 Oct '06  
AnswerRe: Difference between standby and off? PinmemberDalibor Drzik7:37 4 Apr '07  
Questioncan't keep blank when mediaplayer playing next song Pinmemberaftcast7:18 6 Jul '06  
AnswerRe: can't keep blank when mediaplayer playing next song PinmemberDalibor Drzik7:38 4 Apr '07  
GeneralControl your monitor by software PinmemberRobsori21:25 13 Jun '06  
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  

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
Web04 | 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