📄 statuslist.cpp
字号:
* int i: Position to change
* DWORD result: Result value from GetLastError
* CString s: Result name
* Result: void
*
* Effect:
* Changes the result. If the height changes invalidates the entire
* area. If the value changes, invalidates only that item
****************************************************************************/
void CStatusList::SetResult(int i, DWORD result, CString s)
{
ListItem * item = (ListItem *)GetItemDataPtr(i);
if(item == NULL)
return;
if(item->result == result)
return; // no change, no flicker
if( (item->result == 0) ^ (result == 0))
{ /* height change */
if(item->result == 0)
SetItemHeight(i, 3 * height);
else
SetItemHeight(i, height);
InvalidateRect(NULL);
} /* height change */
else
{ /* no height change */
// Redraw just this item
CRect r;
GetItemRect(i, &r);
InvalidateRect(&r);
} /* no height change */
item->result = result;
item->winerror = s;
LPTSTR msg;
if(::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL,
result,
0,
(LPTSTR)&msg,
0,
NULL) == 0)
{ /* failed */
item->text = _T("?");
} /* failed */
else
{ /* success */
if(msg[lstrlen(msg) - 2] = _T('\r'))
msg[lstrlen(msg) - 2] = _T('\0');
s = msg;
int n;
for(n = s.FindOneOf(_T("\r\n")); n >= 0; n = s.FindOneOf(_T("\r\n")))
{ /* delete internal */
if(s[n] == _T('\n'))
s = s.Left(n) + _T(" ") + s.Mid(n+1);
else
s = s.Left(n) + s.Mid(n+1);
} /* delete internal */
item->text = s;
LocalFree(msg);
} /* success */
}
/****************************************************************************
* GetValue
* Inputs:
* int i: Index of entry whose value is to be retrieved
* Result: DWORD
* The NTSTATUS code associated with the index
****************************************************************************/
DWORD CStatusList::GetValue(int i)
{
if(i == LB_ERR)
return 0xFFFFFFFF;
ListItem * item = (ListItem *)GetItemDataPtr(i);
if(item == NULL)
return 0xFFFFFFFF;
return item->value;
}
/****************************************************************************
* CStatusList::cvstr
* Inputs:
* DWORD value: Value to convert
* Result: CString
* A string in one of the two formats
* 0x00000000 if h/o bit set
* 9 if h/o bit not set
****************************************************************************/
CString CStatusList::cvstr(DWORD value)
{
if(value & 0x80000000)
{ /* hex */
CString s;
s.Format(_T("0x%08x"), value);
return s;
} /* hex */
else
{ /* decimal */
CString s;
s.Format(_T("%10d"), value);
return s;
} /* decimal */
}
/****************************************************************************
* CStatusList::Save
* Inputs:
* CStdioIoFile & file: File to write to
* Result: void
*
* Effect:
* Saves the contents
****************************************************************************/
void CStatusList::Save(CStdioFile & file)
{
int count = GetCount();
RegistryInt flags(IDS_FLAGS);
flags.load();
DWORD lastResult = (DWORD)-1;
CString s;
for(int i = 0; i < count; i++)
{ /* scan */
ListItem * item = (ListItem *)GetItemDataPtr(i);
// if(item->result == 0)
// continue;
if(SortType == ByValue)
{ /* By value */
if(flags.value & FLAGS_FORMATTED)
{ /* formatted */
// +------------+------------------+----+---------------+--------
// | 0x00000000 | STATUS_SOMETHING | 3 |ERROR_WHATEVER | This is
// +------------+------------------+----+---------------+--------
s.Format(_T("0x%08x\t%s\t%d\t%s\t%s\n"),
item->value,
item->name,
item->result,
item->winerror,
item->text);
} /* formatted */
else
{ /* plain */
s.Format(_T("0x%08x %s\n"
" %s %s\n"
" %s\n"),
item->value,
item->name,
cvstr(item->result),
item->winerror,
item->text);
} /* plain */
} /* By value */
else
if(SortType == ByName)
{ /* by name */
// +------------------+------------+----+---------------+--------
// | STATUS_SOMETHING | 0x00000000 | 3 |ERROR_WHATEVER | This is
// +------------------+------------+----+---------------+--------
if(flags.value & FLAGS_FORMATTED)
{ /* formatted */
s.Format(_T("%s\t0x%08x\t%s\t%s\t%s\n"),
item->name,
item->value,
cvstr(item->result),
item->winerror,
item->text);
} /* formatted */
else
{ /* plain */
s.Format(_T("%-32.32s %08x\n"
" %s %s\n"
" %s\n"),
item->name,
item->value,
cvstr(item->result),
item->winerror,
item->text);
} /* plain */
} /* by name */
else
if(SortType == ByWinError)
{ /* error-to-ntstatus */
// ERROR_WHATEVER>3>This is an error>STATUS_SOMETHING
// >>>STATUS_OTHER
// +----------------+-----+----------------+-------------------+
// | ERROR_WHATEVER | 3 | This is an | STATUS_SOMETHING |
// | | | error | |
// +----------------+-----+----------------+-------------------+
// | | | | STATUS_OTHER |
// +----------------+-----+----------------+-------------------+
if(flags.value & FLAGS_FORMATTED)
{ /* formatted */
if(item->result != lastResult)
{ /* full output */
s.Format(_T("%s\t%s\t%s\t%s\n"),
item->winerror,
cvstr(item->result),
item->text,
item->name);
} /* full output */
else
{ /* ditto output */
s.Format(_T("\t\t\t%s\n"), item->name);
} /* ditto output */
} /* formatted */
else
{ /* unformatted */
if(item->result != lastResult)
{ /* full output */
s.Format(_T("%-32.32s %s %s\n"
" %08x %s\n"),
item->winerror,
cvstr(item->result),
item->text,
item->value,
item->name);
} /* full output */
else
{ /* ditto output */
s.Format(_T(" %08x %s\n"),
item->value,
item->name);
} /* ditto output */
} /* unformatted */
lastResult = item->result;
} /* error-to-ntstatus */
else
if(SortType == ByResult)
{ /* error-to-ntstatus */
// ERROR_WHATEVER>3>This is an error>STATUS_SOMETHING
// >>>STATUS_OTHER
// +---+----------------+----------------+-------------------+
// | 3 | ERROR_WHATEVER | This is an | STATUS_SOMETHING |
// | | | error | |
// +---+----------------+----------------+-------------------+
// | | | | STATUS_OTHER |
// +---+----------------+----------------+-------------------+
if(flags.value & FLAGS_FORMATTED)
{ /* formatted */
if(item->result != lastResult)
{ /* full output */
s.Format(_T("%s\t%s\t%s\t%s\n"),
cvstr(item->result),
item->winerror,
item->text,
item->name);
} /* full output */
else
{ /* ditto output */
s.Format(_T("\t\t\t%s\n"), item->name);
} /* ditto output */
} /* formatted */
else
{ /* unformatted */
if(item->result != lastResult)
{ /* full output */
s.Format(_T("%s %-32.32s %s\n"
" %08x %s\n"),
cvstr(item->result),
item->winerror,
item->text,
item->value,
item->name);
} /* full output */
else
{ /* ditto output */
s.Format(_T(" %08x %s\n"),
item->value,
item->name);
} /* ditto output */
} /* unformatted */
lastResult = item->result;
} /* error-to-ntstatus */
else
{ /* text format */
s.Format(_T("0x%08x %s\n"
" %6d %s\n"
" %s\n"),
item->value,
item->name,
item->result,
item->winerror,
item->text);
} /* text format */
TRY {
if(item->result != 0 || flags.value & FLAGS_KEEP_ZERO)
file.Write(s.GetBuffer(0), s.GetLength());
}
CATCH(CFileException,e )
{
AfxMessageBox("Error");
}
END_CATCH
} /* scan */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -