Saturday, March 03, 2007

How to turn off your monitor via code?This is an important question at least to me , because I use my computer for long time daily and frequently turn on and off the screen as a way to save energy and power .I hate to make that by using the monitor button(off/on) , because I hear sound from the monitor feel me that the screen may damage .So I will inform you here , How to turn off your monitor via code ( C# ) ?

I will code that depending in API called SendMessagefunction it’s useful to handle monitor states - the display is going to low power, the display is being shut off and the display is turned on .Syntax :LRESULT SendMessage( HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam );Parameters:

# HWnd (first paramter)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 (second paramter)Specifies the message to be sent (WM_SYSCOMMAND).

Nice idea. I would just want to point out that SendMessage is the basic Windows API for sending messages to other windows applications.the receiver application must have a valid handle to a window even if it is invisible.It is a Sync. method.There's another similar API called PostMessage which is the same but Async.

@kalpanaPlease refer to specific Windows documentation to see if there is method like SendMessage or not, but I don't think there is alternative method for SendMessage. For all Windows versions there is SendMessage method.

Really , I don't know if it is applicable or not ... if you depend on some hardware to connect the two monitor ,I think it's better to refer to the hardware documentation .. you may get a way ...the another way is to refer to Windows API documentation .

About us

We are a group of bloggers from Faculty of Computers & Information, Helwan University. We have a passion for technology, enjoy programming and we enjoy blogging. This blog is the result of combining those skills and the desire to share our knowledge with others.