• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Turning Monitor off/on in VB

Need to turn off/on a big flatscreen monitor in  VB6  (like energy schedule would do)
reason is that the screen has to be on allways  at daytime , thus drawing attention, but should go off at night , and back on at 5.00 am
0
BIAPRO
Asked:
BIAPRO
  • 8
  • 7
  • 5
1 Solution
 
kbireckiCommented:
Can you try this ==> http://forums.devshed.com/visual-basic-programming-52/turn-off-monitor-72283.html

And then write a timer routine that obeys the time restriction.
0
 
kbireckiCommented:
Actually, I just tried it and it worked, sort of.  My monitor went off then back on right away, then 10 secs later the timer kicked in.  Let me check something else.
0
 
Brook BraswellApplication Development ManagerCommented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Brook BraswellApplication Development ManagerCommented:
oops...kbirecki got it before I did
0
 
kbireckiCommented:
Yea, I saw that one too, and that's the same code in the other example I gave, but in my case, the monitor pops back on right away, before the timer even fires to turn the mon back on itself.  Does it work any differently for you?
0
 
Brook BraswellApplication Development ManagerCommented:
Mine worked but the monitor turned back on with mouse movement or any other interaction.
0
 
kbireckiCommented:
Mine came back on without any keyboard or mouse movement.  I checked and I have no screen saver configured, so that can't be it.  It seemed like a simple idea, but now that it's not working for me, I'm intrigued.

BIAPRO, is it working for you?
0
 
Brook BraswellApplication Development ManagerCommented:
This worked fine for me but if you have a Dual Monitor - it will blink the first time and if run again it works until user interaction but the "Extend" will be shut off and you will be back to both monitors displaying the same screen.
0
 
BIAPROAuthor Commented:
this works
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&
Const MONITOR_ON = -1&
Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112


Private Sub cmdtest_Click()
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF

End Sub


due to to make the call twice, at one call  it goes on again
0
 
kbireckiCommented:
I do have dual monitors, maybe that had something to do with it, but BIAPRO's implementation with two calls to the same function also worked for me.  What is that, something like "Hey, Windows! Turn the monitor off.  Yes, I really mean it, turn the monitor off now!"
0
 
Brook BraswellApplication Development ManagerCommented:
I took it that if you have dual monitors that you have to send it for both monitors....
I do not believe that to be true...
Once I sent Both it worked and from there on out it only required one send.

0
 
BIAPROAuthor Commented:
Can't tell, I tried on my laptop,  ok , that one has a vga extra port to connect extra monitor, i will try flatscreen later
0
 
BIAPROAuthor Commented:
Yes the dual call works perfect on the big flat touchscreen, it realy goes off, once I touch te screen it turns on again
0
 
kbireckiCommented:
Sounds like you've got a good solution.   And if an earthquake rumbles through in the middle of the night and jiggles the mouse, I'm guessing that the monitor going on is not the biggest concern at that point. :)
0
 
BIAPROAuthor Commented:
Impossible that the thing goes on, look below to timer sub


Private Sub tmrLook_Timer()
'================================
Dim kyk
datum$ = Mid$(Date$, 4, 3) & Left$(Date$, 3) & Right$(Date$, 2)
    kyk = Val(Left$(time$, 2))
       
If Format(datum$, "w", vbMonday, vbUseSystem) > 6 Then
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
End If

If Val(Left$(time$, 2)) >= 19 Or Val(Left$(time$, 2)) < 6 Then
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
End If


If Format(datum$, "w", vbMonday, vbUseSystem) < 7 And Val(Left$(time$, 2)) < 19 And Val(Left$(time$, 2)) >= 6 Then
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
End If






  If (m_lTimerCount >= m_lTimerMinutes) Then
      CheckOrders
          m_lTimerCount = 0
     Else
          m_lTimerCount = m_lTimerCount + 1
     End If
End Sub
0
 
kbireckiCommented:
Do you mean the monitor is not coming back on as intended?
0
 
BIAPROAuthor Commented:
NO,  if you read this in timer sub:

If Format(datum$, "w", vbMonday, vbUseSystem) < 7 And Val(Left$(time$, 2)) < 19 And Val(Left$(time$, 2)) >= 6 Then
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
End If



 the timer will say:   if day < 7  (not on sundays')   and  time is > 06:00 am and < 19:00  (07.00 pm) then turn it on
even if energy saving is installed in windows
 


0
 
BIAPROAuthor Commented:
my meaning on this was due to the text:
 "Sounds like you've got a good solution.   And if an earthquake rumbles through in the middle of the night and jiggles the mouse, I'm guessing that the monitor going on is not the biggest concern at that point"

so i said even then it will stay off
0
 
kbireckiCommented:
I see.  I was kidding that it probably didn't matter if the monitor came back on in that circumstance, but your solution to keep turning it on or off every "X" minutes is good.  I thought I saw somewhere some vb6 code to check if the monitor was already on, but I can't find it now, and I now think it may have been a somewhat different situation, maybe dealing with managing Power Management  from vb6 or form positioning.  Glad it's working for you.
0
 
BIAPROAuthor Commented:
ok, thanks , have a nice day,
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now