anyone know how i can turn my montior screen off on the click of a vb button?
Printable View
anyone know how i can turn my montior screen off on the click of a vb button?
Yes, you could look for Power Managemnet options. I'm not sure of the actual code, but its to do with that ;)
i found this somewhere, but now sure if it poweroff.exe even exists
poweroff.exe -scheduled -seconds 2 -notray monitor_off
I didnt have it on my system - XP Pro SP1
Not tested this, but apparantly it works...
VB 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
I found this API code. :)
http://www.vbforums.com/showpost.php...80&postcount=3
So thats where you found it thegreatone :D
thanks m8, i tested that code, the screen goes black, then when i move my mouse, it goes on again..
any way to make it go off properly?
(oops, just saw everybodies replies after i submitted this post, reading everyone elses now lol)
Originally yeah, i've had it on my PC for a while now, never got round to testing it, lol.Quote:
Originally Posted by RobDog888
Still, beat ya *sticks tongue out*
EDIT: Pouncer theres no way to physically turn the monitor off.
The code is probably doing a screensaver power off so when you move the mouse it wakes it up and powers on.
Edit: At least I had a VBF link. :p :D
Its using the power management options, just like my monitor does after 5mins of being inactive, lol :)Quote:
Originally Posted by RobDog888
EDIT: I might have done originally i dunno, i've had that code ages now :p
hm i tested the one robdog found too, doesnt work for me at all
i guess ill stick with thegreastones
Glad it worked for you. I tested it and it works for me as well :) Great :D
Now do us a favour by pulling down the thread tools menu and selecting "Mark thread resolved"
Thanks ;)
They are all the same basically.
These are the APIs for the Monitor. Maybe they will shed some light on the issue.
VB Code:
Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long Declare Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long Declare Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
Don't know what happned ! The EE page now reqires registration. :eek:Quote:
Originally Posted by Myself
Just a few minutes ago I saw the full thread without any registration !!!
I found that link long before I became VBF member. :pQuote:
Originally Posted by RobDog888
Same here, clear your cookies and se what happens...Quote:
Originally Posted by iPrank
No. That didn't help. :(
Thanks to google cache. :)
http://64.233.187.104/search?q=cache...+monitor&hl=en
And
http://64.233.187.104/search?q=cache...en&lr=&strip=1
Looks like its all C++ code though. No VB examples?
See the second link (edited). Has code in VB and C#.
Just seen the second link and seems the same code as I posted a link to with the exception of the first parameter being any window handle vs the const HWND_BROADCAST.
Doesnt work for me using either the Me.hWnd or HWND_BROADCAST.
Sorry. I don't know what difference it makes to the OS if we broadcast the message or send it to our own hwnd.
I found the code almost 6 months ago and after single testing saved under my 'cool codes' folder. :p Never used it since then.
Both hWnd and HWND_BROADCAST works for me.Quote:
Originally Posted by RobDog888
By googling for some time, I found that :
The code will turn off/on the monitor on which the form (hWnd) is displayed. Your motherboard must support advanced power management.
6 months ago I had no problem with this code in Win2K. But now, on WinXP-SP2 it treates MONITOR_OFF as MONITOR_STANDBY. i.e., it turns the monitor on if we move mouse/hit keyboard. :confused:
Then I found this page where a member (agent007bond - last post) pointed to this tool (haven't tested it yet), which turns monitor off. From that page:
So, may be this is XP-SP2 specific problem ?Quote:
03/11/2004 1.53 Fixed 'monitor off' problem in XP SP2.
VB Code:
Const MONITOR_ON = -1& Const MONITOR_OFF = 2& Const MONITOR_STANDBY = 1&
Thanks. I am running SP-1 so maybe its just a XP thing. There must be a proper way as that command line utility can do it so must we. I'll have to break out my mobo manual and check it out.