handlelog.cpp
来自「IO函数调用测试」· C++ 代码 · 共 178 行
CPP
178 行
// HandleLog.cpp : implementation file
//
#include "stdafx.h"
#include "IOExplorer.h"
#include "TraceEvent.h"
#include "handle.h"
#include "HandleLog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHandleLog
CHandleLog::CHandleLog()
{
lastSort = 0;
}
CHandleLog::~CHandleLog()
{
}
BEGIN_MESSAGE_MAP(CHandleLog, CListCtrl)
//{{AFX_MSG_MAP(CHandleLog)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHandleLog message handlers
void CHandleLog::initialize()
{
LV_COLUMN col;
int total = 0;
CString hdr;
hdr.LoadString(IDS_SEQ);
col.cx = max(GetStringWidth(hdr), GetStringWidth(_T("9999")));
col.cx += ::GetSystemMetrics(SM_CXSMICON);
// We have to add the width of a small icon to the column width
col.cx += ::GetSystemMetrics(SM_CXSMICON);
total += col.cx;
col.fmt = LVCFMT_RIGHT;
col.pszText = (LPTSTR)(LPCTSTR)hdr;
col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
col.iSubItem = 0;
InsertColumn(0, &col);
hdr.LoadString(IDS_HANDLE);
col.cx = max(GetStringWidth(hdr),
GetStringWidth(_T("0x00000000")));
col.iSubItem = 0;
total += col.cx;
col.fmt = LVCFMT_RIGHT;
col.pszText = (LPTSTR)(LPCTSTR)hdr;
col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
col.iSubItem = 1;
InsertColumn(1, &col);
hdr.LoadString(IDS_NAME);
col.cx = GetStringWidth(_T("WWWWWW.WWW"));
// We have to add the width of a small icon to the column width
col.cx += ::GetSystemMetrics(SM_CXICON);
col.cx = max(col.cx, GetStringWidth(hdr));
total += col.cx;
col.fmt = LVCFMT_LEFT;
col.pszText = (LPTSTR)(LPCTSTR)hdr;
col.iSubItem = 2;
col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
InsertColumn(2, &col);
CRect r;
GetClientRect(&r);
hdr.LoadString(IDS_CREATOR);
col.cx = r.Width() - total - ::GetSystemMetrics(SM_CXVSCROLL);
// We have to reduce by the width of a small icon to the column width
// col.cx -= ::GetSystemMetrics(SM_CXICON);
col.fmt = LVCFMT_LEFT;
col.pszText = (LPTSTR)(LPCTSTR)hdr;
col.iSubItem = 3;
col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
InsertColumn(3, &col);
}
/****************************************************************************
* CHandleLog::addHandle
* Inputs:
* CHandle * ho: Handle object reference
* Result: int
* Position where it was inserted
* Effect:
* Inserts the handle in the table.
****************************************************************************/
int CHandleLog::addHandle(CHandle * ho)
{
int i = GetItemCount();
// Since the index is 0-based, the count i is the next available position
CString s;
s.Format(_T("%d"), ho->getSeq());
LV_ITEM item;
item.mask = LVIF_TEXT | LVIF_PARAM;
item.iItem = i;
item.iSubItem = 0;
item.state = 0;
item.stateMask = 0;
item.pszText = (LPTSTR)(LPCTSTR)s;
item.cchTextMax = 0;
item.iImage = 0;
item.lParam = (LPARAM)ho;
InsertItem(&item);
if((UINT)ho->h == 0)
s = _T("");
else
s.Format(_T("%08x"), (UINT)ho->h);
SetItemText(i, 1, s);
SetItemText(i, 2, ho->Name);
SetItemText(i, 3, ho->Creator);
return i;
}
/****************************************************************************
* CHandleLog::GetSelHandle
* Inputs:
* int i: Index of item to fetch handle
* Result: CHandle *
* Current item, or NULL
****************************************************************************/
CHandle * CHandleLog::GetSelHandle(int i)
{
if(i < 0)
return NULL;
return (CHandle *)GetItemData(i);
}
/****************************************************************************
* CHandleLog::GetCurSel
* Result: int
* Index of current selection, first selection of multiselect, or -1
* no selection found
****************************************************************************/
int CHandleLog::GetCurSel()
{
int n = GetSelectedCount();
if( n == 0)
return -1;
return GetNextSel(-1);
}
/****************************************************************************
* CHandleLog::GetNextSel
* Inputs:
* int i: Starting position
* Result: int
* Index of next selection, or -1 if not found
* Effect:
*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?