VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName) { LPENUM_SERVICE_STATUSW lpServiceStatus; LPTSTR lpNoDepends; DWORD count, i; BOOL bHasChildren; /* Get a list of service dependents */ lpServiceStatus = TV2_GetDependants(lpServiceName, &count); if (lpServiceStatus) { for (i = 0; i < count; i++) { /* Does this item need a +/- box? */ bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName); /* Add it */ AddItemToTreeView(pDlgInfo->hDependsTreeView2, hParent, lpServiceStatus[i].lpDisplayName, lpServiceStatus[i].lpServiceName, lpServiceStatus[i].ServiceStatus.dwServiceType, bHasChildren); } HeapFree(GetProcessHeap(), 0, lpServiceStatus); } else { /* If there is no parent, set the tree to 'no dependencies' */ if (!hParent) { /* Load the 'No dependencies' string */ AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); AddItemToTreeView(pDlgInfo->hDependsTreeView2, NULL, lpNoDepends, NULL, 0, FALSE); HeapFree(ProcessHeap, 0, lpNoDepends); /* Disable the window */ EnableWindow(pDlgInfo->hDependsTreeView2, FALSE); } } }
// INamespaceWalkCB IFACEMETHODIMP FoundItem(IShellFolder *psf, PCUITEMID_CHILD pidl) { IShellItem *psi; HRESULT hr = SHCreateItemWithParent(NULL, psf, pidl, IID_PPV_ARGS(&psi)); if (SUCCEEDED(hr)) { hr = AddItemToTreeView(_hwndTreeView, psi, _rghTreeParentItemArray[_iCurTreeDepth]) ? S_OK : E_FAIL; psi->Release(); } return hr; }
IFACEMETHODIMP EnterFolder(IShellFolder *psf, PCUITEMID_CHILD pidl) { HRESULT hr = (_iCurTreeDepth < ARRAYSIZE(_rghTreeParentItemArray) - 1) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { IShellItem *psi; hr = SHCreateItemWithParent(NULL, psf, pidl, IID_PPV_ARGS(&psi)); if (SUCCEEDED(hr)) { _rghTreeParentItemArray[_iCurTreeDepth + 1] = AddItemToTreeView(_hwndTreeView, psi, _rghTreeParentItemArray[_iCurTreeDepth]); hr = _rghTreeParentItemArray[_iCurTreeDepth + 1] ? S_OK : E_FAIL; _iCurTreeDepth++; psi->Release(); } } return hr; }
VOID TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPTSTR lpServiceName) { SC_HANDLE hSCManager; SC_HANDLE hService; LPQUERY_SERVICE_CONFIG lpServiceConfig; LPTSTR lpDependants; LPTSTR lpStr; LPTSTR lpNoDepends; BOOL bHasChildren; hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCManager) { hService = OpenService(hSCManager, lpServiceName, SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG); if (hService) { /* Get a list of service dependents */ lpDependants = TV1_GetDependants(pDlgInfo, hService); if (lpDependants) { lpStr = lpDependants; /* Make sure this isn't the end of the list */ while (*lpStr) { /* Get the info for this service */ lpServiceConfig = GetServiceConfig(lpStr); if (lpServiceConfig) { /* Does this item need a +/- box? */ if (lpServiceConfig->lpDependencies && *lpServiceConfig->lpDependencies != '\0') { bHasChildren = TRUE; } else { bHasChildren = FALSE; } /* Add it */ AddItemToTreeView(pDlgInfo->hDependsTreeView1, hParent, lpServiceConfig->lpDisplayName, lpStr, lpServiceConfig->dwServiceType, bHasChildren); HeapFree(GetProcessHeap(), 0, lpServiceConfig); } /* Move to the end of the string */ while (*lpStr++) ; } HeapFree(GetProcessHeap(), 0, lpDependants); } else { /* If there is no parent, set the tree to 'no dependencies' */ if (!hParent) { /* Load the 'No dependencies' string */ AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS); AddItemToTreeView(pDlgInfo->hDependsTreeView1, NULL, lpNoDepends, NULL, 0, FALSE); LocalFree(lpNoDepends); /* Disable the window */ EnableWindow(pDlgInfo->hDependsTreeView1, FALSE); } } CloseServiceHandle(hService); } CloseServiceHandle(hSCManager); } }