Creating folders in the browser programatically |
Top Previous Next |
Sometimes it is useful to have browser pane folders to hide detail. Here is how to create a folder programatically. You will need the name of the folder and an object collection of the occurrences to put inside the folder:
// Create a new folder so grouping together the object occurrences in pObjCollection bool CreateNewPaneFolder (const CString& kcsFolderName, CComPtr<ObjectCollection>& pObjCollection) { CComPtr<Document> pActiveDoc; HRESULT hRes = theApp.GetInvAppPtr()->get_ActiveDocument(&pActiveDoc); if (FAILED(hRes)) { TRACE L"CNFP get_ActiveDocument failed"); return false; }
CComPtr<BrowserPanes> pPanes = nullptr; hRes = pActiveDoc->get_BrowserPanes (&pPanes) ; if (FAILED(hRes)) { TRACE (L"CNFP get_BrowserPanes failed"); return false; }
BrowserPaneObjectPtr pCctPane; hRes = pPanes->get_ActivePane (&pCctPane) ; if (FAILED(hRes)) { TRACE (L"CNPF get_ActivePane failed"); return false; }
// Do this so you can create object collection... CComPtr<TransientObjects> pTransObjs = GetTransientObjectsPtr() ;
CComPtr<ObjectCollection> pNodeCollection = nullptr ; hRes = pTransObjs->CreateObjectCollection (gkvarEmpty,&pNodeCollection) ; if (FAILED(hRes)) { TRACE (L"CNPF CreateObjectCollection for workaxes failed.") ; return false ; }
for (long i = 1; i <= pObjCollection->Count; i++) { CComPtr<BrowserNode> pThisBrowserNode; pCctPane->GetBrowserNodeFromObject(pObjCollection->GetItem(i),&pThisBrowserNode); pNodeCollection->Add(pThisBrowserNode); }
CComVariant cvNodeColl(pNodeCollection); CComBSTR bstrFolderName(kcsFolderName);
hRes = pCctPane->AddBrowserFolder(bstrFolderName, cvNodeColl); if (FAILED(hRes)) { TRACE (L"CNPF AddBrowserFolder failed"); return false ; }
return true; }
Note that AddBrowserFolder will create a new folder, even if a folder of the same name already exists.
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)