Page 1 of 1

Turn off your LCD How to turn off an LCD screen Rate Topic: ***** 1 Votes

#1 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Posted 07 January 2010 - 01:11 PM

Hi, In this tutorial I'm going to show everyone how to turn off your LCD screen. The code ACTUALLY WORKS! (unlike the code you'll find if you google it)

Ok First, open Visual Basic 2008 (I use express) and go File -> New Project -> Windows Forms Application -> Name it Whatever you want. I called it 'OffLCD'

Now you should see a normal windows form Rename it to whatever you want. I calle it 'FrmMain' . For the purposes of this tutorial, add only one button from the toolbox, and name it btnLCDOff.


Now, Double click anywhere on the form to see the code. On the top line, type this code:


'This will shorten the amount we need to type for some commands.
Imports System.Runtime.InteropServices


Note: Make sure this is on the very TOP line, above the class for your form.


Next, go add this code inside the class for your form.


'These are codes which windows can recongnise which tell it to perform certain actions. 
	Private Const MONITOR_OFF As Integer = 2
	Private SC_MONITORPOWER As Integer = &HF170
	Private WM_SYSCOMMAND As Integer = &H112

'There is no direct function in VB to turn off the LCD screen, so we need to make a few calls to some a system file to do our work for us.

'The FindWindow function gets the handle to the topmost window whose class name and window name match the specified strings. In this case we will not be using it for this exact purpose.
	<DllImport("user32.dll", SetLastError:=True)> _
	Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
	End Function

'The sendmessage command unlocks (almost) endless possibilities. Think of it as a function which tells the operating system to do something. Each thing has a seperate signature.
	<DllImport("user32.dll")> _
	Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal hMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
	End Function


	Public Sub TurnOffLCD()
	  'We are using the FindWindow function to call a function which will turn off the LCD screen. It's not exactly the 'best' code to do it, but it does the trick, so why not use it?
		Dim num As Integer = 0
		num = SendMessage(FindWindow(Nothing, Nothing).ToInt32, Me.WM_SYSCOMMAND, Me.SC_MONITORPOWER, 2)
	End Sub





Next we need to add this code to the btnLCDOff_Click event, so go back to the designer, and double click on the button which we added earlier. VB will generate the required code for you.
Now we just need to type:
TurnOffLCD()



In the button event code.



Next press F5 to start debugging. Your application should start with no errors.


When you click the btnLCDOff button, your screen will turn off!


WARNING: Do NOT touch your mouse OR keyboard after you have clicked down, or your screen will turn back on again.

Is This A Good Question/Topic? 1
  • +

Replies To: Turn off your LCD

#2 Stippadippa  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 10-July 09

Posted 24 February 2010 - 08:42 AM

This was interesting to test. Seems to work really. Could be fun for prank program, but other than i find no use.

Lcd turned back on, whatever i did touch mouse or keyboard. But i found way to improve it with a little work.

I added timer with interval 10.

This is my Button1.Click code :

Timer1.Start()


and my Timer1.Tick code :

TurnOffLCD()

This post has been edited by Stippadippa: 24 February 2010 - 09:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Posted 18 April 2010 - 03:04 AM

How do you turn your screen back on?! :D
Was This Post Helpful? 0
  • +
  • -

#4 Stippadippa  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 10-July 09

Posted 24 June 2010 - 08:10 AM

View PostJack Eagles1, on 18 April 2010 - 02:04 AM, said:

How do you turn your screen back on?! :D

You won't, i gave this program to my friend and he lost his nerves figuring out how to turn lcd on.
Was This Post Helpful? 0
  • +
  • -

#5 sougias  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 28-October 09

Posted 25 June 2010 - 10:48 AM

I try this for few times but after that just stop to work.The code is c/p from here.Any ideas? i have lcd screen,this work with every monitor?.
Was This Post Helpful? 0
  • +
  • -

#6 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Posted 26 June 2010 - 06:45 AM

Yeah, it doesn't matter what screen it is. Make sure when you click the button to turn the lcd off, that you dont move your mouse, otherwise the lcd will just go off and come on again really fast. If your mouse has a high DPI then you might encounter problems not moving the mouse when clicking a button.
Was This Post Helpful? 1
  • +
  • -

#7 raymai97  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 16-November 11

Posted 16 November 2011 - 04:34 AM

THANKS A LOT! It's work! :sorcerer: Unlike the others that found in google!
Was This Post Helpful? 0
  • +
  • -

#8 alikolalia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-January 14

Posted 02 January 2014 - 03:46 PM

View PostStippadippa, on 24 June 2010 - 08:10 AM, said:

View PostJack Eagles1, on 18 April 2010 - 02:04 AM, said:

How do you turn your screen back on?! :D/>/>

You won't, i gave this program to my friend and he lost his nerves figuring out how to turn lcd on.

Public Sub TurnOnLCD()
Dim num As Integer = 0
num = SendMessage(FindWindow(Nothing, Nothing).ToInt32, Me.WM_SYSCOMMAND, Me.SC_MONITORPOWER, -1)
End Sub
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1