⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcevents.cpp

📁 windows的snmp api源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//  Delete all of the currently selected events and the corresponding items.
//
//  Parameters:
//      None.
//
//  Returns:
//      Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::DeleteSelectedEvents(CSource& source)
{

    // Delete all the selected items from the list control.
    // Build an array of event pointers corresponding to the events that are selected
    // in the list control.  Also notify the event source view that the event is no
    // longer being trapped.
   	while (TRUE) {
		int iItem = GetNextItem(-1, LVNI_SELECTED);
		if (iItem == -1) {
			break;
		}
        CXEvent* pEvent = GetAt(iItem);
        DeleteItem(iItem);
        source.NotifyTrappingChange(pEvent->m_pEventSource, pEvent->m_message.m_dwId, FALSE);
        delete pEvent;
	}
    UpdateDescriptionWidth();
}



//***************************************************************************
//
//  CLcEvents::GetAt
//
//  This method returns the event pointer located at the given item index.
//  This allows CLcEvents to be used much as an array.
//
//  Parameters:
//		LONG iItem
//			The item index.
//
//  Returns:
//		A pointer to the CEvent stored at the specified index.
//
//  Status:
//
//***************************************************************************
CXEvent* CLcEvents::GetAt(LONG iItem)
{

	// Setup the LV_ITEM structure to retrieve the lparam field.
	// This field contains the CMessage pointer.
    LV_ITEM lvitem;
    lvitem.mask = LVIF_PARAM;
    lvitem.iSubItem = ICOL_LcEvents_LOG;	
    lvitem.iItem = iItem;
    GetItem(&lvitem);

	CXEvent* pEvent = (CXEvent*) (void*) lvitem.lParam;
	return pEvent;
}










//***************************************************************************
//
//  CLcEvents::GetSelectedEvents
//
//  Get the events corresponding to the selected items in this list control.
//  This list control continues to own the event pointers.
//
//  Parameters:
//		CEventArray& aEvents
//			A reference to the event array where the event pointers are returned.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::GetSelectedEvents(CXEventArray& aEvents)
{

	// Clear the message array
	aEvents.RemoveAll();

	// Setup the LV_ITEM structure to retrieve the lparam field.
	// This field contains the CMessage pointer.
    LV_ITEM lvitem;
    lvitem.mask = LVIF_PARAM;
    lvitem.iSubItem = ICOL_LcEvents_LOG;

	// Loop to find all the selected items.	
	int nItem = -1;
	while (TRUE) {
		nItem = GetNextItem(nItem, LVNI_SELECTED);
		if (nItem == -1) {
			break;
		}

		// Get the CMessage pointer for this item and add it to the
		// array.
        lvitem.iItem = nItem;
        GetItem(&lvitem);
		CXEvent* pEvent = (CXEvent*) (void*) lvitem.lParam;
		aEvents.Add(pEvent);
	}
}



//***************************************************************************
//
//  CLcEvents::FindEvent
//
//  Find the specified event and return its item number.
//
//  Parameters:
//		CEvent* pEvent
//			A pointer to the event to search for.
//
//  Returns:
//		The item index if the item was found, otherwise -1.
//
//  Status:
//
//***************************************************************************
LONG CLcEvents::FindEvent(CXEvent* pEvent)
{

    LONG nEvents = GetItemCount();
    for (LONG iEvent = 0; iEvent < nEvents; ++iEvent) {
        CXEvent* pEventTemp = GetAt(iEvent);
        if (pEventTemp == pEvent) {
            return iEvent;
        }
    }
    return -1;
}



//***************************************************************************
//
//  CLcEvents::RefreshEvents
//
//  This method is called when the properties of some number of events
//  have changed and the corresponding items in the list control need
//  to be updated.
//
//  Parameters:
//		CEventArray& aEvents
//			The events that need to be refreshed.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::RefreshEvents(CXEventArray& aEvents)
{
    // Iterate through each of the events and refresh them.
    LONG nEvents = aEvents.GetSize();
    for (LONG iEvent = 0; iEvent < nEvents; ++iEvent) {
        CXEvent* pEvent = aEvents[iEvent];
        LONG nEvent = FindEvent(pEvent);
        SetItem(nEvent, pEvent);
    }
}





