HRESULT CPageEvents::PopulateTreeAndList() { // Get the XML text of the logger's current status CComBSTR bstrEventList; RETURN_FAILED(m_spEventLogger->get_EventList(&bstrEventList)); // Load the XML text into the XMLDOM object VARIANT_BOOL bSucceeded; RETURN_FAILED(m_spXMLDoc->loadXML(bstrEventList, &bSucceeded)); if (!bSucceeded) return E_FAIL; // Get the root element IXMLDOMElementPtr spRoot; RETURN_FAILED(m_spXMLDoc->get_documentElement(&spRoot)); #ifdef _DEBUG { // Ensure that the root element tag is <AGCEvents> CComBSTR bstrRoot; ASSERT(SUCCEEDED(spRoot->get_tagName(&bstrRoot))); ASSERT(0 == wcscmp(bstrRoot, L"AGCEvents")); } #endif // _DEBUG // Recursively process the children of each group RETURN_FAILED(AddXMLNodeToTree(spRoot, TVI_ROOT)); // Caculate the column widths m_cxMaxType += 16 + 2; // Adjust for icon and padding int cxScroll = GetSystemMetrics(SM_CXVSCROLL); // Get the width of the list control's client area CRect rect; m_listEvents.GetClientRect(rect); // Compute the Name column to fit the maximum width int cxTotal = m_cxMaxType + m_cxMaxID + cxScroll; int cxName = rect.Width() - cxTotal; // Set the column widths LVCOLUMN lvcol = {LVCF_WIDTH}; lvcol.cx = m_cxMaxType; m_listEvents.SetColumn(0, &lvcol); lvcol.cx = m_cxMaxID; m_listEvents.SetColumn(1, &lvcol); lvcol.cx = cxName; m_listEvents.SetColumn(2, &lvcol); // Indicate success return S_OK; }