473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Screensaver Event WM_GETMESSAGE Hook

I am trying to capture an event when the screensaver starts. I have code
working on Windows XP etc when the Password/Welcome Screen is enabled
[Workstation is Locked]. Using the Fast User Switching Notifications.

However I am unable to detect the screensaver starting when the screensaver
password option is disabled. When using the WndProc Overrides I am unable to
capture the screensaver event unless the application is active [Our software
often sits in the Windows system tray].

Thank you in advance for any help that is given. I am attempting to use a
Hook to capture the WM_GETMESSAGE Hook using VB.NET my code is as follows:
'--------------------------------------------------------

Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Public Class Screensaver

Dim hp As New HookProc(AddressOf KeyboardProc)

Public Const WH_GETMESSAGE = 3
Public Const HC_ACTION = 0

Private m_ScreensaverHook As IntPtr

Private Declare Auto Function UnhookWindowsHookEx Lib "user32" Alias
"UnhookWindowsHookEx" (ByVal hHook As IntPtr) As Integer
Private Declare Auto Function SetWindowsHookEx Lib "user32" (ByVal
idHook As Integer, ByVal lpfn As HookProc, ByVal hMod As Long, ByVal
dwThreadId As Integer) As IntPtr
Private Declare Auto Function CallNextHookEx Lib "user32" (ByVal curHook
As IntPtr, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As
Integer)
Private Delegate Function HookProc(ByVal code As Integer, ByVal wParam
As Integer, ByVal lParam As IntPtr) As IntPtr

' Events
Public Event Screensaver(ByVal m As Message)

Public Sub SetHook()
Dim hInstance As Long =
System.Runtime.InteropServices.Marshal.GetHINSTANC E(System.Reflection.Assembly.GetExecutingAssembly. GetModules()(0)).ToInt32()
Dim hThreadId As Integer = AppDomain.GetCurrentThreadId()
'Dim hThreadId As Integer = 0
m_ScreensaverHook = SetWindowsHookEx(WH_GETMESSAGE, hp, hInstance,
hThreadId)
End Sub

Public Sub Unhook()
If m_ScreensaverHook.ToInt32 <> 0 Then
UnhookWindowsHookEx(m_ScreensaverHook)
End Sub

Private Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As
Integer, ByVal lParam As IntPtr) As IntPtr

If (nCode < HC_ACTION) Then
Return CallNextHookEx(m_ScreensaverHook, nCode, wParam,
lParam.ToInt32)

ElseIf (nCode = HC_ACTION) Then
Dim m As Message
m = CType(Marshal.PtrToStructure(lParam, GetType(Message)),
Message)
Debug.WriteLine("Screensaver")
RaiseEvent Screensaver(m)
End If

End Function
End Class
Jul 21 '05 #1
0 4145

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

Similar topics

1
by: klappnase | last post by:
Hello everyone, does anyone know a way to stop the screensaver under linux from starting up while a certain process is running? I need this because I experience a memory leak while recording...
2
by: DanielB | last post by:
Does anyone know what the command line argumentto launch a screensaver's options/configuration dialog is on Windows XP Pro? From most of the example source code I can find on the web, it would...
4
by: Paul Smith | last post by:
I have been given an unusual task to create a Windows Service to do something periodically to make the screensaver timer reset. We have a general policy of locking computers automatically after 10...
0
by: Vaughn | last post by:
I'm working on a simple screensaver (it just displays a different image every 5 seconds) but I'm having trouble displaying an image in my form using the BackGroundImage property. I was trying to...
2
by: wushupork | last post by:
I have written a screensaver application in C# .NET and have noticed that whenever the animation loop is running - CPU usage always spikes up close to 100%. My application uses a paint thread which...
4
by: Simon Mercer | last post by:
I have been trying to build a screensaver that will connect to a database and display specific data depending on the user that is logged in. I have managed to get a simple data access screensaver...
3
by: sanjana | last post by:
hi i want to fire an event if the screen saver starts up i have done it using a timer tick event where i have used the api function to detect if screensaver has started..but this means continuous...
2
by: Boris Fortes | last post by:
I need to unhook event receiver as result of native C++ event. It unhooks successfully, but __raise does not return and throws access violation. Visual Studio 2003 How to reproduce: Consol...
0
by: Luke | last post by:
I am trying to capture an event when the screensaver starts. I have code working on Windows XP etc when the Password/Welcome Screen is enabled . Using the Fast User Switching Notifications. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...

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.