Translating VB6 Code to kill the screen saver.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gregory_May

    #1

    Translating VB6 Code to kill the screen saver.

    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




  • Cor Ligthert [MVP]

    #2
    Re: Translating VB6 Code to kill the screen saver.

    Gregory,

    Mostly this does not work because there has been a shift and some
    namechanges.

    By instance a long in VB6 is an integer in VB.Net.

    I hope this helps,

    Cor

    "Gregory_Ma y" <Gregory_May@ho tmail.com> schreef in bericht
    news:eSB26LPaGH A.3736@TK2MSFTN GP04.phx.gbl...[color=blue]
    >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
    >
    >
    >
    >[/color]


    Comment

    Working...