我怎样才能获得CurrentWindow?

时间:2010-03-20 11:08:14

标签: c#

是的,我想获得另一个应用程序的子窗口。  给我总结想法或代码

1 个答案:

答案 0 :(得分:1)

以下是如何使用FindWindow检索窗口句柄的标题:

class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    static void Main(string[] args)
    {
        var hWnd = FindWindow(null, "Untitled - Notepad");
        if (hWnd != IntPtr.Zero)
        {
            Console.WriteLine("window found");
        }
        else
        {
            Console.WriteLine("No window with given title has been found");
        }
    }
}