1. 程式人生 > >根據視窗控制代碼來獲取程序ID

根據視窗控制代碼來獲取程序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);