Finding System Idle Time and ur Customized form as display Screen saver


This article explains about Finding System Idle Time and ur Customized form as display Screen saver.

This Code will help u to trace the system ilde time and also you can display your own customized form as Screen Saver.



Add a timer control and three label , also a form in project to show as screen saver : name the form -->frmScreenSaver


Imports System.Runtime.InteropServices




Structure LASTINPUTINFO
Dim cbSize As Integer
Dim dwTime As Integer
End Structure

'Declare the following
Dim cnt As Integer
'Api to know the last user input
Declare Auto Function GetLastInputInfo Lib "User32.dll" (ByRef LastInputInfo As LASTINPUTINFO) As Boolean
Dim i As Integer
Dim lii As LASTINPUTINFO
Dim ret As Integer

Private Sub frmIdle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

'blnscreen is boolean varialbe declared as public in main module, to know the screen saver is on or not.
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If blnScreensaverOn = False Then
cnt = cnt + 1
End If
Label3.Text = cnt
Label3.Refresh()
If lii.dwTime - Environment.TickCount <= -60093 And cnt > 2 Then
Label1.Text = lii.dwTime - Environment.TickCount
cnt = 0
If blnScreensaverOn = False Then
Dim frmscreen As New frmScreenSaver
frmscreen.Show()
End If
Else
lii.cbSize = Marshal.SizeOf(lii)
ret = GetLastInputInfo(lii)
Label1.Text = "current tick=" & Environment.TickCount & ", last input tick=" & lii.dwTime
Label2.Text = lii.dwTime - Environment.TickCount
Label2.Refresh()
Label1.Refresh()
End If
End Sub




Comments

Author: Anand Vishwakarma28 Mar 2009 Member Level: Gold   Points : 0

Very nice document ......



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: