Iaccessible (2)

Source: Internet
Author: User

Next, we will share how to obtain the iaccessible interface of the sub-control. Before that, let's talk about other things:

For example:

 

The above shows the details of a control. Now we only care about classname, role, and name.

The following describes how to obtain the iaccessible interface of the sub-control.CodeFirst, let's look at the function definition:

 
Bool find (iaccessible * paccparent, lpstr szname, lpstr szrle, lpstr szclass, iaccessible ** paccchild, variant * pvarchild)

The first is the iacessible interface of the parent form, which is name, role, classname, and sub-control interface, which is similar to the ID (explained later)> see implementation:

Bool find (optional * paccparent, lpstr szname, lpstr szrle, lpstr szclass, optional ** paccchild, variant * pvarchild) {hresult hr; long numchildren; unsigned long numfetched; variant varchild; int indexcount; iaccessible * pcacc = NULL; ienumvariant * penum = NULL; idispatch * Pdisp = NULL; bool found = false; char szobjname [max_path], szobjrole [max_path], szobjclass [max_path], szobjstate [max_path]; // get The ienumvariant interfacehr = paccparent-> QueryInterface (iid_ienumvariant, (pvoid *) & penum); If (penum) penum-> Reset (); // get child countpaccparent-> get_accchildcount (& numchildren); For (indexcount = 1; indexcount <= numchildren &&! Found; indexcount ++) {pcacc = NULL; // get next childif (penum) HR = penum-> next (1, & varchild, & numfetched); else {varchild. vt = vt_i4; varchild. lval = indexcount;} // get idispatch interface for the childif (varchild. vt = vt_i4) {Pdisp = NULL; HR = paccparent-> get_accchild (varchild, & Pdisp);} elsepdisp = varchild. pdispval; // get iaccessible interface for the childif (Pdisp) {hR = Pdisp-> QueryInterface (I Id_iaccessible, (void **) & pcacc); HR = Pdisp-> release () ;}// get information about the childif (pcacc) {variantinit (& varchild); varchild. vt = vt_i4; varchild. lval = childid_self; * paccchild = pcacc;} else * paccchild = paccparent; // skip invisible and unavailable objects and their childrengetobjectstate (* paccchild, & varchild, szobjstate, sizeof (szobjstate); If (null! = Strstr (szobjstate, "unavailable") {If (pcacc) pcacc-> release (); continue;} getobjectname (* paccchild, & varchild, szobjname, sizeof (szobjname); getobjectrole (* paccchild, & varchild, szobjrole, sizeof (role); getobjectclass (* paccchild, szobjclass, sizeof (szobjclass); If ((! Szname |! Strcmp (szname, szobjname ))&&(! Szrle |! Strcmp (szrle, szobjrole ))&&(! Szclass |! Strcmp (szclass, szobjclass) {found = true; * pvarchild = varchild; break;} If (! Found & pcacc) {// go deeperfound = find (pcacc, szname, szrle, szclass, paccchild, pvarchild); If (* paccchild! = Pcacc) pcacc-> release () ;}// clean upif (penum) penum-> release (); return found ;}

Function for obtaining the control status:

Uint getobjectstate (iaccessible * pACC, variant * pvarchild, lpstr lpszstate, uint cchstate) {hresult hr; variant varretval; * lpszstate = 0; variantinit (& varretval ); hR = pACC-> get_accstate (* pvarchild, & varretval); If (! Succeeded (HR) Return (0); DWORD dwstatebit; int cchars = 0; If (varretval. vt = vt_i4) {// convert state flags to comma separated list. for (dwstatebit = state_system_unavailable; dwstatebit <state_system_alert_high; dwstatebit <= 1) {If (varretval. lval & dwstatebit) {cchars + = getstatetexta (dwstatebit, lpszstate + cchars, cchstate-cchars); * (lpszstate + cchars ++) = ',';}} if (cchars> 1) * (lpszstate + cchars-1) = '\ 0';} else if (varretval. vt = vt_bstr) {widechartomultibyte (cp_acp, 0, varretval. bstrval,-1, lpszstate, cchstate, null, null);} variantclear (& varretval); Return (lstrlena (lpszstate ));}
 

Used to obtain whether a widget is available. Let's look at an example:

 
Hwnd =: findwindoww (null, l "run"); iaccessible * paccmainwindow = NULL; accessibleobjectfromwindow (hwnd, objid_window, callback, (void **) & paccmainwindow ); long Count = 0; paccmainwindow-> get_accchildcount (& COUNT); iaccessible * pacccontrol = NULL; variantvarcontrol; If (find (paccmainwindow, "Open:", "editable text ", "edit", & pacccontrol, & varcontrol) {pacccontrol-> put_accvalue (varcontrol, ccombstr ("123 "));}

Running result:

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.