📄 lcsource.cpp
字号:
#include "stdafx.h"
#include "source.h"
#include "lcsource.h"
#include "regkey.h"
#include "source.h"
#include "utils.h"
#include "globals.h"
#include "busy.h"
#include "trapreg.h"
/////////////////////////////////////////////////////////////////////////////
// CLcSource
CLcSource::CLcSource()
{
}
CLcSource::~CLcSource()
{
}
//***************************************************************************
//
// CLcSource::AddMessage
//
// Add a message 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 pMessage.
//
//
// Parameters:
// CMessage* pMessage
//
// Returns:
// Nothing.
//
// Status:
//
//***************************************************************************
void CLcSource::AddMessage(CXMessage* pMessage)
{
CString sText;
pMessage->GetShortId(sText);
// Insert a new item into this list control.
LV_ITEM lvitem;
lvitem.mask = LVIF_TEXT | LVIF_PARAM;
lvitem.iSubItem = ICOL_LcSource_EVENTID;
lvitem.cchTextMax = MAX_STRING;
lvitem.lParam = (LPARAM)pMessage;
lvitem.pszText = (LPTSTR)(LPCTSTR)sText;
int nItem = InsertItem(&lvitem);
if (nItem >= 0)
{
CXEventSource* pEventSource = pMessage->m_pEventSource;
// Now set the string value for each sub-item.
pMessage->GetSeverity(sText);
SetItemText(nItem, ICOL_LcSource_SEVERITY, (LPTSTR)(LPCTSTR) sText);
pMessage->IsTrapping(sText);
SetItemText(nItem, ICOL_LcSource_TRAPPING, (LPTSTR)(LPCTSTR)sText);
SetItemText(nItem, ICOL_LcSource_DESCRIPTION, (LPTSTR)(LPCTSTR) pMessage->m_sText);
}
}
//*******************************************************************
// CXMessageArray::SetDescriptionWidth
//
// Set the width of the description field so that it is wide enough to
// hold the widest message.
//
// Parameters:
// CXMessageArray& aMessages
// The message array that will be used to fill the list control.
//
// Returns:
// Nothing.
//
//*******************************************************************
void CLcSource::SetDescriptionWidth(CXMessageArray& aMessages)
{
LONG cxWidestMessage = CX_DEFAULT_DESCRIPTION_WIDTH;
LONG nMessages = aMessages.GetSize();
for (LONG iMessage = 0; iMessage < nMessages; ++iMessage) {
CXMessage* pMessage = aMessages[iMessage];
int cx = GetStringWidth(pMessage->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_LcSource_DESCRIPTION, cxWidestMessage + CX_DESCRIPTION_SLOP);
}
//***************************************************************************
//
// CLcSource::LoadMessages
//
// Load the messages from the message library module and insert them into
// this list control.
//
// Parameters:
// CMessage* pMessage
//
// Returns:
// Nothing.
//
// Status:
//
//***************************************************************************
SCODE CLcSource::SetEventSource(CXEventSource* pEventSource)
{
CBusy busy;
DeleteAllItems();
if (pEventSource == NULL) {
return S_OK;
}
UpdateWindow();
//!!!CR: Should do something with the return code in case the
//!!!CR: messages weren't loaded.
SCODE sc = pEventSource->LoadMessages();
// Iterate through each of the messages and insert them into
// the list control.
CXMessageArray& aMessages = pEventSource->m_aMessages;
// Set the width of the description field so that it is wide enough to contain
// the widest message.
SetDescriptionWidth(aMessages);
LONG nMessages = aMessages.GetSize();
for (LONG iMessage=0; iMessage < nMessages; ++iMessage) {
if ((iMessage < 40 && (iMessage % 10 == 9)) ||
(iMessage % 100 == 99)) {
// Update the window often for the first few messages and less frequently
// thereafter for a good response time.
UpdateWindow();
}
AddMessage(aMessages[iMessage]);
}
SortItems(ICOL_LcSource_EVENTID);
SetRedraw(TRUE);
UpdateWindow();
EnsureVisible(0, FALSE);
if (GetSize())
SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
return S_OK;
}
BEGIN_MESSAGE_MAP(CLcSource, CListCtrl)
//{{AFX_MSG_MAP(CLcSource)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLcSource message handlers
//***************************************************************************
//
// CLcSource::CreateWindowEpilogue()
//
// This method is called after a window has been created for this list
// control. Final initialization is done here.
//
// Parameters:
// None.
//
// Returns:
// SCODE
// S_OK if the initialization was successful, otherwise E_FAIL.
//
// Status:
//
//***************************************************************************
SCODE CLcSource::CreateWindowEpilogue()
{
ListView_SetExtendedListViewStyle(m_hWnd, LVS_EX_FULLROWSELECT);
SetColumnHeadings();
return S_OK;
}
//***************************************************************************
//
// CLcSource::SetColumnHeadings
//
// Define's the columns for this list control. The column title, width, and
// order is defined here.
//
// Parameters:
// None.
//
// Returns:
// Nothing.
//
// Status:
//
//***************************************************************************
void CLcSource::SetColumnHeadings()
{
static UINT auiResColumnTitle[ICOL_LcSource_MAX] = {
IDS_LcSource_TITLE_EVENT_ID,
IDS_LcSource_TITLE_SEVERITY,
IDS_LcSource_TITLE_TRAPPING,
IDS_LcSource_TITLE_DESCRIPTION
};
static int aiColWidth[ICOL_LcSource_MAX] = {60, 75, 60, 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_LcSource_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();
}
}
//******************************************************************
// CLcSource::Find
//
// Find the specified event source in this list control.
//
// Parameters:
// CString& sText
// A string containing the text to search for.
//
// BOOL bWholeWord
// TRUE if this is a "whole word" search. False if it
// is OK to match a partial word.
//
// BOOL bMatchCase
// TRUE if a case-sensitive comparison should be used.
//
// Returns:
// BOOL
// TRUE if the string was found, FALSE otherwise. If the specified
// text is found, then the selection is set on the corresponding
// list control item, the item is scrolled into view and the focus
// is set on the item.
//
//******************************************************************
BOOL CLcSource::Find(CString sText, BOOL bWholeWord, BOOL bMatchCase)
{
// Don't do anything if the list is empty.
if (GetSize() == 0)
return FALSE;
if (!bMatchCase)
sText.MakeUpper();
// Get the selected item.
LONG iItem = GetNextItem(-1, LVNI_SELECTED);
// Nothing selected; start from the top of the list.
if (iItem == -1)
iItem = 0;
// Iterate through all of the items starting at one item past
// the currently selected item.
CXMessage* pMessage;
CString sDescription;
BOOL bFound = FALSE;
LONG nItems = GetSize();
LONG iItemStart = iItem;
for (long i=0; !bFound && i<nItems; ++i) {
// Bump the item index to the next one and wrap it if its past the
// last item.
iItem = (iItem + 1) % nItems;
// Get the message description for this item.
pMessage = GetAt(iItem);
sDescription = pMessage->m_sText;
if (!bMatchCase)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -