Click here to Skip to main content
11,480,938 members (57,815 online)
Click here to Skip to main content

Tagged as

Turn on/off monitor

, 25 Jul 2005 203K 8K 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 | ;-)

Comments and Discussions

 
QuestionRequest_To_Elaborate_Code Pin
Member 815523825-Dec-13 3:51
memberMember 815523825-Dec-13 3:51 
Questionmonitor blinks Pin
SanjeevCharla6-Feb-13 16:42
memberSanjeevCharla6-Feb-13 16:42 
QuestionCan this work under remote desktop? Pin
george0880722-Dec-12 5:56
membergeorge0880722-Dec-12 5:56 
I use remote desktop to logon to another machine. Since I don't need to use the monitor, I want to turn off the monitor. However, it seems this doesn't take effect. I guess it's because of the window handle is confined to the current remote desktop session. Is there a way to turn off the physical monitor in this case? Thanks!
GeneralMy vote of 5 Pin
sunny_rajwadi23-May-12 1:11
membersunny_rajwadi23-May-12 1:11 
QuestionReally Turn Off Monitor Pin
nano2k20-Oct-11 4:08
membernano2k20-Oct-11 4:08 
GeneralThank you so much! Pin
Member 211670621-May-09 15:52
memberMember 211670621-May-09 15:52 
Questionhow to calculate the time between monitor off and on Pin
srinag4911-Sep-08 18:37
membersrinag4911-Sep-08 18:37 
GeneralMonitior control--in Windows xp Pin
nnuurraa29-Feb-08 20:56
membernnuurraa29-Feb-08 20:56 
QuestionShall it stay countinously? Pin
thamizhinpan15-Oct-07 8:57
memberthamizhinpan15-Oct-07 8:57 
AnswerRe: Shall it stay countinously? Pin
Dalibor Drzik16-Oct-07 2:39
memberDalibor Drzik16-Oct-07 2:39 
GeneralRe: Shall it stay countinously? Pin
kingmax_00718-Nov-07 21:09
memberkingmax_00718-Nov-07 21:09 
GeneralKeeping the Monitor Turned ON Pin
Sukhjinder_K6-Sep-07 7:40
memberSukhjinder_K6-Sep-07 7:40 
AnswerRe: Keeping the Monitor Turned ON Pin
Dalibor Drzik6-Sep-07 12:22
memberDalibor Drzik6-Sep-07 12:22 
GeneralRe: Keeping the Monitor Turned ON Pin
Sukhjinder_K7-Sep-07 1:33
memberSukhjinder_K7-Sep-07 1:33 
Generalkeeping the monitor turned off Pin
auldthief13-Jun-07 23:36
memberauldthief13-Jun-07 23:36 
Generalplz help!!! Pin
misha2dope3-Apr-07 22:51
membermisha2dope3-Apr-07 22:51 
AnswerRe: plz help!!! Pin
Dalibor Drzik4-Apr-07 8:50
memberDalibor Drzik4-Apr-07 8:50 
QuestionDifference between standby and off? Pin
oeriksen11-Oct-06 13:01
memberoeriksen11-Oct-06 13:01 
AnswerRe: Difference between standby and off? Pin
Dalibor Drzik4-Apr-07 8:37
memberDalibor Drzik4-Apr-07 8:37 
Questioncan't keep blank when mediaplayer playing next song Pin
aftcast6-Jul-06 8:18
memberaftcast6-Jul-06 8:18 
AnswerRe: can't keep blank when mediaplayer playing next song Pin
Dalibor Drzik4-Apr-07 8:38
memberDalibor Drzik4-Apr-07 8:38 
GeneralControl your monitor by software Pin
Robsori13-Jun-06 22:25
memberRobsori13-Jun-06 22:25 
GeneralRe: Control your monitor by software Pin
Member 47288042-Jun-08 19:12
memberMember 47288042-Jun-08 19:12 
GeneralRe: Control your monitor by software Pin
Member 47288042-Jun-08 23:08
memberMember 47288042-Jun-08 23:08 
GeneralFYI Pin
Michael Dunn13-Jun-06 9:07
sitebuilderMichael Dunn13-Jun-06 9:07 

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
Web04 | 2.8.150520.1 | Last Updated 25 Jul 2005
Article Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid