473,473 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Translating VB6 Code to kill the screen saver.

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.Ru ntime.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


Apr 26 '06 #1
1 4124
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_May" <Gr*********@hotmail.com> schreef in bericht
news:eS**************@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.Ru ntime.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

Apr 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Card.Starzinger | last post by:
Hi! I need help to simulate programmatically user interaction on WinNT 4.0, to avoid screen saver activation. I try with key injection event. SendInput API and keybd_event API work...
3
by: Thom Little | last post by:
How do I invoke the current screen saver with C#? Where did you find the information on how to do it? -- -- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd. --
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
1
by: Daniel | last post by:
Hi all, i have a doubt related to the screen saver ability. After developing the asp.net webform, can i add screen saver ability in this webform? which means, i open the asp.net webform, after a...
2
by: Kurien Baker Fenn | last post by:
I have developed a screen saver with 10 different images.when the screen saver is executed in my computer it is in the center.but when i execute the screen saver in a computer with a different...
2
by: Claire | last post by:
Hi, Our software runs on a XP system attached to a touch screen monitor and smartcard USB reader. We run our own simple corporate screen saver. When the screen is touched the screen saver...
1
by: ashwiniappajigowda | last post by:
Hi, I have an simple MFC dialog based application. On launch of that application 'Password protected screen saver' is not getting activated after the screen saver timeout. If 'On resume,...
3
by: KK | last post by:
Dear All I want to prevent the screen saver getting activated when my application is running. I have the following code, but still screen saver is activated. What corrections I should make to...
0
by: rehanrana | last post by:
I built application in VB6, my application appear in system tray, when I double click on icon of my application, it run screen saver, my screen saver shows images and news. Screen saver...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.