|
-
Sep 1st, 2009, 11:09 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Controlling monitor power. [ Turn on / Off ]
OK,
i wanna be able to switch off my screen via code (using v/c)
looked through my old code and found this.... - it doesnt work though, comes out with Error 6: overflow, pointing to sendmessage....
now ive got a fresh xp install so maybe its something i havent set up correctly, so does this need something setting to be able to use it?
vb Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Const SC_MONITORPOWER = &HF170&
Const MONITOR_ON = -1&
Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112
Private Sub ControlScreenPower(bTurnOn As Boolean)
Select Case bTurnOn
Case True:
'Turn Monitor on:
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
Case False:
'Turn Monitor off:
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
End Select
End Sub
'me.hwnd = 2294342
' WM_SYSCOMMAND= 274
' sc_monitorpower = 61808
' monitor on = -1
' and off = 2
i havent actually tried it on another machine yet, but if you guys say its right ill make an install n check it on the other machine
-
Sep 1st, 2009, 11:31 AM
#2
Re: Controlling monitor power. [ Turn on / Off ]
Try this modification to your API declaration.
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, ByVal lParam As Long) As Long
You have declared it as integer yet you are passing a long variable.
-
Sep 1st, 2009, 01:07 PM
#3
Thread Starter
Frenzied Member
Re: Controlling monitor power. [ Turn on / Off ]
cheers.
i forgot i posted this till i jst come for a nosy, i actually changed it to Long and it solved it... - but as you suggested the ANY works too
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|