int CALLBACK CompareEventsProc(LPARAM lParam1, LPARAM lParam2, LPARAM
   lParamSort)
{
    CXEvent* pEvent1 = (CXEvent *)lParam1;
    CXEventSource* pEventSource1 = pEvent1->m_pEventSource;

    CXEvent* pEvent2 = (CXEvent *)lParam2;
    CXEventSource* pEventSource2 = pEvent2->m_pEventSource;


    ASSERT((pEvent1 != NULL) && (pEvent2 != NULL));
    int nResult = 0;
    CString sText1, sText2;

    switch( lParamSort)
    {
    case ICOL_LcEvents_LOG:
        // Sort by log, then by source, then by ID
        nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
            if (nResult == 0) {
                 nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
            }
        }
        break;
    case ICOL_LcEvents_SOURCE:
        // Sort by source, then by Log, then by ID
        nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                 nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
            }
        }
        break;
    case ICOL_LcEvents_ID:
        // Sort by ID, then by log, then by source.
        nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
            }
        }
        break;
    case ICOL_LcEvents_SEVERITY:
        // Sort by severity, then by log, then by source, then by ID
        pEvent1->m_message.GetSeverity(sText1);
        pEvent2->m_message.GetSeverity(sText2);
        nResult = lstrcmp(sText1, sText2);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
                if (nResult == 0) {
                     nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
                }
            }
        }
        break;
    case ICOL_LcEvents_COUNT:
        // Sort by count, then by log, then by source, then by ID
        pEvent1->GetCount(sText1);
        pEvent2->GetCount(sText2);
        nResult = lstrcmp(sText1, sText2);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
                if (nResult == 0) {
                     nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
                }
            }
        }
        break;
    case ICOL_LcEvents_TIME:
        // Sort by time, then by log, then by source, then by ID
        pEvent1->GetTimeInterval(sText1);
        pEvent2->GetTimeInterval(sText2);
        nResult = lstrcmp(sText1, sText2);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
                if (nResult == 0) {
                     nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
                }
            }
        }
        break;
    case ICOL_LcEvents_DESCRIPTION:
        // Sort by description, then by log, then by source, then by ID
        nResult = lstrcmp(pEvent1->m_message.m_sText, pEvent2->m_message.m_sText);
        if (nResult == 0) {
            nResult = lstrcmp(pEventSource1->m_pEventLog->m_sName, pEventSource2->m_pEventLog->m_sName);
            if (nResult == 0) {
                nResult = lstrcmp(pEventSource1->m_sName, pEventSource2->m_sName);
                if (nResult == 0) {
                     nResult = ((LONG) pEvent1->m_message.GetShortId()) - ((LONG) pEvent2->m_message.GetShortId());
                }
            }
        }
        break;
    default:
        ASSERT(FALSE);
        break;
    }


    if (!g_abLcEventsSortAscending[lParamSort]) {
        if (nResult > 0) {
            nResult = -1;
        }
        else if (nResult < 0) {
            nResult = 1;
        }
    }

    return nResult;
}


//***************************************************************************
//
//  CLcEvents::SortItems
//
//  Sort the items in this list control given the column index.  This method
//  hides all details about the sort implementation from this class's clients.
//
//  Parameters:
//		DWORD dwColumn
//			The column to use as the sort key.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::SortItems(DWORD dwColumn)
{
    CListCtrl::SortItems(CompareEventsProc, dwColumn);
    m_dwSortColumn = dwColumn;
}





//****************************************************************************
// CLcEvents::UpdateDescriptionWidth()
//
// Measure the message description string associated with each item and set the
// width of the description column to match the widest message length plus a
// little extra room for slop and appearances.
//
// Parameters:
//      None.
//
// Returns:
//      Nothing.
//
//*****************************************************************************
void CLcEvents::UpdateDescriptionWidth()
{
    LONG cxWidestMessage = CX_DEFAULT_DESCRIPTION_WIDTH;
    LONG nEvents = GetItemCount();
    for (LONG iEvent = 0; iEvent < nEvents; ++iEvent) {
        CXEvent* pEvent = GetAt(iEvent);
        int cx = GetStringWidth(pEvent->m_message.m_sText);
        if (cx > cxWidestMessage) {
            cxWidestMessage = cx;
        }
    }


    // Set the column width to the width of the widest string plus a little extra
    // space for slop and to make it obvious to the user that the complete string
    // is displayed.
    SetColumnWidth(ICOL_LcEvents_DESCRIPTION, cxWidestMessage + CX_DESCRIPTION_SLOP);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -