The advantage of UIAutomation is similar to the message handling mechanism, rather than sending messages primarily by simulating the mouse keyboard
Add references Uiautomationclient and Uiautomationtypes first, available on the computer where the. net3.5 is installed. The lower version of VS can directly reference the DLL.
Using System.Windows.Automation;
Use the traditional method to find the HWND, the UI can also be found, the new project should be unified to the UI
IntPtr Leftview = API. FindWindowEx (wd0, 0, "SysListView32", "Cfqs");
IntPtr Rightview = API. FindWindowEx (wd0, 0, "SysListView32", "List2");
if (Leftview = = IntPtr.Zero | | rightview = = IntPtr.Zero) return;
AutomationElement el = Automationelement.fromhandle (Leftview); Left view
AutomationElement er = automationelement.fromhandle (rightview); Right view
PropertyCondition CONDITION_BK = new PropertyCondition (Automationelement.controltypeproperty, ControlType.DataItem) ; Find sub-window conditions are also ListViewItem, on the left can only use Controltype.dataitem, the right side with Controltype.listitem
Automationelementcollection bks = el. FindAll (Treescope.children, CONDITION_BK); Gets the collection of all child windows that meet the criteria
There is also a way to traverse a sub-window with Treewalker
AutomationElement el = Automationelement.fromhandle (Leftview);
TreeWalker Walker = Treewalker.contentviewwalker;
for (AutomationElement child = Walker. Getfirstchild (EL); Child! = NULL; Child = Walker. Getnextsibling (child))//{
String Name=child. Current.name
//}
Api.mouse_event ((int) (Mouseeventflags.wheel | Mouseeventflags.absolute), 0, 0, -380, IntPtr.Zero); Let the scroll bar roll down, only for visual effects, not also line
Selectionitempattern Selpattern = (selectionitempattern) item. Getcurrentpattern (Selectionitempattern.pattern);
Selpattern.select (); Select the Palette//Implement ListView Interior Element selection
Item. Current.name the contents of the ListView inner element
PropertyCondition condition = new PropertyCondition (Automationelement.isenabledproperty, true); All non-disabled items can be generalized as types
2016.9.2 Supplement
Entering content into a control
automationelement element = Automationelement.fromhandle (Edbox);
Object valuepattern = null;
if (element. Trygetcurrentpattern (Valuepattern.pattern, out ValuePattern))//Whether direct write is supported
{
Set focus for input functionality and begin.
Element. SetFocus ();
((ValuePattern) valuepattern). SetValue (FullPath);
}
else//otherwise analog typing
{
Set focus for input functionality and begin.
Element. SetFocus ();
Pause before sending keyboard input.
Thread.Sleep (100);
Delete existing content in the control and insert new content.
Sendkeys.sendwait ("^{home}"); Move to start of control
Sendkeys.sendwait ("^+{end}"); Select everything
Sendkeys.sendwait ("{DEL}"); Delete selection
Sendkeys.sendwait (FullPath);
}
2015.4.25 using the UIAutomation substitution API function, the problem of the ListView cannot read data is solved, and the mouse simulation wheel is realized by the way.