Net/WFP表單枚舉類

來源:互聯網
上載者:User

標籤:style   c   class   blog   code   java   

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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.