5,666,547 members and growing! (14,486 online)
Email Password   helpLost your password?
General Reading » Hardware & System » Hardware     Intermediate

Turn on/off monitor

By Dalibor Drzik

Sets the state of the display.
VC6, C++Windows, NT4VS6, Visual Studio, Dev

Posted: 25 Jul 2005
Updated: 25 Jul 2005
Views: 75,631
Bookmarked: 36 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
30 votes for this Article.
Popularity: 6.56 Rating: 4.44 out of 5
3 votes, 10.0%
1
0 votes, 0.0%
2
3 votes, 10.0%
3
2 votes, 6.7%
4
22 votes, 73.3%
5

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


Wink
Occupation: Web Developer
Location: Slovakia Slovakia

Other popular Hardware & System articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 44 (Total in Forum: 44) (Refresh)FirstPrevNext
Generalhow to calculate the time between monitor off and onmembersrinag4918:37 11 Sep '08  
GeneralMonitior control--in Windows xpmembernnuurraa20:56 29 Feb '08  
QuestionShall it stay countinously?memberthamizhinpan8:57 15 Oct '07  
AnswerRe: Shall it stay countinously?memberDalibor Drzik2:39 16 Oct '07  
GeneralRe: Shall it stay countinously?memberkingmax_00721:09 18 Nov '07  
GeneralKeeping the Monitor Turned ONmemberSukhjinder_K7:40 6 Sep '07  
AnswerRe: Keeping the Monitor Turned ONmemberDalibor Drzik12:22 6 Sep '07  
GeneralRe: Keeping the Monitor Turned ONmemberSukhjinder_K1:33 7 Sep '07  
Generalkeeping the monitor turned offmemberauldthief23:36 13 Jun '07  
Generalplz help!!!membermisha2dope22:51 3 Apr '07  
AnswerRe: plz help!!!memberDalibor Drzik8:50 4 Apr '07  
QuestionDifference between standby and off?memberoeriksen13:01 11 Oct '06  
AnswerRe: Difference between standby and off?memberDalibor Drzik8:37 4 Apr '07  
Questioncan't keep blank when mediaplayer playing next songmemberaftcast8:18 6 Jul '06  
AnswerRe: can't keep blank when mediaplayer playing next songmemberDalibor Drzik8:38 4 Apr '07  
GeneralControl your monitor by softwarememberRobsori22:25 13 Jun '06  
GeneralRe: Control your monitor by softwarememberMember 472880419:12 2 Jun '08  
GeneralRe: Control your monitor by softwarememberMember 472880423:08 2 Jun '08  
GeneralFYIsitebuilderMichael Dunn9:07 13 Jun '06  
AnswerRe: FYImemberDalibor Drzik8:29 4 Apr '07  
GeneralAnd how to turn off harddisk?memberandreasm822:26 11 Jun '06  
GeneralDetect monitor changes?memberJudge429:43 3 Apr '06  
AnswerRe: Detect monitor changes?memberDalibor Drzik4:11 24 Apr '06  
GeneralGood Job!memberJohn R. Shaw17:46 16 Mar '06  
AnswerRe: Good Job!memberDalibor Drzik3:08 17 Mar '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Jul 2005
Editor: Smitha Vijayan
Copyright 2005 by Dalibor Drzik
Everything else Copyright © CodeProject, 1999-2008
Web12 | Advertise on the Code Project