I cant seem to figure out this vb6 code ... its almost done except for the
"AddressOf StopScreenSaver Proc" ... anyone know how to fix this?.... it says
a "long" isnt a Delegate. Or if someone knows a cleaner way to kill the
screen saver, that would be fine too.
Thanks!
Public Class ScreenSaverCont rolClass
' Declare Type for API call:
Private Structure OSVERSIONINFO
Dim dwOSVersionInfo Size As Integer
Dim dwMajorVersion As Integer
Dim dwMinorVersion As Integer
Dim dwBuildNumber As Integer
Dim dwPlatformId As Integer
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lTStr,
SizeConst:=128) > Public szCSDVersion As String ' Maintenance string for PSS
usage
End Structure
Private Declare Function GetVersionEx Lib "kernel32" Alias
"GetVersion ExA" (ByRef lpVersionInform ation As OSVERSIONINFO) As Integer
Private Const VER_PLATFORM_WI N32_WINDOWS = 1
Private Const VER_PLATFORM_WI N32_NT = 2
Private Declare Function SystemParameter sInfo Lib "user32" Alias
"SystemParamete rsInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef
lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessag eA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindow A"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function OpenDesktop Lib "user32" Alias "OpenDeskto pA"
(ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As
Boolean, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As
Long) As Long
Private Declare Function EnumDesktopWind ows Lib "user32" (ByVal hDesktop
As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Private Const SC_SCREENSAVE = &HF140&
Private Const SPI_GETSCREENSA VEACTIVE = 16
Private Const SPI_SCREENSAVER RUNNING = 97
Private Const SPI_SETSCREENSA VEACTIVE = 17
Private Const SPIF_NOINIFILE = &H0
Private Const SPIF_SENDWININI CHANGE = &H2
Private Const SPIF_UPDATEINIF ILE = &H1
Private Const DESKTOP_READOBJ ECTS = &H1&
Private Const DESKTOP_WRITEOB JECTS = &H80&
Private Const WM_CLOSE = &H10
Private Const WM_SYSCOMMAND = &H112
Public Function StopScreenSaver Proc(ByVal hWnd As Long, ByVal lParam As
Long) As Boolean
Dim lngRet As Long
Call PostMessage(hWn d, WM_CLOSE, 0, 0)
Call SystemParameter sInfo(SPI_SETSC REENSAVEACTIVE, 1, 0,
SPIF_SENDWININI CHANGE)
StopScreenSaver Proc = True
End Function
Delegate Function Compare(ByVal x As Integer, _
ByVal y As Integer) As Boolean
Public Sub StopScreenSaver ()
Dim OSVER As OSVERSIONINFO
OSVER.dwOSVersi onInfoSize = Len(OSVER)
Call GetVersionEx(OS VER)
Select Case OSVER.dwPlatfor mId
Case VER_PLATFORM_WI N32_WINDOWS '95,98
Dim hWnd As Long
hWnd = FindWindow("Win dowsScreenSaver Class", vbNullString)
If hWnd <> 0 Then
Call PostMessage(hWn d, WM_CLOSE, 0, 0)
End If
Case VER_PLATFORM_WI N32_NT 'NT
Dim hDesk As Long
hDesk = OpenDesktop("Sc reen-Saver", 0, False,
DESKTOP_READOBJ ECTS Or DESKTOP_WRITEOB JECTS)
If hDesk <> 0 Then
Call EnumDesktopWind ows(hDesk, AddressOf
StopScreenSaver Proc, 0)
Call CloseDesktop(hD esk)
End If
End Select
End Sub
End Class
"AddressOf StopScreenSaver Proc" ... anyone know how to fix this?.... it says
a "long" isnt a Delegate. Or if someone knows a cleaner way to kill the
screen saver, that would be fine too.
Thanks!
Public Class ScreenSaverCont rolClass
' Declare Type for API call:
Private Structure OSVERSIONINFO
Dim dwOSVersionInfo Size As Integer
Dim dwMajorVersion As Integer
Dim dwMinorVersion As Integer
Dim dwBuildNumber As Integer
Dim dwPlatformId As Integer
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lTStr,
SizeConst:=128) > Public szCSDVersion As String ' Maintenance string for PSS
usage
End Structure
Private Declare Function GetVersionEx Lib "kernel32" Alias
"GetVersion ExA" (ByRef lpVersionInform ation As OSVERSIONINFO) As Integer
Private Const VER_PLATFORM_WI N32_WINDOWS = 1
Private Const VER_PLATFORM_WI N32_NT = 2
Private Declare Function SystemParameter sInfo Lib "user32" Alias
"SystemParamete rsInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef
lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessag eA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindow A"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function OpenDesktop Lib "user32" Alias "OpenDeskto pA"
(ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As
Boolean, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As
Long) As Long
Private Declare Function EnumDesktopWind ows Lib "user32" (ByVal hDesktop
As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Private Const SC_SCREENSAVE = &HF140&
Private Const SPI_GETSCREENSA VEACTIVE = 16
Private Const SPI_SCREENSAVER RUNNING = 97
Private Const SPI_SETSCREENSA VEACTIVE = 17
Private Const SPIF_NOINIFILE = &H0
Private Const SPIF_SENDWININI CHANGE = &H2
Private Const SPIF_UPDATEINIF ILE = &H1
Private Const DESKTOP_READOBJ ECTS = &H1&
Private Const DESKTOP_WRITEOB JECTS = &H80&
Private Const WM_CLOSE = &H10
Private Const WM_SYSCOMMAND = &H112
Public Function StopScreenSaver Proc(ByVal hWnd As Long, ByVal lParam As
Long) As Boolean
Dim lngRet As Long
Call PostMessage(hWn d, WM_CLOSE, 0, 0)
Call SystemParameter sInfo(SPI_SETSC REENSAVEACTIVE, 1, 0,
SPIF_SENDWININI CHANGE)
StopScreenSaver Proc = True
End Function
Delegate Function Compare(ByVal x As Integer, _
ByVal y As Integer) As Boolean
Public Sub StopScreenSaver ()
Dim OSVER As OSVERSIONINFO
OSVER.dwOSVersi onInfoSize = Len(OSVER)
Call GetVersionEx(OS VER)
Select Case OSVER.dwPlatfor mId
Case VER_PLATFORM_WI N32_WINDOWS '95,98
Dim hWnd As Long
hWnd = FindWindow("Win dowsScreenSaver Class", vbNullString)
If hWnd <> 0 Then
Call PostMessage(hWn d, WM_CLOSE, 0, 0)
End If
Case VER_PLATFORM_WI N32_NT 'NT
Dim hDesk As Long
hDesk = OpenDesktop("Sc reen-Saver", 0, False,
DESKTOP_READOBJ ECTS Or DESKTOP_WRITEOB JECTS)
If hDesk <> 0 Then
Call EnumDesktopWind ows(hDesk, AddressOf
StopScreenSaver Proc, 0)
Call CloseDesktop(hD esk)
End If
End Select
End Sub
End Class
Comment