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.

Source: Internet
Author: User

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.

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.