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 (); } }}