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

Turn on/off monitor

By , 24 Jul 2005
 

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
AnswerRe: Shall it stay countinously?memberDalibor Drzik16 Oct '07 - 1:39 
This process is OS dependent so it's not possible to wake up a monitor only by pressing the Enter key.
GeneralRe: Shall it stay countinously?memberkingmax_00718 Nov '07 - 20:09 
Hi
My name is Sandesh. I am writing a code to blank the screen. The requirement is that the screen should be kept blank until a specific event is fired by the remote software(A VNC viewer).
 

I have seen the UltraVNC (code is available on net)(Server code which is not compiling). They have used a hook to desktop procedure. When the desktop procedure receives a WM_POWER or WM_POWERBROADCAST event they have taken some action so that the screen remains blank. Also the keyboard and mouse event are locked so that the windows remains in the sleep mode
and keyboard and mouse is locked.
Currenty I am working on the project, so I felt like sharing the information I have. If you find the solution please help me out...
 
Waiting for your responce.
 
kingmax_007@yahoo.com

GeneralKeeping the Monitor Turned ONmemberSukhjinder_K6 Sep '07 - 6:40 
Hi, My requirements are to keep the Monitor ON for the Lifetime of my App. So how can it be done?
 
Thanks...
AnswerRe: Keeping the Monitor Turned ONmemberDalibor 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 ONmemberSukhjinder_K7 Sep '07 - 0:33 
Thanks for the Help. I'm coding in C# and am pretty new to it. If you can give me a C# equivalent then it would be easier for me. I'll try using DllImport("user32.dll") and then maybe use sendMessage function...
Generalkeeping the monitor turned offmemberauldthief13 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! Frown | :( br /> 
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!!!membermisha2dope3 Apr '07 - 21:51 
hey guys im super new to all this coding stuff... and i thought it would be pretty neat to make a program where i press a button and monitor turns off...
so #1 wat do i do with that source thing i downloaded...wen i double click the files they open in c++ and i have no idea wat to do with that code...#2 can i make this work in vb6? any help would be great ty!!!Laugh | :laugh:
AnswerRe: plz help!!!memberDalibor Drzik4 Apr '07 - 7:50 
Choose an appropriate language and an appropriate book...
 
For C/C++ read this article [^].
QuestionDifference between standby and off?memberoeriksen11 Oct '06 - 12:01 
First, thanks for the code.
Saved me some time looking up win api code Smile | :)
 
But what is really the diffence between standby and off?
I've tested both (I'm currently on my laptop) and can't see any diffence...
 

Regards,
Oyvind Eriksen
AnswerRe: Difference between standby and off?memberDalibor Drzik4 Apr '07 - 7:37 
I have to say I don't ever know... Sigh | :sigh:

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

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