Imports System
Imports System.io
Module Module1
private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
'Win32 Api
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Sub Main()
Dim bt As Boolean = True
' ä¿�å˜æ ‡é¢˜æ–‡æœ¬
Dim stext As String
' ä¿�å˜ä¸Šä¸€ä¸ªçª—å�£å�¥æŸ?
Dim hwnd As Long
' ä¿�å˜å½“å‰�窗å�£å�¥æŸ„
Dim curHwnd As Long
' 书写�写入日志文�
Dim sw As StreamWriter
' 日志文件ä¿�å˜è·¯å¾„
Dim path As String = "c:log.txt"
' 如果å˜åœ¨æ—¥å¿—文件则跳过,å�¦åˆ™åˆ›å»ºä¸€ä¸ªæ—¥å¿—æ–‡ä»?
If Not File.Exists(path) Then
File.Create(path)
End If
sleep(3000)
' 这里是个æ»å¾ªçŽ?
While bt
stext = Space(255)
' 获�当�窗��柄
hwnd = GetForegroundWindow
' 如果当å‰�是新窗å�£åˆ™å†™å…¥æ–°çª—å�£æ ‡é¢˜
If hwnd <> curHwnd Then
curHwnd = hwnd
' 获å�–窗å�£æ ‡é¢˜
GetWindowText(hwnd,stext,255)
sw = System.IO.File.AppendText(path)
' 写入新窗å�£æ ‡é¢?æ ¼å¼� yyyyå¹´mm月ddæ—?hh:hh:ss + æ ‡é¢˜
Using sw
sw.WriteLine(String.Format("{0:F}", DateTime.Now) +" "+ stext)
sw.Flush()
End Using
End If
sleep(2000)
End While
End Sub
End Module