根据窗口句柄来获取进程ID

    [DllImport("User32.dll", CharSet = CharSet.Auto)]
    public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
    //根据窗口来获取进程ID,
       public static int GetCurrentProcessID()
    {
        int oo;
        GetWindowThreadProcessId(CurrentGameHandler, out oo);
        return oo;
    }
    //获取窗口句柄,我一般都是用lpClassName来获取特定窗口,曾经使用过lpWindowName,好像无法获取到窗口的句柄,不知道为什么;ps:可以使用vs自带的spy++工具来查看特定窗口的类名称
    [DllImport("User32.dll", EntryPoint = "FindWindow")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

你可能感兴趣的:(winAPI编程,WPF项目回顾)