Welcome Guest [Log In] [Register]
Welcome to Abstracted.View. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Logging windows; Visual Basic.NET
Topic Started: Jul 18 2006, 04:41 PM (224 Views)
Hacker-X
Dedicated Member
[ *  *  *  * ]
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.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Visual Basic · Next Topic »
Add Reply