Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Automation;
- using System.Runtime.InteropServices;
- namespace ConsoleApplication6
- {
- class Program
- {
- [StructLayout(LayoutKind.Sequential)]
- private struct POINT
- {
- public int x;
- public int y;
- };
- [DllImport("user32.dll")]
- private static extern IntPtr WindowFromPoint(POINT pt);
- [DllImport("user32.dll")]
- private static extern int GetCursorPos(out POINT pt);
- static void Main(string[] args)
- {
- Console.WriteLine("Place pointer over listview and hit return...");
- Console.ReadLine();
- // Get cursor position, then the window handle at that point...
- POINT pt;
- GetCursorPos(out pt);
- IntPtr hwnd = WindowFromPoint(pt);
- // Get the AutomationElement that represents the window handle...
- AutomationElement el = AutomationElement.FromHandle(hwnd);
- // Walk the automation element tree using content view, so we only see
- // list items, not scrollbars and headers. (Use ControlViewWalker if you
- // want to traverse those also.)
- TreeWalker walker = TreeWalker.ContentViewWalker;
- int i = 0;
- for( AutomationElement child = walker.GetFirstChild(el) ;
- child != null;
- child = walker.GetNextSibling(child) )
- {
- // Print out the type of the item and its name
- Console.WriteLine("item {0} is a \"- {1} -\" with name \"- {2} -\"", i++, child.Current.LocalizedControlType, child.Current.ToString() );
- int k = 0;
- for (AutomationElement child2 = walker.GetFirstChild(child);
- child2 != null;
- child2 = walker.GetNextSibling(child2))
- {
- Console.WriteLine("Child2 == item {0} is a \"- {1} -\" with name \"- {2} -\"", k++, child2.Current.LocalizedControlType, child2.Current.ClassName);
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement