找到哪个(子)窗口具有焦点的方法? [英] A way to find which (sub) window has the focus?

查看:61
本文介绍了找到哪个(子)窗口具有焦点的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正试图找到一种方法来确定哪个窗口在另一个程序中

目前有焦点。


情况:(如果您不想要

背景,请跳至我的问题)


*这是一个人们办理登机手续的服务台。使用某个设施

或面积。

*该公司正在运行他们现成购买的应用程序。

*该应用程序接受来自串口的成员号输入

条码卡扫描器。

*卡片扫描器只是将刷卡数据输入键盘缓冲区。 />
示例:" / 123456 \"

*应用程序有一个窗口,通常是活动的,接受会员登记

数字。

*但它也有其他形式(设置,成员编辑等生活)

*如果某个成员滑动他们的特定窗口没有活动

卡...输入丢失。


我正在尝试编写一个可以捕获任何键盘输入的程序。

如果它匹配斜杠格式 - ###### - 斜杠 - 那么我知道它是会员

数字。

如果输入会员号码 ;表单是活动的,我只需要通过

传递数据。

如果其他东西是活动的,我会捕获这些数据并给他们一个方法

稍后再访问它。

我的问题:


使用下面的代码,我可以找出哪个APPLICATION处于活动状态。

但是在应用程序中,有各种各样的窗口。

有没有办法让我知道哪个子窗口?有焦点吗?


注意:

我想我必须有办法因为......考虑ALT-PRINT-SCREEN
按钮。

如果按Print-Screen,它会将整个屏幕复制到缓冲区

但按Alt-Print-Screen,仅复制当前活动子窗口

到缓冲区。

所以,不知何故,windows知道哪个子窗口是活动的。


Of当然可以。它必须。但我怎么能在VB中找到这个呢?

谢谢,

加里

我想要找到哪个窗口是活动的代码:

(但是不知道应用程序中的哪个文档/子窗口是

有效)


私有声明函数GetForegroundWindow Lib " USER32.DLL" ()作为IntPtr


私有声明函数GetWindowThreadProcessId Lib" user32.dll" (ByVal

hwnd As IntPtr,ByRef lpdwProcessID As Integer)as Integer


Private Sub timerActiveWindowCheck_Tick(ByVal sender As System.Object,ByVal
$ b $ as As System.EventArgs)处理timerActiveWindowCheck.Tick


''-----在窗口中放一个星号,所以我知道它做了些什么。


txtActiveWindow.Text = txtActiveWindow.Text +" *" &安培; vbCrLf


Dim hWnd As IntPtr = GetForegroundWindow()


如果hWnd = IntPtr.Zero则退出Sub


Dim pid As Integer = 0


如果0 = GetWindowThreadProcessId(hWnd,pid)则退出Sub


Dim proc As Process = Process.GetProcessById(pid)


如果proc为Nothing则退出Sub


txtActiveWindow.Text = txtActiveWindow.Text + proc.ProcessName& ; " - &

proc.MainWindowTitle& vbCrLf


End Sub


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

推荐答案

Gary写道:
Gary wrote:

我正试图找到一种方法来确定哪个窗口

在另一个程序中目前有焦点。


使用下面的代码,我可以找出哪个APPLICATION处于活动状态。

但是在应用程序中,有各种各样的窗口。

我有什么办法可以告诉哪个子窗QUOT;有焦点吗?


Dim hWnd As IntPtr = GetForegroundWindow()
I''m trying to find a way to determin which window
Within-Another-Program currently has the focus.
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?
Dim hWnd As IntPtr = GetForegroundWindow()



不是吗?


你继续获得拥有它的进程,以及那个

进程的主窗口标题,但是这个hWnd应该是活动窗口。

Isn''t that it?

You go on to get the process that owns it, and the the main window title of that
process, but this hWnd should be the active window.




" Steve Gerrard" < my ******** @ comcast.netwrote in message

news:tv ********************** ********@comcast.com。 ..

"Steve Gerrard" <my********@comcast.netwrote in message
news:tv******************************@comcast.com. ..

>>

Dim hWnd As IntPtr = GetForegroundWindow()
>>

Dim hWnd As IntPtr = GetForegroundWindow()



不是吗?


你继续获得拥有它的进程,以及主窗口标题

该过程,但这个hWnd应该是活动窗口。


Isn''t that it?

You go on to get the process that owns it, and the the main window title
of that process, but this hWnd should be the active window.



不完全。


这将返回APPLICATION的名称。


但应用程序有各种窗口可以在其中打开。


For exaple,取MS-Word。

*" MS-Word"是应用程序。

*你可以和一个有焦点的用户文档。

*或者你有Borders& amp;遮光"工具箱表单打开

*您可以使用工具选项形式开放。


上面的内容总是只返回MS-Word,无论是哪个

" sub form" (这里正确的术语?)目前是活跃的。


我需要一种方法来了解哪个子形式是开放的。


感谢您的兴趣,

Gary

Not quite.

This returns the name of the APPLICATION.

But the application has various windows that can be open within it.

For exaple, take MS-Word.
* "MS-Word" is the application.
* You can and a user document that has focus.
* Or you have have the "Borders & Shading" tool box form open
* Of you can have the "Tools Options" form open.

What I have above always returns just "MS-Word", no matter which
"sub form" (correct term here?) is currently active.

I need a way to know which "sub form" is open.

Thanks for taking an interest,
Gary




Steve Gerrard < my ******** @ comcast.netwrote in message

news:tv ********************** ********@comcast.com。 ..

"Steve Gerrard" <my********@comcast.netwrote in message
news:tv******************************@comcast.com. ..

>>
Dim hWnd As IntPtr = GetForegroundWindow()
>>
Dim hWnd As IntPtr = GetForegroundWindow()



不是吗?


你继续获得拥有它的进程,以及主窗口标题
$ b这个过程的$ b,但是这个hWnd应该是活动窗口。


Isn''t that it?

You go on to get the process that owns it, and the the main window title
of that process, but this hWnd should be the active window.



我觉得我可能非常接近,但我只是错过了一些明显的

参数或其他什么来得到我想要的东西。

I feel like I''m maybe very close but am just missing some obvious
parameter or something to get what I want.


这篇关于找到哪个(子)窗口具有焦点的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