T
Trammel
Hi. I have been trying to make a simple application that will sit in the
background and alert me of any changes in window focus (IE: Pop-up windows)
on my system.
I have used DirectTextToSpeech from Microsoft and tried the following
code...
The problem I am having is that it detects its own caption fine... but no
captions of other windows :¬/
Could someone please have a look at the following code and lemme know what
Im doing wrong?
===============================================================
Option Strict Off
Option Explicit On
Friend Class Form1Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
*** snip ***
#End Region
#Region "Upgrade Support "
*** snip ***
#End Region
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
DirectSS1.Pitch = CInt("100")
DirectSS1.Speed = CInt("150")
LastTitle = ""
DirectSS1.Sayit = "Hello!"
End Sub
Private Sub tmrScan_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrScan.Tick
Dim ThisTitle As String
ThisTitle = RetCurTitle()
If ThisTitle <> LastTitle Then
LastTitle = ThisTitle
DirectSS1.Sayit = "Window focus has changed."
DirectSS1.Sayit = "New window title is " + ThisTitle
Label1.Text = "New window title is " + ThisTitle
End If
End Sub
End Class
Module WindowScanner
Public Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
Public Declare Auto Function GetWindowText Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As
Integer) As Integer
Public LastTitle As String
Public Function RetCurTitle() As String
' Create a buffer of 256 characters
Dim Caption As New System.Text.StringBuilder(256)
Dim hWnd As IntPtr = GetActiveWindow()
GetWindowText(hWnd, Caption, Caption.Capacity)
Return Caption.ToString()
End Function
End Module
background and alert me of any changes in window focus (IE: Pop-up windows)
on my system.
I have used DirectTextToSpeech from Microsoft and tried the following
code...
The problem I am having is that it detects its own caption fine... but no
captions of other windows :¬/
Could someone please have a look at the following code and lemme know what
Im doing wrong?
===============================================================
Option Strict Off
Option Explicit On
Friend Class Form1Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
*** snip ***
#End Region
#Region "Upgrade Support "
*** snip ***
#End Region
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
DirectSS1.Pitch = CInt("100")
DirectSS1.Speed = CInt("150")
LastTitle = ""
DirectSS1.Sayit = "Hello!"
End Sub
Private Sub tmrScan_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrScan.Tick
Dim ThisTitle As String
ThisTitle = RetCurTitle()
If ThisTitle <> LastTitle Then
LastTitle = ThisTitle
DirectSS1.Sayit = "Window focus has changed."
DirectSS1.Sayit = "New window title is " + ThisTitle
Label1.Text = "New window title is " + ThisTitle
End If
End Sub
End Class
Module WindowScanner
Public Declare Function GetActiveWindow Lib "user32" () As System.IntPtr
Public Declare Auto Function GetWindowText Lib "user32" (ByVal hWnd As
System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As
Integer) As Integer
Public LastTitle As String
Public Function RetCurTitle() As String
' Create a buffer of 256 characters
Dim Caption As New System.Text.StringBuilder(256)
Dim hWnd As IntPtr = GetActiveWindow()
GetWindowText(hWnd, Caption, Caption.Capacity)
Return Caption.ToString()
End Function
End Module