|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Translating VB6 Code to kill the screen saver."AddressOf StopScreenSaverProc" ... 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 ScreenSaverControlClass ' Declare Type for API call: Private Structure OSVERSIONINFO Dim dwOSVersionInfoSize As Integer Dim dwMajorVersion As Integer Dim dwMinorVersion As Integer Dim dwBuildNumber As Integer Dim dwPlatformId As Integer <VBFixedString(128), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String ' Maintenance string for PSS usage End Structure Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Integer Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32_NT = 2 Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (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 "SendMessageA" (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 "PostMessageA" (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 "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (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 EnumDesktopWindows Lib "user32" (ByVal hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long Private Const SC_SCREENSAVE = &HF140& Private Const SPI_GETSCREENSAVEACTIVE = 16 Private Const SPI_SCREENSAVERRUNNING = 97 Private Const SPI_SETSCREENSAVEACTIVE = 17 Private Const SPIF_NOINIFILE = &H0 Private Const SPIF_SENDWININICHANGE = &H2 Private Const SPIF_UPDATEINIFILE = &H1 Private Const DESKTOP_READOBJECTS = &H1& Private Const DESKTOP_WRITEOBJECTS = &H80& Private Const WM_CLOSE = &H10 Private Const WM_SYSCOMMAND = &H112 Public Function StopScreenSaverProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean Dim lngRet As Long Call PostMessage(hWnd, WM_CLOSE, 0, 0) Call SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, 0, SPIF_SENDWININICHANGE) StopScreenSaverProc = True End Function Delegate Function Compare(ByVal x As Integer, _ ByVal y As Integer) As Boolean Public Sub StopScreenSaver() Dim OSVER As OSVERSIONINFO OSVER.dwOSVersionInfoSize = Len(OSVER) Call GetVersionEx(OSVER) Select Case OSVER.dwPlatformId Case VER_PLATFORM_WIN32_WINDOWS '95,98 Dim hWnd As Long hWnd = FindWindow("WindowsScreenSaverClass", vbNullString) If hWnd <> 0 Then Call PostMessage(hWnd, WM_CLOSE, 0, 0) End If Case VER_PLATFORM_WIN32_NT 'NT Dim hDesk As Long hDesk = OpenDesktop("Screen-Saver", 0, False, DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS) If hDesk <> 0 Then Call EnumDesktopWindows(hDesk, AddressOf StopScreenSaverProc, 0) Call CloseDesktop(hDesk) End If End Select End Sub End Class 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 Show quoteHide quote "Gregory_May" <Gregory_***@hotmail.com> schreef in bericht news:eSB26LPaGHA.3736@TK2MSFTNGP04.phx.gbl... >I cant seem to figure out this vb6 code ... its almost done except for the >"AddressOf StopScreenSaverProc" ... 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 ScreenSaverControlClass > > ' Declare Type for API call: > Private Structure OSVERSIONINFO > Dim dwOSVersionInfoSize As Integer > Dim dwMajorVersion As Integer > Dim dwMinorVersion As Integer > Dim dwBuildNumber As Integer > Dim dwPlatformId As Integer > <VBFixedString(128), > System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, > SizeConst:=128)> Public szCSDVersion As String ' Maintenance string for > PSS usage > End Structure > > Private Declare Function GetVersionEx Lib "kernel32" Alias > "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Integer > > Private Const VER_PLATFORM_WIN32_WINDOWS = 1 > Private Const VER_PLATFORM_WIN32_NT = 2 > > Private Declare Function SystemParametersInfo Lib "user32" Alias > "SystemParametersInfoA" (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 "SendMessageA" > (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 "PostMessageA" > (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 "FindWindowA" > (ByVal lpClassName As String, ByVal lpWindowName As String) As Long > Private Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" > (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 EnumDesktopWindows Lib "user32" (ByVal > hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long > > Private Const SC_SCREENSAVE = &HF140& > > Private Const SPI_GETSCREENSAVEACTIVE = 16 > Private Const SPI_SCREENSAVERRUNNING = 97 > Private Const SPI_SETSCREENSAVEACTIVE = 17 > > Private Const SPIF_NOINIFILE = &H0 > Private Const SPIF_SENDWININICHANGE = &H2 > Private Const SPIF_UPDATEINIFILE = &H1 > > Private Const DESKTOP_READOBJECTS = &H1& > Private Const DESKTOP_WRITEOBJECTS = &H80& > > Private Const WM_CLOSE = &H10 > Private Const WM_SYSCOMMAND = &H112 > > Public Function StopScreenSaverProc(ByVal hWnd As Long, ByVal lParam As > Long) As Boolean > Dim lngRet As Long > > Call PostMessage(hWnd, WM_CLOSE, 0, 0) > Call SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, 0, > SPIF_SENDWININICHANGE) > > StopScreenSaverProc = True > End Function > > Delegate Function Compare(ByVal x As Integer, _ > ByVal y As Integer) As Boolean > > > Public Sub StopScreenSaver() > Dim OSVER As OSVERSIONINFO > > OSVER.dwOSVersionInfoSize = Len(OSVER) > Call GetVersionEx(OSVER) > > Select Case OSVER.dwPlatformId > Case VER_PLATFORM_WIN32_WINDOWS '95,98 > Dim hWnd As Long > hWnd = FindWindow("WindowsScreenSaverClass", vbNullString) > If hWnd <> 0 Then > Call PostMessage(hWnd, WM_CLOSE, 0, 0) > End If > Case VER_PLATFORM_WIN32_NT 'NT > Dim hDesk As Long > hDesk = OpenDesktop("Screen-Saver", 0, False, > DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS) > If hDesk <> 0 Then > Call EnumDesktopWindows(hDesk, AddressOf > StopScreenSaverProc, 0) > Call CloseDesktop(hDesk) > End If > End Select > End Sub > End Class > > > >
date calculations
Do loop memory consumption? "Send To Mail Recipient" Saving outlook email attachment? ListBox Control Classes and collections vs. virtual tables (datasets) Display All Domain Names on the Network Recursion with a Tree View and checkboxes GetType question Getting property settings for controls in the immidiate window in VB2005 |
|||||||||||||||||||||||