NET/WFP Form Enumeration Class

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Windows;usingSystem.Xml;//Author:andy, 20140521//WPF under Form enumerationnamespaceDrawcanvas { Public classXmalwinenumhelper {Private Delegate BOOLEnumchilddelegateproc (IntPtr hWnd, IntPtr lParam);  Public structPoint { Public intX;  Public intY;  PublicPoint (intXinty) { This. X =x;  This. Y =y; }} [DllImport ("user32.dll")]        [return: MarshalAs (unmanagedtype.bool)]Private Static extern BOOLenumchildwindows (IntPtr hwndparent, Xmalwinenumhelper.enumchilddelegateproc lpenumfunc, IntPtr lParam); [DllImport ("user32.dll")]        Private Static extern BOOLScreenToClient (IntPtr hWnd,refxmalwinenumhelper.point lppoint); [DllImport ("user32.dll")]        Private Static extern intGetWindowText (IntPtr hWnd, StringBuilder lpstring,intnMaxCount); [DllImport ("user32.dll")]        [return: MarshalAs (unmanagedtype.bool)]Private Static extern BOOLiswindowvisible (IntPtr hWnd); //= Funciton         Public Staticlist<int>getchildwindows (IntPtr hwndparent) {List<int> list =Newlist<int>(); GCHandle value=GCHandle.Alloc (list); Xmalwinenumhelper.enumchilddelegateproc Lpenumfunc=NewXmalwinenumhelper.enumchilddelegateproc (XMALWINENUMHELPER.DOENUMCHILDWINDOWSPROC);            Xmalwinenumhelper.enumchildwindows (hWndParent, Lpenumfunc, gchandle.tointptr (value)); Value.            Free (); List.            Sort (); returnlist; }        Private Static BOOLDoenumchildwindowsproc (IntPtr hWnd, IntPtr lParam) {List<int> list = gchandle.fromintptr (LParam). Target aslist<int>; if(List! =NULL&&xmalwinenumhelper.iswindowvisible (hWnd)) {list.            ADD (Hwnd.toint32 ()); }            return true; }         Public Static BOOLConvertpointfromscreentoclient (IntPtr hWnd,refSystem.Windows.Point PT) {            if(Hwnd.toint32 () = =0) {                return false; } xmalwinenumhelper.point Point=NewXmalwinenumhelper.point ((int) pt. X, (int) pt.            Y); BOOLFlag = Xmalwinenumhelper.screentoclient (HWnd,refPoint ); if(flag) {pt. X= (Double) Point.x/1.0; Pt. Y= (Double) Point.y/1.0; }            returnFlag; }         Public Static stringGetwindowtitle (IntPtr hWnd) {StringBuilder StringBuilder=NewStringBuilder ( +); Xmalwinenumhelper.getwindowtext (HWnd, StringBuilder, +); returnstringbuilder.tostring (); }    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.