Public Class Form1
Private WithEvents tmr As New System.Windows.Forms.Timer
Private Declare Auto Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tmr.Interval = TimeSpan.FromMinutes(5).TotalMilliseconds
tmr.Start()
End Sub
Private Sub tmr_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick
Dim foreWnd As IntPtr = GetForegroundWindow
For Each P As Process In Process.GetProcesses
If P.MainWindowHandle.Equals(foreWnd) Then
Debug.Print("Current Time: " & DateTime.Now)
Debug.Print("Process Name: " & P.ProcessName)
Debug.Print("Process Title: " & P.MainWindowTitle)
Debug.Print("-----------------------------------------------------------")
Exit For
End If
Next
End Sub
End Class
|