📄 statuslist.cpp
字号:
// StatusList.cpp : implementation file
//
#include "stdafx.h"
#include <afxtempl.h>
#include "NTSTATUSExplorer.h"
#include "StatusList.h"
#include "RegVars.h"
#include "flags.h"
class ListItem {
public:
ListItem(CString & n, DWORD v) { name = n; value = v; result = 0;
selected = FALSE;
}
void SetWinerror(CString & s) { winerror = s; }
virtual ~ListItem() { }
CString name; // NTSTATUS name
DWORD value; // NTSTATUS value
DWORD result; // winerror.h value
CString winerror; // symbolic name of winerror.h value
CString text; // text explanation of winerror.h value
BOOL selected; // valid only when in temp list
};
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStatusList
CStatusList::CStatusList()
{
col1 = 0;
col2 = 0;
col3 = 0;
height = 0;
SortType = ByValue;
}
CStatusList::~CStatusList()
{
}
BEGIN_MESSAGE_MAP(CStatusList, CListBox)
//{{AFX_MSG_MAP(CStatusList)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatusList message handlers
int CStatusList::CompareItem(LPCOMPAREITEMSTRUCT cis)
{
ListItem * item1 = ((ListItem *)cis->itemData1);
ListItem * item2 = ((ListItem *)cis->itemData2);
switch(SortType)
{ /* sorttype */
case Unsorted:
return -1;
case ByName:
return lstrcmp(item1->name, item2->name);
case ByWinError:
return lstrcmp(item1->winerror, item2->winerror);
case ByResult:
if(item1->result != item2->result)
{ /* different */
if(item1->result < item2->result)
return -1;
else
if(item1->result > item2->result)
return 1;
else
return 0;
} /* different */
// FALLS THRU
case ByValue:
if(item1->value < item2->value)
return -1;
else
if(item1->value > item2->value)
return 1;
else
return 0;
} /* sorttype */
// return -1 = item 1 sorts before item 2
// return 0 = item 1 and item 2 sort the same
// return 1 = item 1 sorts after item 2
return 0;
}
void CStatusList::DeleteItem(LPDELETEITEMSTRUCT dis)
{
ListItem * item = (ListItem *)dis->itemData;
delete item;
CListBox::DeleteItem(dis);
}
void CStatusList::DrawItem(LPDRAWITEMSTRUCT dis)
{
CDC * dc = CDC::FromHandle(dis->hDC);
// Compute height. Note that this will get computed when
// the empty list is first drawn
if(height == 0)
height = GetItemHeight(0);
// traceDrawItem(dis);
if(dis->itemID == -1)
{ /* empty */
CBrush bg(::GetSysColor(COLOR_WINDOW));
dc->FillRect(&dis->rcItem, &bg);
if(dis->itemState & ODS_FOCUS)
{ /* selected */
dc->DrawFocusRect(&dis->rcItem);
} /* selected */
return; // nothing to draw
} /* empty */
if(dis->itemData == 0)
return; // data is not present
if(dis->itemState & ODA_FOCUS)
{ /* focus only */
dc->DrawFocusRect(&dis->rcItem);
return;
} /* focus only */
int saved = dc->SaveDC();
COLORREF txcolor;
COLORREF gycolor;
dc->SetBkMode(TRANSPARENT);
///////////////////////////////////////////////////////////////////////
// Background
///////////////////////////////////////////////////////////////////////
if((dis->itemState & ODS_SELECTED))
{ /* selected */
COLORREF fill;
if(::GetFocus() == m_hWnd)
fill = ::GetSysColor(COLOR_HIGHLIGHT);
else
fill = ::GetSysColor(COLOR_GRAYTEXT);
CBrush bg(fill);
dc->FillRect(&dis->rcItem, &bg);
txcolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
gycolor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
} /* selected */
else
{ /* not selected */
CBrush bg(::GetSysColor(COLOR_WINDOW));
dc->FillRect(&dis->rcItem, &bg);
txcolor = ::GetSysColor(COLOR_WINDOWTEXT);
gycolor = ::GetSysColor(COLOR_GRAYTEXT);
} /* not selected */
ListItem * item = (ListItem *)dis->itemData;
///////////////////////////////////////////////////////////////////////
// Value
///////////////////////////////////////////////////////////////////////
dc->SetTextColor(txcolor);
if(col1 == 0)
{ /* set it */
col1 = dc->GetTextExtent(CString(_T("0x00000000 "))).cx;
} /* set it */
CString s;
s.Format(_T("0x%08x "), item->value);
dc->TextOut(0, dis->rcItem.top, s);
///////////////////////////////////////////////////////////////////////
// Name
///////////////////////////////////////////////////////////////////////
dc->TextOut(col1, dis->rcItem.top, item->name);
///////////////////////////////////////////////////////////////////////
// Result
///////////////////////////////////////////////////////////////////////
//
// 0x00000000 STATUS_MUMBLE
// | 0x00000000 6 ERROR_WHATEVER
// | | There is an error
// | | | | |
// | col2 col3 | col5
// col1 col4
if(col2 == 0)
{ /* compute it */
col2 = dc->GetTextExtent(CString(_T("0x80000000 WWWW"))).cx;
col3 = col2 + dc->GetTextExtent(CString(_T("0x80000000 "))).cx;
col4 = col3 + dc->GetTextExtent(CString(_T("000000"))).cx;
col5 = col4 + dc->GetTextExtent(CString(_T(" "))).cx;
} /* compute it */
if(item->result != 0)
{ /* result */
s.Format(_T("0x%08x"), item->result);
dc->TextOut(col2, dis->rcItem.top + height, s);
s.Format(_T("%d"), item->result);
int offset = dc->GetTextExtent(s).cx;
dc->TextOut(col4 - offset, dis->rcItem.top + height, s);
dc->TextOut(col5, dis->rcItem.top + height, item->winerror);
dc->TextOut(col3, dis->rcItem.top + 2 * height, item->text);
} /* result */
///////////////////////////////////////////////////////////////////////
// finish off processing
///////////////////////////////////////////////////////////////////////
if(dis->itemState & ODS_FOCUS)
{ /* selected */
dc->DrawFocusRect(&dis->rcItem);
} /* selected */
dc->RestoreDC(saved);
}
void CStatusList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: Add your code to determine the size of specified item
}
/****************************************************************************
* CStatusList.AddString
* Inputs:
* CString & name: Name to add
* DWORD value: Value to add
* Result: int
* Position of insertion
* Effect:
* Adds an entry for the list item
****************************************************************************/
int CStatusList::AddString(CString & name, DWORD value)
{
ListItem * item = new ListItem(name, value);
return CListBox::AddString((LPCTSTR)item);
}
/****************************************************************************
* CStatusList::SetSort
* Inputs:
* int type: CStatusList::ByValue, CStatusList::ByName, CStatusList::Unsorted
* Result: void
*
* Effect:
* Sets the sort type
****************************************************************************/
void CStatusList::SetSort(int type)
{
if(SortType == type)
return; // no change
CList<ListItem *, ListItem *> temp;
int count = GetCount();
for(int i = 0; i < count; i++)
{ /* remove data */
ListItem * item = (ListItem *)GetItemDataPtr(i);
temp.AddHead(item);
item->selected = GetSel(i);
SetItemDataPtr(i, NULL);
} /* remove data */
SortType = type;
SetRedraw(FALSE);
ResetContent();
while(!temp.IsEmpty())
{ /* reinsert */
ListItem * item = temp.RemoveHead();
int n = CListBox::AddString((LPCTSTR)item);
if(item->selected)
SetSel(n);
if(item->result == 0)
SetItemHeight(n, height);
else
SetItemHeight(n, 3 * height);
} /* reinsert */
SetRedraw(TRUE);
InvalidateRect(NULL);
}
/****************************************************************************
* CStatusList::SetResult
* Inputs:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -