Click here to Skip to main content
11,714,345 members (88,851 online)
Click here to Skip to main content

Tagged as

Turn on/off monitor

, 24 Jul 2005 208.9K 8.4K 66
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Dalibor Drzik
Web Developer
Slovakia Slovakia
Wink | ;-)

You may also be interested in...

Comments and Discussions

 
Question[Virus(Worm)] Download demo project - 2.81 Kb Pin
Member 1193673525-Aug-15 23:27
memberMember 1193673525-Aug-15 23:27 
AnswerRe: [Virus(Worm)] Download demo project - 2.81 Kb Pin
Member 1193673525-Aug-15 23:56
memberMember 1193673525-Aug-15 23:56 
QuestionRequest_To_Elaborate_Code Pin
Member 815523825-Dec-13 2:51
memberMember 815523825-Dec-13 2:51 
Questionmonitor blinks Pin
SanjeevCharla6-Feb-13 15:42
memberSanjeevCharla6-Feb-13 15:42 
QuestionCan this work under remote desktop? Pin
george0880722-Dec-12 4:56
membergeorge0880722-Dec-12 4:56 
GeneralMy vote of 5 Pin
sunny_rajwadi23-May-12 0:11
membersunny_rajwadi23-May-12 0:11 
QuestionReally Turn Off Monitor Pin
nano2k20-Oct-11 3:08
membernano2k20-Oct-11 3:08 
GeneralThank you so much! Pin
Member 211670621-May-09 14:52
memberMember 211670621-May-09 14:52 
Questionhow to calculate the time between monitor off and on Pin
srinag4911-Sep-08 17:37
membersrinag4911-Sep-08 17:37 
GeneralMonitior control--in Windows xp Pin
nnuurraa29-Feb-08 19:56
membernnuurraa29-Feb-08 19:56 
QuestionShall it stay countinously? Pin
thamizhinpan15-Oct-07 7:57
memberthamizhinpan15-Oct-07 7:57 
AnswerRe: Shall it stay countinously? Pin
Dalibor Drzik16-Oct-07 1:39
memberDalibor Drzik16-Oct-07 1:39 
GeneralRe: Shall it stay countinously? Pin
kingmax_00718-Nov-07 20:09
memberkingmax_00718-Nov-07 20:09 
GeneralKeeping the Monitor Turned ON Pin
Sukhjinder_K6-Sep-07 6:40
memberSukhjinder_K6-Sep-07 6:40 
AnswerRe: Keeping the Monitor Turned ON Pin
Dalibor Drzik6-Sep-07 11:22
memberDalibor Drzik6-Sep-07 11:22 
GeneralRe: Keeping the Monitor Turned ON Pin
Sukhjinder_K7-Sep-07 0:33
memberSukhjinder_K7-Sep-07 0:33 
Generalkeeping the monitor turned off Pin
auldthief13-Jun-07 22:36
memberauldthief13-Jun-07 22:36 
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! :(

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!!! Pin
misha2dope3-Apr-07 21:51
membermisha2dope3-Apr-07 21:51 
AnswerRe: plz help!!! Pin
Dalibor Drzik4-Apr-07 7:50
memberDalibor Drzik4-Apr-07 7:50 
QuestionDifference between standby and off? Pin
oeriksen11-Oct-06 12:01
memberoeriksen11-Oct-06 12:01 
AnswerRe: Difference between standby and off? Pin
Dalibor Drzik4-Apr-07 7:37
memberDalibor Drzik4-Apr-07 7:37 
Questioncan't keep blank when mediaplayer playing next song Pin
aftcast6-Jul-06 7:18
memberaftcast6-Jul-06 7:18 
AnswerRe: can't keep blank when mediaplayer playing next song Pin
Dalibor Drzik4-Apr-07 7:38
memberDalibor Drzik4-Apr-07 7:38 
GeneralControl your monitor by software Pin
Robsori13-Jun-06 21:25
memberRobsori13-Jun-06 21:25 
GeneralRe: Control your monitor by software Pin
Member 47288042-Jun-08 18:12
memberMember 47288042-Jun-08 18:12 

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.

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