通过名称查找句柄,通过层级关系查找句柄,获得句柄窗口类名称
//FindWindow 从类名或窗口名中返回一个相匹配的顶层窗口的句柄 [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //GetWindow 返回指定窗口的句柄 [DllImport("user32.dll", EntryPoint = "GetWindow", SetLastError = true)] public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); //同级别第一个 private const int GW_HWNDFIRST = 0; //同级别最后一个 private const int GW_HWNDLAST = 1; //同级别下一个 private const int GW_HWNDNEXT = 2; //同级别上一个 private const int GW_HWNDPREV = 3; //属主窗口 private const int GW_OWNER = 4; //子窗口 private const int GW_CHILD = 5; //Enabled popup window有效的弹出窗口 private const int GW_ENABLEDPOPUP = 6; //GetClassName 检取指定窗口类的名称 [DllImport("user32.dll", EntryPoint = "GetClassName", CharSet = CharSet.Auto)] public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); //GetClassName 检取指定窗口的标题 [DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
评论前必须登录!
注册