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

📄 lcevents.cpp

📁 windows的snmp api源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// lcevents.cpp : implementation file
//

#include "stdafx.h"
#include "eventrap.h"
#include "lcevents.h"
#include "settings.h"
#include "source.h"
#include "globals.h"
#include "utils.h"
#include "lcsource.h"
#include "busy.h"
#include "trapreg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif




/////////////////////////////////////////////////////////////////////////////
// CLcEvents

CLcEvents::CLcEvents()
{
    m_dwSortColumn = ICOL_LcEvents_LOG;
    m_cxWidestMessage = CX_DEFAULT_DESCRIPTION_WIDTH;
}

CLcEvents::~CLcEvents()
{
}


BEGIN_MESSAGE_MAP(CLcEvents, CListCtrl)
	//{{AFX_MSG_MAP(CLcEvents)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


SCODE CLcEvents::CreateWindowEpilogue()
{
	ListView_SetExtendedListViewStyle(m_hWnd, LVS_EX_FULLROWSELECT);
	SetColumnHeadings();
    return S_OK;
}



/////////////////////////////////////////////////////////////////////////////
// CLcEvents message handlers





//***************************************************************************
//  CLcEvents::SelectEvents
//
//  Select the specified events in the list control.
//
//  Parameters:
//		CXEventArray& aEvents
//          An array of event pointers.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::SelectEvents(CXEventArray& aEventsSel)
{
    int iItemFirstSelection = -1;
    LONG nItems = GetSize();
    for (LONG iItem = 0; iItem < nItems; ++iItem) {
        CXEvent* pEventTrapping = GetAt(iItem);

        // If the event associated with this item is in aEvents, then select the item.
        // Otherwise clear selection on the item.
        BOOL bDidFindEvent = FALSE;
        LONG nEventsSel = aEventsSel.GetSize();
        for (LONG iEventSel = 0; iEventSel < nEventsSel; ++iEventSel) {
            CXEvent* pEventSel;
            pEventSel = aEventsSel[iEventSel];
            if ((pEventSel->m_message.m_dwId == pEventTrapping->m_message.m_dwId) &&
                (pEventSel->m_pEventSource == pEventTrapping->m_pEventSource) &&
                (pEventSel->m_pEventSource->m_pEventLog == pEventTrapping->m_pEventSource->m_pEventLog)) {

                bDidFindEvent = TRUE;
                if (iItemFirstSelection == -1) {
                    iItemFirstSelection = iItem;
                }
                break;
            }
        }

        SetItemState(iItem, bDidFindEvent ? LVIS_SELECTED : 0, LVIS_SELECTED);
    }

    // Scroll the first selected item into view.
    if (iItemFirstSelection > 0) {
        EnsureVisible(iItemFirstSelection, FALSE);
    }
}






//***************************************************************************
//
//  CLcEvents::SetColumnHeadings
//
//  Define's the columns for this list control.  The column title, width, and
//  order is defined here.
//
//  Parameters:
//		None.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::SetColumnHeadings()
{
 	static UINT auiResColumnTitle[ICOL_LcEvents_MAX] = {
        IDS_LcEvents_TITLE_LOG,
        IDS_LcEvents_TITLE_SOURCE,
		IDS_LcEvents_TITLE_ID,
		IDS_LcEvents_TITLE_SEVERITY,
        IDS_LcEvents_TITLE_COUNT,
        IDS_LcEvents_TITLE_TIME,
		IDS_LcEvents_TITLE_DESCRIPTION
	};

	static int aiColWidth[ICOL_LcEvents_MAX] = {75, 60, 60, 60, 50, 50, CX_DEFAULT_DESCRIPTION_WIDTH};


    // Build the columns in the AllEventsList control.
    LV_COLUMN lvcol;
    lvcol.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

    for (int iCol=0; iCol<ICOL_LcEvents_MAX; ++iCol)
    {
		CString sColTitle;
		sColTitle.LoadString(auiResColumnTitle[iCol]);

        lvcol.pszText = sColTitle.GetBuffer(sColTitle.GetLength());
        lvcol.iSubItem = iCol;
        lvcol.cx = aiColWidth[iCol];
        InsertColumn(iCol, &lvcol);
		sColTitle.ReleaseBuffer();
    }
}



//********************************************************************
// CLcEvents::AddEvents
//
// Add all the events for all the event sources contained in the
// event-log array.   The source is notified that each of these
// events is being trapped.
//
// Parameters:
//      CSource& source
//          The message source container.
//
//      CEventLogArray& aEventLogs
//          An array of event-logs.
//
// Returns:
//      Nothing.
//
//*******************************************************************
void CLcEvents::AddEvents(CSource& source, CXEventLogArray& aEventLogs)
{
    // Iterate though all the event logs.
    LONG nLogs = aEventLogs.GetSize();
    for (LONG iLog=0; iLog < nLogs; ++iLog) {
        CXEventLog* pEventLog = aEventLogs[iLog];

        // Iterate through all the event sources within this event log
        LONG nSources = pEventLog->m_aEventSources.GetSize();
        for (LONG iSource = 0; iSource < nSources; ++iSource) {

            // Add all the events for the source to this list control.
            CXEventSource* pEventSource = pEventLog->m_aEventSources[iSource];
            AddEvents(source, pEventSource->m_aEvents);
        }
    }

	if (GetSize() > 0 && !HasSelection())
	{
		SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
	}
}





