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

Turn on/off monitor

By , 24 Jul 2005
Rate this:
Please Sign up or sign in to vote.

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
Wink | ;-)

Comments and Discussions

 
QuestionRequest_To_Elaborate_Code PinmemberMember 815523825-Dec-13 2:51 
Questionmonitor blinks PinmemberSanjeevCharla6-Feb-13 15:42 
QuestionCan this work under remote desktop? Pinmembergeorge0880722-Dec-12 4:56 
GeneralMy vote of 5 Pinmembersunny_rajwadi23-May-12 0:11 
QuestionReally Turn Off Monitor Pinmembernano2k20-Oct-11 3:08 
GeneralThank you so much! PinmemberMember 211670621-May-09 14:52 
Questionhow to calculate the time between monitor off and on Pinmembersrinag4911-Sep-08 17:37 
GeneralMonitior control--in Windows xp Pinmembernnuurraa29-Feb-08 19:56 
QuestionShall it stay countinously? Pinmemberthamizhinpan15-Oct-07 7:57 
AnswerRe: Shall it stay countinously? PinmemberDalibor Drzik16-Oct-07 1:39 
GeneralRe: Shall it stay countinously? Pinmemberkingmax_00718-Nov-07 20:09 
GeneralKeeping the Monitor Turned ON PinmemberSukhjinder_K6-Sep-07 6:40 
AnswerRe: Keeping the Monitor Turned ON PinmemberDalibor Drzik6-Sep-07 11:22 
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SYSCOMMAND:
 
switch (wParam)
{
// disable screen saver and monitor power-saving mode
case SC_SCREENSAVE:
case SC_MONITORPOWER:

return 0;
}
 
break;
 
case WM_DESTROY:
 
PostQuitMessage(0);

return 0;
}
 
return DefWindowProc(hwnd, message, wParam, lParam);
}

GeneralRe: Keeping the Monitor Turned ON PinmemberSukhjinder_K7-Sep-07 0:33 
Generalkeeping the monitor turned off Pinmemberauldthief13-Jun-07 22:36 
Generalplz help!!! Pinmembermisha2dope3-Apr-07 21:51 
AnswerRe: plz help!!! PinmemberDalibor Drzik4-Apr-07 7:50 
QuestionDifference between standby and off? Pinmemberoeriksen11-Oct-06 12:01 
AnswerRe: Difference between standby and off? PinmemberDalibor Drzik4-Apr-07 7:37 
Questioncan't keep blank when mediaplayer playing next song Pinmemberaftcast6-Jul-06 7:18 
AnswerRe: can't keep blank when mediaplayer playing next song PinmemberDalibor Drzik4-Apr-07 7:38 
GeneralControl your monitor by software PinmemberRobsori13-Jun-06 21:25 
GeneralRe: Control your monitor by software PinmemberMember 47288042-Jun-08 18:12 
GeneralRe: Control your monitor by software PinmemberMember 47288042-Jun-08 22:08 
GeneralFYI PinsitebuilderMichael Dunn13-Jun-06 8:07 
AnswerRe: FYI PinmemberDalibor Drzik4-Apr-07 7:29 
QuestionAnd how to turn off harddisk? Pinmemberandreasm8211-Jun-06 1:26 
QuestionDetect monitor changes? PinmemberJudge423-Apr-06 8:43 
AnswerRe: Detect monitor changes? PinmemberDalibor Drzik24-Apr-06 3:11 
GeneralGood Job! PinmemberJohn R. Shaw16-Mar-06 16:46 
AnswerRe: Good Job! PinmemberDalibor Drzik17-Mar-06 2:08 
QuestionHow to turn off monitor Pinmemberuyencpham16-Dec-05 10:56 
AnswerRe: How to turn off monitor PinmemberDalibor Drzik18-Dec-05 4:05 
GeneralI tried using C# but it wont work , where i am missing PinmemberLalit N Dubey16-Aug-05 1:38 
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberOMalleyW16-Aug-05 3:12 
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberLalit N Dubey16-Aug-05 18:48 
GeneralRe: I tried using C# but it wont work , where i am missing PinmemberDalibor Drzik18-Aug-05 2:29 
GeneralExcellent - but i need it in VB PinsussAnonymous4-Aug-05 5:59 
GeneralRe: Excellent - but i need it in VB PinsussAnonymous4-Aug-05 6:21 
GeneralRe: Excellent - but i need it in VB PinsussAnonymous4-Aug-05 14:02 
GeneralRe: Excellent - but i need it in VB PinsussAnonymous4-Aug-05 14:36 
GeneralRe: Excellent - but i need it in VB Pinsusscodephoenix1-Oct-05 17:29 
GeneralRe: Excellent - but i need it in VB Pinmemberuyencpham16-Dec-05 11:13 
GeneralI had no idea... PinmemberTom Archer25-Jul-05 6:35 
GeneralRe: I had no idea... PinmemberTed Ferenc25-Jul-05 12:33 
GeneralRe: I had no idea... PinmemberTom Archer25-Jul-05 13:07 
GeneralRe: I had no idea... PinmemberDalibor Drzik26-Jul-05 5:35 
GeneralRe: I had no idea... PinmemberDalibor Drzik26-Jul-05 5:29 
GeneralGreat PinmemberDanila Korablin25-Jul-05 6:09 
GeneralRe: Great PinmemberDalibor Drzik26-Jul-05 5:25 

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 | Mobile
Web03 | 2.8.140415.2 | Last Updated 25 Jul 2005
Article Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid