我正在尝试自动化我的context menus之一,并且我深入了解了主动辅助功能。文档和代码示例非常差...经过大量的试验和错误后,我设法激活出现在“主”上下文菜单中的菜单命令:(在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!
问题是当我尝试对子菜单中的命令执行相同操作时。我可以获取子菜单子对象,但其accDoDefaultAction
失败,0x80020003(找不到方法)
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
矛盾的是,虽然子菜单命令不会执行,但我可以获得有关它的信息,例如: get_accName
看到它的名字!! ??
我能给出的唯一解释是,子菜单在失败时不会显示在屏幕上。 “主”菜单成功(可能)因为它是可见的。但我尝试用accDoDefaultAction
打开子菜单,只需选择,而无需打开弹出窗口
MSAA处女的任何提示? :) 如何从子菜单打开和执行命令? 感谢