首页 > 代码库 > Net/WFP窗体枚举类
Net/WFP窗体枚举类
using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; using System.Windows; using System.Xml; // author: andy , 20140521 // WPF下窗体枚举 namespace DrawCanvas { public class XmalWinEnumHelper { private delegate bool EnumChildDelegateProc(IntPtr hWnd, IntPtr lParam); public struct POINT { public int X; public int Y; public POINT(int x, int y) { this.X = x; this.Y = y; } } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EnumChildWindows(IntPtr hwndParent, XmalWinEnumHelper.EnumChildDelegateProc lpEnumFunc, IntPtr lParam); [DllImport("user32.dll")] private static extern bool ScreenToClient(IntPtr hWnd, ref XmalWinEnumHelper.POINT lpPoint); [DllImport("user32.dll")] private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool IsWindowVisible(IntPtr hWnd); //=> FUNCITON public static List<int> GetChildWindows(IntPtr hWndParent) { List<int> list = new List<int>(); GCHandle value = GCHandle.Alloc(list); XmalWinEnumHelper.EnumChildDelegateProc lpEnumFunc = new XmalWinEnumHelper.EnumChildDelegateProc(XmalWinEnumHelper.DoEnumChildWindowsProc); XmalWinEnumHelper.EnumChildWindows(hWndParent, lpEnumFunc, GCHandle.ToIntPtr(value)); value.Free(); list.Sort(); return list; } private static bool DoEnumChildWindowsProc(IntPtr hWnd, IntPtr lParam) { List<int> list = GCHandle.FromIntPtr(lParam).Target as List<int>; if (list != null && XmalWinEnumHelper.IsWindowVisible(hWnd)) { list.Add(hWnd.ToInt32()); } return true; } public static bool ConvertPointFromScreenToClient(IntPtr hWnd, ref System.Windows.Point pt) { if (hWnd.ToInt32() == 0) { return false; } XmalWinEnumHelper.POINT pOINT = new XmalWinEnumHelper.POINT((int)pt.X, (int)pt.Y); bool flag = XmalWinEnumHelper.ScreenToClient(hWnd, ref pOINT); if (flag) { pt.X = (double)pOINT.X / 1.0; pt.Y = (double)pOINT.Y / 1.0; } return flag; } public static string GetWindowTitle(IntPtr hWnd) { StringBuilder stringBuilder = new StringBuilder(512); XmalWinEnumHelper.GetWindowText(hWnd, stringBuilder, 512); return stringBuilder.ToString(); } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。