Solved

Turning Monitor off/on in VB

Posted on 2010-11-29
20
323 Views
Last Modified: 2012-05-10
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
Comment
Question by:BIAPRO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 5
20 Comments
 
LVL 11

Accepted Solution

by:
kbirecki earned 500 total points
ID: 34230875
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
 
LVL 11

Expert Comment

by:kbirecki
ID: 34230919
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34231012
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34231023
oops...kbirecki got it before I did
0
 
LVL 11

Expert Comment

by:kbirecki
ID: 34231031
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34231102
Mine worked but the monitor turned back on with mouse movement or any other interaction.
0
 
LVL 11

Expert Comment

by:kbirecki
ID: 34231122
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34231288
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
 

Author Comment

by:BIAPRO
ID: 34231332
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
 
LVL 11

Expert Comment

by:kbirecki
ID: 34231390
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34231459
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
 

Author Comment

by:BIAPRO
ID: 34231586
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
 

Author Comment

by:BIAPRO
ID: 34231704
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
 
LVL 11

Expert Comment

by:kbirecki
ID: 34231724
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
 

Author Comment

by:BIAPRO
ID: 34236933
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
 
LVL 11

Expert Comment

by:kbirecki
ID: 34237521
Do you mean the monitor is not coming back on as intended?
0
 

Author Comment

by:BIAPRO
ID: 34237549
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
 

Author Comment

by:BIAPRO
ID: 34237554
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
 
LVL 11

Expert Comment

by:kbirecki
ID: 34237661
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
 

Author Comment

by:BIAPRO
ID: 34237708
ok, thanks , have a nice day,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 42
VBA Shell can't Find Word document 11 131
how to Classify of email (pdf attachments) 7 50
Error with a code discussed on this page 5 39
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question