打开microsoft help viewer2.0,切换到favorites窗口。
添加列表框,变量名为m_list1;
在OnInitDialog里面添加:
CListCtrl* lst1 = (CListCtrl*)GetDlgItem(IDC_LIST1);
lst1->ModifyStyle( 0, LVS_REPORT ); // 报表模式
lst1->SetExtendedStyle(lst1->GetExtendedStyle()
| LVS_EX_GRIDLINES
| LVS_EX_FULLROWSELECT
| LVS_EX_CHECKBOXES
);
lst1->InsertColumn(0,_T("Favorites List"));
lst1->SetColumnWidth(0,600);
新建一个button,在button里面添加如下代码:
HRESULT hRes;
HWND MainHwnd;
TCHAR tcMainHwnd[MAX_PATH] = {0};//新建一个文本输入框,用SPY++获取microsoft help viewer 2.0 的类名
m_edit.GetWindowTextW(tcMainHwnd, MAX_PATH);//tcMainHwnd 为microsoft help viewer 2.0 的类名
MainHwnd = ::FindWindow(tcMainHwnd, NULL);
if(!MainHwnd){
AfxMessageBox(L"DEBUG: Unable to find main IE window");
return;
}
IAccessible *MainHwndAccess;
if(AccessibleObjectFromWindow(MainHwnd, OBJID_WINDOW, IID_IAccessible, (void **)&MainHwndAccess) != S_OK){
AfxMessageBox(L"DEBUG: Unable to get IAccessible interface");
return;
}
long inMainHwndCount = 0;
hRes = MainHwndAccess->get_accChildCount(&inMainHwndCount);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: Unable to get Objects count");
return;
}
long outMainHwndCount = 0;
VARIANT vMainHwnd[MAX_PATH];
hRes = AccessibleChildren(MainHwndAccess, 0, inMainHwndCount, vMainHwnd, &outMainHwndCount);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: Unable to get objects");
return;
}
for(int i = 0; i < outMainHwndCount; i++){//第1级,7个孩子
if(vMainHwnd[i].vt==VT_DISPATCH){
IDispatch *IdspMainHwnd = vMainHwnd[i].pdispVal;
IAccessible *IChildWNDAccess;
hRes=IdspMainHwnd->QueryInterface(IID_IAccessible,(void **)&IChildWNDAccess);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: QueryInterface to tabObject failed");
continue;
}
VARIANT vChildWnd[MAX_PATH];
VARIANT vChildWndType;
VARIANT vChildWndRole;
vChildWndRole.vt = VT_I4;
vChildWndRole.lVal = CHILDID_SELF;
hRes=IChildWNDAccess->get_accRole(vChildWndRole, &vChildWndType);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: Unable to receive object role");
continue;
}
if(vChildWndType.lVal != ROLE_SYSTEM_WINDOW)
continue;
long inChildWNDCount = 0;
hRes=IChildWNDAccess->get_accChildCount(&inChildWNDCount);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: tab count failed");
continue;
}
long outChildWNDCount = 0;
hRes=AccessibleChildren(IChildWNDAccess,0,inChildWNDCount,vChildWnd,&outChildWNDCount);//第2级,5个孩子
for(int j = 0; j < outChildWNDCount; j++){
IDispatch *IdispPaneChildChild = vChildWnd[j].pdispVal;
IAccessible *IPaneChildChildAccess;
hRes=IdispPaneChildChild->QueryInterface(IID_IAccessible,(void **)&IPaneChildChildAccess);
if(!SUCCEEDED(hRes)){
AfxMessageBox(L"DEBUG: QueryInterface to newObj failed");
continue;
}
VARIANT vChildChild;
VARIANT vChildChildRole;
vChildChildRole.vt=VT_I4;
vChildChildRole.lVal=CHILDID_SELF;
IPaneChildChildAccess->get_accRole(vChildChildRole, &vChildChild);
if (vChildChild.lVal != ROLE_SYSTEM_PANE){
continue;
}
long inChildChildCount = 0;
IPaneChildChildAccess->get_accChildCount(&inChildChildCount);
VARIANT vChildChildWnd[MAX_PATH];
long outChildChildCount = 0;
AccessibleChildren(IPaneChildChildAccess,0,inChildChildCount,vChildChildWnd,&outChildChildCount);//第3级,5个孩子
for (int K = 0; K < outChildChildCount; K++){
IDispatch *IdispGreatgrandchildren = vChildChildWnd[K].pdispVal;
IAccessible *IGreatgrandchildren;
IdispGreatgrandchildren->QueryInterface(IID_IAccessible, (void **)&IGreatgrandchildren);
VARIANT varGreatgrandchildren;
varGreatgrandchildren.vt=VT_I4;
varGreatgrandchildren.lVal=CHILDID_SELF;
VARIANT vGreatgrandchildren;
IGreatgrandchildren->get_accRole(varGreatgrandchildren, &vGreatgrandchildren);
if (vGreatgrandchildren.llVal != ROLE_SYSTEM_PANE){
continue;
}
long inGreatgrandchildren = 0;
IGreatgrandchildren->get_accChildCount(&inGreatgrandchildren);
VARIANT vGreatgrandchildrenWnd[MAX_PATH];
long outGreatgrandchildren = 0;
AccessibleChildren(IGreatgrandchildren, 0, inGreatgrandchildren, vGreatgrandchildrenWnd,
&outGreatgrandchildren);//第4级,2个孩子
for (int m = 0; m < outGreatgrandchildren; m++){
IDispatch *IdispClient = vGreatgrandchildrenWnd[m].pdispVal;
IAccessible *IClient;
IdispClient->QueryInterface(IID_IAccessible, (void **)&IClient);
VARIANT vClientRole;
vClientRole.vt = VT_I4;
vClientRole.lVal = CHILDID_SELF;
VARIANT varClientType;
IClient->get_accRole(vClientRole, &varClientType);
if (varClientType.lVal != ROLE_SYSTEM_PAGETABLIST){
continue;
}
long inClientCount = 0;
IClient->get_accChildCount(&inClientCount);
VARIANT varClientWnd[MAX_PATH];
long outClientCount = 0;
AccessibleChildren(IClient, 0, inClientCount, varClientWnd, &outClientCount);//第5级,4个孩子
for (int n = 0; n < outClientCount; n++){
IDispatch *IdispHistory = varClientWnd[n].pdispVal;
IAccessible *IHistory;
IdispHistory->QueryInterface(IID_IAccessible, (void **)&IHistory);
VARIANT vHistoryRole;
vHistoryRole.vt = VT_I4;
vHistoryRole.lVal = CHILDID_SELF;
VARIANT varHistoryType;
IHistory->get_accRole(vHistoryRole, &varHistoryType);
if (varHistoryType.lVal != ROLE_SYSTEM_PAGETAB){
continue;
}
long inHistoryCount = 0;
IHistory->get_accChildCount(&inHistoryCount);
VARIANT varHistoryWnd[MAX_PATH];
long outHistoryCount = 0;
AccessibleChildren(IHistory, 0, inHistoryCount, varHistoryWnd, &outHistoryCount);//第6级,2个孩子
for (int t = 0; t < outHistoryCount; t++){
IDispatch *IdispClt = varHistoryWnd[t].pdispVal;
IAccessible *IClt;
IdispClt->QueryInterface(IID_IAccessible, (void **)&IClt);
VARIANT vCltRole;
vCltRole.vt = VT_I4;
vCltRole.lVal = CHILDID_SELF;
VARIANT varCltType;
IClt->get_accRole(vCltRole, &varCltType);
if (varCltType.lVal != ROLE_SYSTEM_PANE){
continue;
}
long inCltCount = 0;
IClt->get_accChildCount(&inCltCount);
VARIANT varCltWnd[MAX_PATH];
long outCltCount = 0;
AccessibleChildren(IClt, 0, inCltCount, varCltWnd, &outCltCount);//第7级,1个孩子
for (int X = 0; X < outCltCount; X++){
IDispatch *IdispScrollView = varCltWnd[X].pdispVal;
IAccessible *IScrollView;
IdispScrollView->QueryInterface(IID_IAccessible, (void **)&IScrollView);
VARIANT vScrollViewRole;
vScrollViewRole.vt = VT_I4;
vScrollViewRole.lVal = CHILDID_SELF;
VARIANT varScrollViewType;
IScrollView->get_accRole(vScrollViewRole, &varScrollViewType);
if (varScrollViewType.lVal != ROLE_SYSTEM_CLIENT){
continue;
}
long inScrollViewCount = 0;
IScrollView->get_accChildCount(&inScrollViewCount);
VARIANT varScrollViewWnd[MAX_PATH];
long outScrollViewCount = 0;
AccessibleChildren(IScrollView, 0, inScrollViewCount, varScrollViewWnd, &outScrollViewCount);
for (int Y = 0; Y < outScrollViewCount; Y++){//8级,4个孩子
IDispatch *IdispGrouping = varScrollViewWnd[Y].pdispVal;
IAccessible *IGrouping;
IdispGrouping->QueryInterface(IID_IAccessible, (void **)&IGrouping);
VARIANT vGroupingRole;
vGroupingRole.vt = VT_I4;
vGroupingRole.lVal = CHILDID_SELF;
VARIANT varGroupingType;
IGrouping->get_accRole(vGroupingRole, &varGroupingType);
if (varGroupingType.lVal != ROLE_SYSTEM_PANE){
continue;
}
long inGroupingCount = 0;
IGrouping->get_accChildCount(&inGroupingCount);
VARIANT varGroupingWnd[MAX_PATH];
long outGroupingCount = 0;
AccessibleChildren(IGrouping, 0, inGroupingCount, varGroupingWnd, &outGroupingCount);
for (int w = 0; w < outGroupingCount; w++){
IDispatch *IdispSet = varGroupingWnd[w].pdispVal;
IAccessible *ISet;
IdispSet->QueryInterface(IID_IAccessible, (void **)&ISet);
VARIANT vSetRole;
vSetRole.vt = VT_I4;
vSetRole.lVal = CHILDID_SELF;
VARIANT varSetType;
ISet->get_accRole(vSetRole, &varSetType);
BSTR Str1;
ISet->get_accName(vSetRole, &Str1);
if (varSetType.lVal != ROLE_SYSTEM_GROUPING){
continue;
}
CString StrFavorites = Str1;
if (wcscmp(StrFavorites, L"FavoritesExpander") != 0){
continue;
}
long inSetCount = 0;
ISet->get_accChildCount(&inSetCount);
VARIANT varSetWnd[MAX_PATH];
long outSetCount = 0;
AccessibleChildren(ISet, 0, inSetCount, varSetWnd, &outSetCount);
for (int e = 0; e < outSetCount; e++){
IDispatch *IdispTabNames = varSetWnd[e].pdispVal;
IAccessible *ITabNames;
IdispTabNames->QueryInterface(IID_IAccessible, (void **)&ITabNames);
VARIANT vTabNamesRole;
vTabNamesRole.vt = VT_I4;
vTabNamesRole.lVal = CHILDID_SELF;
VARIANT varTabNamesType;
ITabNames->get_accRole(vTabNamesRole, &varTabNamesType);
if (varTabNamesType.lVal != ROLE_SYSTEM_OUTLINE){
continue;
}
long inTabNamesCount = 0;
ITabNames->get_accChildCount(&inTabNamesCount);
VARIANT varTabNamesWnd[MAX_PATH];
long outTabNamesCount = 0;
AccessibleChildren(ITabNames, 0, inTabNamesCount, varTabNamesWnd, &outTabNamesCount);
for (int u = 0; u < outTabNamesCount; u++){
IDispatch *IdispFavoritesNames = varTabNamesWnd[u].pdispVal;
IAccessible *IFavoritesNames;
IdispFavoritesNames->QueryInterface(IID_IAccessible, (void **)&IFavoritesNames);
VARIANT vFavoritesNames;
vFavoritesNames.vt = VT_I4;
vFavoritesNames.lVal = CHILDID_SELF;
BSTR bstrTemp;
IFavoritesNames->get_accName(vFavoritesNames, &bstrTemp);
m_list1.InsertItem(u, L"");
m_list1.SetItemText(u, 0, bstrTemp);//最后的结果显示在列表框
}
}
}
}
}
}
}
}
}
}
}
}
通过COM获取microsoft help viewer2.0 的收藏列表
最新推荐文章于 2021-07-14 11:11:27 发布