|
Viewing Single Post From: Logging windows
|
|
Hacker-X
|
Jul 18 2006, 04:41 PM
|
- Posts:
- 512
- Group:
- Admin
- Member
- #50
- Joined:
- March 6, 2005
|
Lets start by creating a new textbox, use the default settings. You'll also need a timer with an interval of 1 millisecond.
Switch to code view and paste this code:
- Code:
-
Public Class Form1 Private Declare Function GetForegroundWindow Lib "user32" () As Integer Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim hWnd As Integer Static OldhWnd As Integer Dim iReturn As Integer Dim s As New System.Text.StringBuilder(256)
hWnd = GetForegroundWindow If OldhWnd = hWnd Then Exit Sub OldhWnd = hWnd Debug.WriteLine("New Window Handle : " & hWnd.ToString) iReturn = GetWindowText(hWnd, s, 256) Debug.WriteLine("Number of Characters : " & iReturn.ToString) TextBox1.Text = TextBox1.Text & "Window Changed to: " & s.ToString & vbNewLine & vbNewLine End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True End Sub End Class
When running the code just switch windows and it'll write the window caption, of the current window, to the textbox.
Note: I came across this code while searching the MSDN forums. I got the original code from this article. I modified the code so that it actually logs everything to the textbox.
|
|
|