L
Larry Dodd
I am trying to write an application that sits in the system tray and just
monitors for a certain Window to be opened. Once this window is opened all
keystrokes will be captured. I have the key capture working correctly but
cant seem to get the Window thing working.
I think I need to use GetActiveWindow and GetWindowText but not sure. These
are the functions that I am using:
Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
' Create string filled with null characters.
Dim strCaption As String
Dim lngLen As Long
Dim currentForm As Form = Form.ActiveForm
Try
' Return length of string.
lngLen = 256
' Call GetActiveWindow to return handle to active window,
' and pass handle to GetWindowText, along with string and its length.
If (GetWindowText(GetForegroundWindow, strCaption, lngLen) > 0 Then
strCaption = GetWindowText(GetForegroundWindow, strCaption, lngLen
' Return value that Windows has written to string.
Return strCaption
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
I am using a timer control to fire the procedure that will look for the
current window's caption.
If someone could tell me how to do this in VB.NET I would really appreciate
it.
monitors for a certain Window to be opened. Once this window is opened all
keystrokes will be captured. I have the key capture working correctly but
cant seem to get the Window thing working.
I think I need to use GetActiveWindow and GetWindowText but not sure. These
are the functions that I am using:
Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
' Create string filled with null characters.
Dim strCaption As String
Dim lngLen As Long
Dim currentForm As Form = Form.ActiveForm
Try
' Return length of string.
lngLen = 256
' Call GetActiveWindow to return handle to active window,
' and pass handle to GetWindowText, along with string and its length.
If (GetWindowText(GetForegroundWindow, strCaption, lngLen) > 0 Then
strCaption = GetWindowText(GetForegroundWindow, strCaption, lngLen
' Return value that Windows has written to string.
Return strCaption
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
I am using a timer control to fire the procedure that will look for the
current window's caption.
If someone could tell me how to do this in VB.NET I would really appreciate
it.