G
Gary
I'm trying to find a way to determin which window Within-Another-Program
currently has the focus.
THE SITUATION: (Skip down to "My Question" if you don't want the
background...)
* This is a service desk where people "check in" to use a certain facility
or area.
* The company is running an application they purchased off-the-shelf.
* The application accepts input of member numbers from a serial-port
bar-code card-scanner.
* The card scanner just pipes the swiped card data into the keyboard buffer.
Example: "/123456\"
* The application has a window, usually active, to accept member check-in
numbers.
* But it has other forms too (life for setup, member edit, etc.)
* If that particular window is not active when a member slides their
card...the input is lost.
I'm trying to write a program that will capture any keyboard input.
If it matches the format slash-######-slash -- then I know it's a member
number.
If the "Enter Member Number" form is active, I'll just pass the data on
through.
If something else is active, I'll capture this data and give them a way to
access it later.
MY QUESTION:
Using the code below, I can find out which APPLICATION is active.
But within the application, there are various windows.
Is there a way I can tell which "sub-window" has the focus?
NOTE:
I'M thinking there must be a way because...consider the ALT-PRINT-SCREEN
button.
If you press Print-Screen, it copies the entire screen to a buffer
But pressing Alt-Print-Screen, copies only the currently active sub-window
to the buffer.
So, somehow, windows knows which sub-window is active.
Of course it does. It has to. But how can I find this in VB
THANKS,
Gary
CODE I'M USING To FIND WHICH WINDOW IS ACTIVE:
(But does not tell which document / sub-window with-in the application is
active)
Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal
hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
Private Sub timerActiveWindowCheck_Tick(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles timerActiveWindowCheck.Tick
'----- Put an asterisk in the window so I know it did something.
txtActiveWindow.Text = txtActiveWindow.Text + "*" & vbCrLf
Dim hWnd As IntPtr = GetForegroundWindow()
If hWnd = IntPtr.Zero Then Exit Sub
Dim pid As Integer = 0
If 0 = GetWindowThreadProcessId(hWnd, pid) Then Exit Sub
Dim proc As Process = Process.GetProcessById(pid)
If proc Is Nothing Then Exit Sub
txtActiveWindow.Text = txtActiveWindow.Text + proc.ProcessName & " -- " &
proc.MainWindowTitle & vbCrLf
End Sub
currently has the focus.
THE SITUATION: (Skip down to "My Question" if you don't want the
background...)
* This is a service desk where people "check in" to use a certain facility
or area.
* The company is running an application they purchased off-the-shelf.
* The application accepts input of member numbers from a serial-port
bar-code card-scanner.
* The card scanner just pipes the swiped card data into the keyboard buffer.
Example: "/123456\"
* The application has a window, usually active, to accept member check-in
numbers.
* But it has other forms too (life for setup, member edit, etc.)
* If that particular window is not active when a member slides their
card...the input is lost.
I'm trying to write a program that will capture any keyboard input.
If it matches the format slash-######-slash -- then I know it's a member
number.
If the "Enter Member Number" form is active, I'll just pass the data on
through.
If something else is active, I'll capture this data and give them a way to
access it later.
MY QUESTION:
Using the code below, I can find out which APPLICATION is active.
But within the application, there are various windows.
Is there a way I can tell which "sub-window" has the focus?
NOTE:
I'M thinking there must be a way because...consider the ALT-PRINT-SCREEN
button.
If you press Print-Screen, it copies the entire screen to a buffer
But pressing Alt-Print-Screen, copies only the currently active sub-window
to the buffer.
So, somehow, windows knows which sub-window is active.
Of course it does. It has to. But how can I find this in VB
THANKS,
Gary
CODE I'M USING To FIND WHICH WINDOW IS ACTIVE:
(But does not tell which document / sub-window with-in the application is
active)
Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal
hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
Private Sub timerActiveWindowCheck_Tick(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles timerActiveWindowCheck.Tick
'----- Put an asterisk in the window so I know it did something.
txtActiveWindow.Text = txtActiveWindow.Text + "*" & vbCrLf
Dim hWnd As IntPtr = GetForegroundWindow()
If hWnd = IntPtr.Zero Then Exit Sub
Dim pid As Integer = 0
If 0 = GetWindowThreadProcessId(hWnd, pid) Then Exit Sub
Dim proc As Process = Process.GetProcessById(pid)
If proc Is Nothing Then Exit Sub
txtActiveWindow.Text = txtActiveWindow.Text + proc.ProcessName & " -- " &
proc.MainWindowTitle & vbCrLf
End Sub