//***************************************************************************
//
//  CLcEvents::AddEvents
//
//  Add an array of events to this list control.  This involves the following
//      a. Add each event to the list control
//      b. Notify the CLcSource that the event has been modified so that it
//         can update the trapping flag.
//      c. Sort the events by the most recently selected column.
//      d. Make sure that the first item in CEventArray passed in is visible.
//
//  Parameters:
//      CSource& source
//          A reference to the CSource object.  This object must be notified
//          when the trapping status of an event changes.
//
//		CEventArray& aEvents
//          An array containing pointers to the events to add.  This list control
//          then becomes the owner of these events.
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
void CLcEvents::AddEvents(CSource& source, CXEventArray& aEvents)
{
    CBusy busy;

    // Now add them into this list control.  This is where they actually
    LONG nEvents = aEvents.GetSize();
    LONG iEvent;

    // Unselect all the previous items first
    iEvent = -1;
    do
    {
        iEvent = GetNextItem(iEvent, LVNI_SELECTED);
        if (iEvent == -1)
            break;
        SetItemState(iEvent, ~LVIS_SELECTED, LVIS_SELECTED);
    } while (TRUE);

    for (iEvent = 0; iEvent < nEvents; ++iEvent) {
        if ((iEvent < 40 && (iEvent % 10 == 9)) ||
            (iEvent % 100 == 99)) {
            UpdateWindow();
        }

        CXEvent* pEvent = aEvents[iEvent];
        AddEvent(pEvent);
        source.NotifyTrappingChange(pEvent->m_pEventSource, pEvent->m_message.m_dwId, TRUE);
    }

    UpdateDescriptionWidth();

    // Sort the items by the most recently selected column, and then
    // make sure the first item is visible.
    SortItems(m_dwSortColumn);
    if (nEvents > 0) {
        iEvent = FindEvent(aEvents[0]);
        EnsureVisible(iEvent, TRUE);
    }
}


//***************************************************************************
//
//  CLcEvents::AddEvent
//
//  Add an event to the list control. This sets the text for each column in
//  the list view and sets the lParam field of the list-view item to pEvent
//
//
//  Parameters:
//		CEvent* pEvent
//
//  Returns:
//		Nothing.
//
//  Status:
//
//***************************************************************************
LONG CLcEvents::AddEvent(CXEvent* pEvent)
{
    // Insert a new item into this list control.
    LV_ITEM lvitem;
    lvitem.mask = LVIF_TEXT | LVIF_PARAM;
    lvitem.iSubItem = ICOL_LcEvents_LOG;
    lvitem.lParam = (LPARAM)pEvent;
    lvitem.cchTextMax = pEvent->m_message.m_sText.GetLength() + 1;
    lvitem.pszText = (LPTSTR)(void*)(LPCTSTR) (pEvent->m_message.m_sText);
    LONG nItem = CListCtrl::InsertItem(&lvitem);

    SetItem(nItem, pEvent);
    SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
    return nItem;
}



//********************************************************************
// CLcEvents::SetItem
//
// Refresh an item from an event.
//
// Parameters:
//      LONG nItem
//
//      CEvent* pEvent
//          Pointer to the event to copy the data from.
//
// Returns:
//      Nothing.
//
//*******************************************************************
void CLcEvents::SetItem(LONG nItem, CXEvent* pEvent)
{


    // Check the item index against the array bounds.
    if (nItem < 0 || nItem >= GetItemCount()) {
        ASSERT(FALSE);
        return;
    }

    ASSERT(GetItemData(nItem) == (DWORD) (void*) pEvent);

    // Get the pointer for brevity.
    CXEventSource* pEventSource = pEvent->m_pEventSource;
	CString sText;

    SetItemData(nItem, (DWORD_PTR) (void*) pEvent);

    SetItemText(nItem, ICOL_LcEvents_LOG, (LPTSTR) (LPCTSTR) pEventSource->m_pEventLog->m_sName);

	SetItemText(nItem, ICOL_LcEvents_SOURCE, (LPTSTR)(LPCTSTR) pEventSource->m_sName);

    pEvent->m_message.GetShortId(sText);
    SetItemText(nItem, ICOL_LcEvents_ID, (LPTSTR)(LPCTSTR)sText);

    pEvent->m_message.GetSeverity(sText);
    SetItemText(nItem, ICOL_LcEvents_SEVERITY, (LPTSTR)(LPCTSTR)sText);

    pEvent->GetCount(sText);
    SetItemText(nItem, ICOL_LcEvents_COUNT, (LPTSTR)(LPCTSTR)sText);

    pEvent->GetTimeInterval(sText);
    SetItemText(nItem, ICOL_LcEvents_TIME, (LPTSTR)(LPCTSTR)sText);

    SetItemText(nItem, ICOL_LcEvents_DESCRIPTION, (LPTSTR)(LPCTSTR)pEvent->m_message.m_sText);

}



//***************************************************************************
//
//  CLcEvents::DeleteSelectedEvents.
//

⌨️ 快捷键说明

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