获取.NET应用程序的活动窗口 [英] Get Active Window of .net application
本文介绍了获取.NET应用程序的活动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为ProLaunch.exe的应用程序。我想在成为活动窗口,并关闭它,如果用户没有进行任何操作的期间speicified。在应用一个定时器将被用于此目的。
I have an application named ProLaunch.exe. I want to get the active window in it and close it if the user is not performing any operation for the speicified period. A timer in the application will be used for this purpose.
我怎样才能获得活动窗口并关闭它?
How can I get the active window and close it?
推荐答案
如果我理解正确的问题,你可以使用Win32 API的 GetActiveWindow 这一点。这应该在两个窗体和WPF应用程序。
If I understand the question correctly, you can use the Win32 API GetActiveWindow for this. This should work in both Forms and WPF apps.
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, IntPtr msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
// close the active window using API
private void FindAndCloseActiveWindow()
{
IntPtr handle=GetActiveWindow();
SendMessage(handle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
这篇关于获取.NET应用程序的活动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文