handles.cpp
来自「IO函数调用测试」· C++ 代码 · 共 318 行
CPP
318 行
// Handles.cpp : implementation file
//
#include "stdafx.h"
#include "afxtempl.h"
//#include "prsht.h"
#include "IOExplorer.h"
#include "help.h"
#include "status.h"
#include "format.h"
#include "TraceEvent.h"
#include "handle.h"
#include "EventList.h"
#include "EventLog.h"
#include "handleManager.h"
#include "SetNameEvent.h"
#include "TraceManager.h"
#include "CreateFileSheet.h"
#include "CloseHandleEvent.h"
#include "HandleLog.h"
#include "Handles.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHandles property page
IMPLEMENT_DYNCREATE(CHandles, CPropertyPage)
CHandles::CHandles() : CPropertyPage(CHandles::IDD)
{
//{{AFX_DATA_INIT(CHandles)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CHandles::~CHandles()
{
}
void CHandles::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHandles)
DDX_Control(pDX, IDC_STATUS, c_Status);
DDX_Control(pDX, IDC_SETNAME, c_SetName);
DDX_Control(pDX, IDC_NAME, c_Name);
DDX_Control(pDX, IDC_HANDLES, c_Handles);
DDX_Control(pDX, IDC_CLOSEHANDLE, c_CloseHandle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHandles, CPropertyPage)
//{{AFX_MSG_MAP(CHandles)
ON_BN_CLICKED(IDC_CLOSEHANDLE, OnClosehandle)
ON_NOTIFY(NM_CLICK, IDC_HANDLES, OnClickHandles)
ON_NOTIFY(NM_DBLCLK, IDC_HANDLES, OnDblclkHandles)
ON_EN_CHANGE(IDC_NAME, OnChangeName)
ON_BN_CLICKED(IDC_SETNAME, OnSetname)
ON_BN_CLICKED(IDC_HELPBUTTON, OnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHandles message handlers
/****************************************************************************
* CHandles::OnClosehandle
* Result: void
*
* Effect:
* Closes the handle. Removes it from the handle list
****************************************************************************/
void CHandles::OnClosehandle()
{
CHandle * ho = c_Handles.GetSelHandle(c_Handles.GetCurSel());
if(ho == NULL)
return; // actually, should never happen
CloseHandleEvent * e = new CloseHandleEvent(ho->Name, ho->h);
if(e->execute())
{ /* worked */
CCreateFileSheet * sheet = getSheet();
sheet->HandleList.Remove(ho->h);
sheet->HandleList.setCurrentHandle(NULL);
CString s = e->display_result();
c_Status.SetWindowText(s);
} /* worked */
else
{ /* failed */
c_Status.SetWindowText(e->lasterror);
} /* failed */
getSheet()->log->add(e);
loadHandles();
updateControls();
}
/****************************************************************************
* CHandles::OnClickHandles
* Inputs:
* NMMHDR * pNMHDR: ignored
* LRESULT * pResult: result location
* Result: void
*
* Effect:
* Updates the controls on a selection change
****************************************************************************/
void CHandles::OnClickHandles(NMHDR* pNMHDR, LRESULT* pResult)
{
updateControls();
*pResult = 0;
}
/****************************************************************************
* CHandles::OnDblclkHandles
* Inputs:
* NMHDR * pNMHDR
* LRESULT * pResult
* Result: void
*
* Effect:
* Selects the handle as being the current handle
****************************************************************************/
void CHandles::OnDblclkHandles(NMHDR* pNMHDR, LRESULT* pResult)
{
CHandle * ho = c_Handles.GetSelHandle(c_Handles.GetCurSel());
ASSERT(ho != NULL);
if(ho != NULL)
{ /* select it */
getSheet()->HandleList.setCurrentHandle(ho);
updateControls();
} /* select it */
*pResult = 0;
}
/****************************************************************************
* CHandles::OnChangeName
* Result: void
*
* Effect:
* Updates the display
****************************************************************************/
void CHandles::OnChangeName()
{
updateControls();
}
/****************************************************************************
* CHandles::OnSetName
* Result: void
*
* Effect:
* Changes the text name of the specified handle
****************************************************************************/
void CHandles::OnSetname()
{
CString s;
CHandle * ho = c_Handles.GetSelHandle(c_Handles.GetCurSel());
HandleManager * HandleList = getHandleList();
c_Name.GetWindowText(s);
SetNameEvent * e = new SetNameEvent(ho->Name, s, HandleList);
if(!e->execute())
{ /* error */
CString s = formatError(e->lasterror);
AfxMessageBox(s, MB_OK | MB_ICONERROR);
return;
} /* error */
// Successful completion
getSheet()->log->add(e);
c_Name.SetWindowText(_T(""));
loadHandles();
updateControls();
}
/****************************************************************************
* CHandles::OnKillActive
* Result: BOOL
* Superclass OnKillActive result
* Effect:
* handled by superclass
****************************************************************************/
BOOL CHandles::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
return CPropertyPage::OnKillActive();
}
/****************************************************************************
* CHandles::OnSetActive
* Result: BOOL
* Superclass OnSetActive result
* Effect:
* Loads the display list from the handles list
****************************************************************************/
BOOL CHandles::OnSetActive()
{
loadHandles();
return CPropertyPage::OnSetActive();
}
/****************************************************************************
* CHandles::loadHandles
* Result: void
*
* Effect:
* Loads up the handle list
****************************************************************************/
void CHandles::loadHandles()
{
HandleManager * HandleList = getHandleList();
// Clear out the current list
c_Handles.DeleteAllItems();
POSITION p;
for(p = HandleList->GetHeadPosition(); p != NULL; )
{ /* loop across handles */
CHandle * e = HandleList->GetNext(p);
// display the handle:
// Handle | Name | Creator
// 800032 MyDevice CreateFile("\\.\\MyDevice", ...)
c_Handles.addHandle(e);
} /* loop across handles */
// Now sort it by the appropriate criterion stored in the manager object
c_Handles.sort();
}
/****************************************************************************
* CHandles::OnInitDialog
* Result: BOOL
* TRUE, always
* Effect:
* Initializes the dialog
****************************************************************************/
BOOL CHandles::OnInitDialog()
{
CPropertyPage::OnInitDialog();
c_Handles.initialize();
updateControls();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/****************************************************************************
* CHandles::updateControls
* Result: void
*
* Effect:
* Updates all controls
****************************************************************************/
void CHandles::updateControls()
{
CHandle * ho = c_Handles.GetSelHandle(c_Handles.GetCurSel());
if(ho == NULL || c_Handles.GetSelectedCount() != 1)
{ /* no file */
CString s;
s.LoadString(IDS_CLOSE_HANDLE_1);
c_CloseHandle.SetWindowText(s);
c_CloseHandle.EnableWindow(FALSE);
} /* no file */
else
{ /* has file */
CString s;
s.LoadString(IDS_CLOSE_HANDLE_3);
CString t;
t.Format(s, ho->Name);
c_CloseHandle.SetWindowText(t);
c_CloseHandle.EnableWindow(TRUE);
} /* has file */
c_SetName.EnableWindow(c_Name.GetWindowTextLength() > 0
&& c_Handles.GetSelectedCount() == 1);
}
void CHandles::OnHelp()
{
AfxGetApp()->WinHelp(HandlesHelp, HELP_CONTEXT);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?