Click here to Skip to main content
13,000,569 members (52,935 online)
Click here to Skip to main content
Add your own
alternative version

Stats

247.3K views
12K downloads
67 bookmarked
Posted 24 Jul 2005

Turn on/off monitor

, 24 Jul 2005
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

 
You must Sign In to use this message board.
Spacing  Layout  Per page   
QuestionSending these commands to a 2nd monitor? Pin
Member 113804936-Jun-17 13:05
memberMember 113804936-Jun-17 13:05 
QuestionAvoid turn on Pin
Sh.H.8-Jun-16 0:42
memberSh.H.8-Jun-16 0:42 
QuestionThis does not work on windows 10! Pin
jerbio15-Mar-16 7:07
memberjerbio15-Mar-16 7:07 
Questionexplanation for .rc file and batch file Pin
Member 1235707228-Feb-16 4:02
memberMember 1235707228-Feb-16 4:02 
Questionhow to generate .exe file from code Pin
Member 1235707228-Feb-16 3:56
memberMember 1235707228-Feb-16 3:56 
Question[Virus(Worm)] Download demo project - 2.81 Kb Pin
Member 1193673525-Aug-15 23:27
memberMember 1193673525-Aug-15 23:27 
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 
GeneralKeeping the Monitor Turned ON Pin
Sukhjinder_K6-Sep-07 6:40
memberSukhjinder_K6-Sep-07 6:40 
Generalkeeping the monitor turned off Pin
auldthief13-Jun-07 22:36
memberauldthief13-Jun-07 22:36 
Generalplz help!!! Pin
misha2dope3-Apr-07 21:51
membermisha2dope3-Apr-07 21:51 
QuestionDifference between standby and off? Pin
oeriksen11-Oct-06 12:01
memberoeriksen11-Oct-06 12:01 
Questioncan't keep blank when mediaplayer playing next song Pin
aftcast6-Jul-06 7:18
memberaftcast6-Jul-06 7:18 
GeneralControl your monitor by software Pin
Robsori13-Jun-06 21:25
memberRobsori13-Jun-06 21:25 
GeneralFYI Pin
Michael Dunn13-Jun-06 8:07
sitebuilderMichael Dunn13-Jun-06 8:07 
QuestionAnd how to turn off harddisk? Pin
andreasm8211-Jun-06 1:26
memberandreasm8211-Jun-06 1:26 
QuestionDetect monitor changes? Pin
Judge423-Apr-06 8:43
memberJudge423-Apr-06 8:43 
GeneralGood Job! Pin
John R. Shaw16-Mar-06 16:46
memberJohn R. Shaw16-Mar-06 16:46 
QuestionHow to turn off monitor Pin
uyencpham16-Dec-05 10:56
memberuyencpham16-Dec-05 10:56 
GeneralI tried using C# but it wont work , where i am missing Pin
Lalit N Dubey16-Aug-05 1:38
memberLalit N Dubey16-Aug-05 1:38 
GeneralExcellent - but i need it in VB Pin
Anonymous4-Aug-05 5:59
sussAnonymous4-Aug-05 5:59 
GeneralI had no idea... Pin
Tom Archer25-Jul-05 6:35
memberTom Archer25-Jul-05 6:35 
GeneralGreat Pin
Danila Korablin25-Jul-05 6:09
memberDanila Korablin25-Jul-05 6:09 

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

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