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:
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.