Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 24th, 2003, 11:36 PM
NASCAR6Frd NASCAR6Frd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 15 NASCAR6Frd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 24 sec
Reputation Power: 0
Turn Off Monitor

Hi! I'm very new to VB, and I would appreciate it very much if someone could help me a little here. I am trying to make a simple app that will turn off the computer's monitor when a button is pressed. I was given this code, but I'm not exactly sure what to do with it:

Code:
Option Explicit
Private Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long


Const SC_MONITORPOWER = &HF170&
Public Const MONITOR_ON = -1&
Public Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112

'Turn Monitor on:
'SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
'
'Turn Monitor off:
'SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF


Thanks in advance.

Zach

Last edited by NASCAR6Frd : July 25th, 2003 at 12:41 AM.

Reply With Quote
  #2  
Old July 25th, 2003, 10:34 AM
NASCAR6Frd NASCAR6Frd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 15 NASCAR6Frd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 24 sec
Reputation Power: 0
Can anybody help me?

Reply With Quote
  #3  
Old July 25th, 2003, 12:50 PM
alexus alexus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 26 alexus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 32 sec
Reputation Power: 0
Hi,
as I can understand it send specific set of command to the User32 library.... so to know what those commands are you have to get documentation for user32.dll (have no Idea how you can get it ... , but you can brows the dll, to do this go to View => othere window => object browser=> then your dll

Reply With Quote
  #4  
Old September 18th, 2003, 03:41 AM
CyberLynx CyberLynx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 CyberLynx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 37 sec
Reputation Power: 0
Smile

This is a rather simple API call that WILL turn off (or on) your computer monitor

1) To use this API call in Visual Basic, or at least try it out, simply create a blank form. Then in the declarations section of the form (under the Option Explicit) simply copy and paste the following code:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long


Const SC_MONITORPOWER = &HF170&
Const MONITOR_ON = -1&
Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112


Note: You can place this code into a module but then be sure to make the two Constants

MONITOR_ON
and MONITOR_OFF

as Public Contstants:

Public Const MONITOR_ON = -1&
Public Const MONITOR_OFF = 2&

End Note:

2) Now, place a Timer control into the form and name it: Timer1. Make sure the 'Interval' property for this control is set to 0 (zero).

Next, copy and paste the following code into the 'Timer1_Timer' event:

SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON

(all one line). This API function tells the monitor to turn ON. We have simply placed it into a timer for the sole purpose of turning the monitor on again after a specific time period (which will be 10 seconds). We have no real control once the monitor turns off unless we use a key press or a timing mechanism of some kind to do the job. How and when you want the monitor to turn back on again is entirely up to you but for this example, we are going to use a Timer control.

3) Now you must place a Comand button into your new form. Do so now, then in the caption property of this button, enter "Monitor OFF" (no quotes). For now, make sure the name of your button is 'Command1'. Now...place the following code into the 'Command1_Click' event of your button:

'(*All one Line*) This API function call will turn the monitor OFF.
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF

' Here, we set the Timer1 control Interval to 10000.
' By doing so, we are telling the timer to start and
' after 10000 miliseconds (10 seconds), fire the
' Timer1_Timer event and run the code in that event.
Me.Timer1.Interval = 10000


'End of Code

When you start your example program, you will see a blank form with just on command button on it that says "Monitor OFF". Once you click on this button, the monitor will shut down (if your monitor supports suspend mode). Then, after a 10 second time period, the monitor will turn back on again.

Increasing the Timer1.Interval will increase the length of time the monitor stays off (keep in mind: 1 second = 1000 interval ticks).

I hope this helps.

Reply With Quote
  #5  
Old September 18th, 2003, 03:50 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
So detailed explain! Thank CyberLynx
!

Reply With Quote
  #6  
Old September 21st, 2003, 09:34 AM
NASCAR6Frd NASCAR6Frd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 15 NASCAR6Frd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 24 sec
Reputation Power: 0
Thanks so much! Works wonderfully.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Turn Off Monitor


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway