我用如下方法得到了当前活动窗口的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);
        }

解决方案 »

  1.   

    多谢啊,你是说遍历Process么?那样的话怎么比对这个Handler的号码和Process的号码?他们是一样的?有没有什么实例代码?
      

  2.   

    多谢多谢,我后来这样使用MainWindowHandle属性成功了:这个属性和上面的handle是一样的
    Process[] processlist = Process.GetProcesses();
    foreach(Process theprocess in processlist){
        this.richTextBox1.Text += ("Process:" + theprocess.ProcessName + "\tID:" +  
        theprocess.MainWindowHandle + "\n\n");
    }