How to query Windows Control Panel Programmatically?

允我心安 提交于 2019-12-24 14:55:25

问题


I need to search the entire Windows Control Panel for a string (just like windows search from start menu or control panel explorer) in C++ MFC, anyone could help me?

I've already tried to search within the control panel virtual folder but doesn't work...

EDIT: It Works NOW! but only if compliled to the proper plataform (x86 or x64) (x86 dosen't work on x64 SO)

void CSearchView::BuildControlPanelCache()
{
    CComPtr<IShellFolder> pDesktop;
    SHGetDesktopFolder(&pDesktop);
    PIDLIST_ABSOLUTE path;
    SHGetKnownFolderIDList(FOLDERID_ControlPanelFolder,0,NULL,&path);
    CComPtr<IShellFolder> pFolder;
    pDesktop->BindToObject(path,NULL,IID_IShellFolder,(void**)&pFolder);

    ILFree(path);

    CComPtr<IEnumIDList> pEnum;
    if (pFolder->EnumObjects(NULL,SHCONTF_NONFOLDERS|SHCONTF_FOLDERS,&pEnum)!=S_OK) pEnum=NULL;
    if (!pEnum) return;

    PITEMID_CHILD pidl;
    while (pEnum->Next(1,&pidl,NULL)==S_OK)
    {
      STRRET strDispName;

        if( pFolder->GetDisplayNameOf(pidl, SHGDN_NORMAL, &strDispName) == S_OK )
        { 
              CComPtr<IQueryInfo> pLink;
              if (SUCCEEDED(pFolder->GetUIObjectOf(NULL,1,(PCITEMID_CHILD*) &pidl,IID_IQueryInfo,NULL,(void**)&pLink)))
              {
                    TCHAR *pwszTip; 
                    pLink->GetInfoTip( 0, &pwszTip ); 
                    if ( pwszTip ) 
                          { 
                                SHFree( pwszTip ); 
                          } 
                    //pLink->Release();           
              }
        }

        ILFree(pidl);
    }
}

It seems to do the trick! Ty Guys!


回答1:


Try searching %SYSTEM%\*.cpl. On some systems, %CSIDL_CONTROLS%\*.cpl.




回答2:


You can enumerate all the control panel items and search for the one which you are looking for try this and this



来源:https://stackoverflow.com/questions/10233812/how-to-query-windows-control-panel-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!