我用如下方法得到了当前活动窗口的Title信息和句柄Handler号码,但是这个信息没有办法了解当前活动的窗口属于什么类型。比如我用IE打开Google,这个方法只返回“Google”而不是“Internet Explorer”。有什么方法能了解活动窗口的类型么?多谢。附上得到窗口Title的方法:
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern int GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(int hWnd, StringBuilder text, int count);
public string GetActiveWindowInformation()
{
string activeWindowInfo = "";
const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars); handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0)
{
activeWindowInfo = Buff.ToString() + ":\n" + handle.ToString();
}
return activeWindowInfo.Substring(0,49);
}
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern int GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(int hWnd, StringBuilder text, int count);
public string GetActiveWindowInformation()
{
string activeWindowInfo = "";
const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars); handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0)
{
activeWindowInfo = Buff.ToString() + ":\n" + handle.ToString();
}
return activeWindowInfo.Substring(0,49);
}
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
this.richTextBox1.Text += ("Process:" + theprocess.ProcessName + "\tID:" +
theprocess.MainWindowHandle + "\n\n");
}