activate submenu command using IAccessible (MSAA)

1

I am trying to automate one of my context menus and I took a dive into active accessibility. The documentation and code samples are very poor... after a lot of trial and error I managed to activate menu commands appearing in the "main" context menu: (after a WM_CONTEXTMENU)

// rough sketch of the code without error checking etc
CComQIPtr<IAccessible> iacc;
AccessibleObjectFromWindow(FindWindow(L"#32768",0), OBJID_CLIENT, IID_PPV_ARGS(&iacc));
CComVariant varId(CHILDID_SELF);
hr = iacc->get_accRole(varId, &out); //ROLE_SYSTEM_MENUPOPUP
varId.lVal = menu_cmd_offset + 1;
hr = iacc->accDoDefaultAction(varId); // command executs correctly!

The problem is when I try to do the same for a command in a submenu. I can obtain the submenu child object but its accDoDefaultAction fails with 0x80020003 (method not found)

LPDISPATCH pp = 0;
varId.lVal = submenu_offset + 1;
hr = iacc->get_accChild(varId, &pp);
iacc = pp;
pp->Release();
// this item isn't the submenu, we need ITS single child!
varId.lVal = 1;
hr = iacc->get_accChild(varId, &pp);
iacc = pp; //ROLE_SYSTEM_MENUPOPUP
pp->Release();
// try to execute from this submenu...
varId.lVal = sub_cmd_offset + 1;
hr = iacc->accDoDefaultAction(varId); // FAIL!
hr = iacc->get_accDefaultAction(varId, &name); //=Execute, why not do it!?
hr = iacc->get_accName(varId, &name); // "paste" or whatever

The oxymoron is that whereas the submenu command will not execute, I can get information about it, e.g. get_accName to see its name!!??

The only explanation I could give is that the submenu doesn't show on the screen when it fails. The "main" menu succeeds (perhaps) because it is visible. But I tried to open the submenu with its accDoDefaultAction and it will just select it, without opening the popup

any tips for an MSAA virgin? :) how can I open and execute commands from a submenu? thanks

c++
winapi
accessibility
atl
asked on Stack Overflow May 23, 2017 by nikos

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0