0

如何通过 Win32 获取窗口的所有句柄?我找到了这段代码,但我不知道它是如何工作的!

[DllImport("user32.dll")]
  [return: MarshalAs(UnmanagedType.Bool)]
  static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc,   IntPtr lParam);

  private List<IntPtr> GetChildWindows(IntPtr parent)  
  {  
    List<IntPtr> result = new List<IntPtr>();  
    GCHandle listHandle = GCHandle.Alloc(result);  
    try  
    {  
         EnumWindowProc childProc = new EnumWindowProc(EnumWindow);  
         EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));  
    }  
    finally  
    {  
         if (listHandle.IsAllocated)  
               listHandle.Free();  
    }  
    return result;  
   }
4

0 回答 0