在C#中检测活动/重点窗口

Detect active/focused window in C#
2021-07-21
  •  译文(汉语)
  •  原文(英语)

我将如何检测C#中当前处于活动状态且当前正在关注的窗口?Likes以Windows Media Player为例.我将如何检测该窗口当前是否在C#中并集中在该窗口上?

谢谢!

速聊1:
解决过程1

您可以GetForegroundWindow为此使用Win32 .但是,这只会给您一个句柄(a HWND).您将需要使用其他P / Invoke方法来实际执行一些有用的操作.

有关更多信息,请参见http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms633505(v=vs.85).aspxGetForegroundWindowhttp://www.pinvoke.net/default.aspx/ user32.getforegroundwindow,以了解如何从C#访问此窗口.

How would I be able to detect what window is active and currently being focused on in C#? Likes lets take Windows Media player for example. How would I detect if that window is currently up and being focused on in C#?

Thank you!

Talk1:
Looks like a duplicate of stackoverflow.com/questions/115868/…
Solutions1

You can use the Win32 GetForegroundWindow for this. However, this will only get you a handle (a HWND). You will need to use further P/Invoke methods to actually do something useful with this.

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx for more information on GetForegroundWindow and http://www.pinvoke.net/default.aspx/user32.getforegroundwindow for how to access this from C#.

转载于:https://stackoverflow.com/questions/17397635/detect-active-focused-window-in-c-sharp

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入