Question

I'm developing an application and there is a portion of the code that i want to run only when the screensaver is running but i cant find a way to do it, i searched all over the web and i find only solutions for c++ and c#.

I know that in C++ when can use SystemParametersInfo to find out, but in Visual Basic 2012 i don't know of a way, i tried using it but it says its not declared.

Is there something that i have to import? Is there a way to find out if the screensaver is running?

Was it helpful?

Solution

I have found this way, which detects when the screensaver starts and stops:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

    Const WM_SYSCOMMAND As Integer = &H112
    Const SC_SCREENSAVE As Integer = &HF140

    MyBase.WndProc(m)
    If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_SCREENSAVE Then
        MsgBox("Capturado screensaver" & Now.ToLongTimeString)
        AddHandler Application.Idle, AddressOf Application_Idle
    End If
End Sub

Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)

    MsgBox("Capturada actividade" & Now.ToLongTimeString)
    RemoveHandler Application.Idle, AddressOf Application_Idle
End Sub

Basically what I did was to detect the screensaver activation and at that time I create a handler for the Idle event so, when i get user activity (which is what stops the screensaver) I know when the screensaver stopped.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top