readfile.cpp

来自「IO函数调用测试」· C++ 代码 · 共 263 行

CPP
263
字号
// ReadFile.cpp : implementation file
//

#include "stdafx.h"
#include <afxtempl.h>

#include "help.h"
#include "DataArray.h" 
#include "HexDisp.h"
#include "Status.h"
#include "IOExplorer.h"
#include "NumericEdit.h"
#include "TraceEvent.h"
  #include "EventList.h"
    #include "EventLog.h"
#include "Handle.h"
  #include "HandleCombo.h"
  #include "handleManager.h"
  #include "TraceManager.h"
    #include "CreateFileSheet.h"
      #include "ReadFileEvent.h"
#include "HandlePage.h"
#include "ReadFile.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CReadFile property page

IMPLEMENT_DYNCREATE(CReadFile, CHandlePage)

CReadFile::CReadFile() : CHandlePage(CReadFile::IDD)
{
    initialized = FALSE;
	//{{AFX_DATA_INIT(CReadFile)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CReadFile::~CReadFile()
{
}

/****************************************************************************
*                          CReadFile::DoDataExchange
* Inputs:
*       CDataExchange * pDX:
* Result: void
*       
* Effect: 
*       Data exchange
****************************************************************************/

void CReadFile::DoDataExchange(CDataExchange* pDX)
{
	CHandlePage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReadFile)
	DDX_Control(pDX, IDC_BYTES, c_Bytes);
	DDX_Control(pDX, IDC_HEX, c_Hex);
	DDX_Control(pDX, IDC_SPIN_BYTESTOREAD, c_SpinBytesToRead);
	DDX_Control(pDX, IDC_READFILE, c_ReadFile);
	DDX_Control(pDX, IDC_BYTESTOREAD, c_BytesToRead);
	DDX_Control(pDX, IDC_BYTESREAD, c_BytesRead);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReadFile, CHandlePage)
	//{{AFX_MSG_MAP(CReadFile)
	ON_EN_CHANGE(IDC_BYTESTOREAD, OnChangeBytestoread)
	ON_BN_CLICKED(IDC_READFILE, OnReadfile)
	ON_BN_CLICKED(IDC_HEX, OnHex)
	ON_BN_CLICKED(IDC_HELPBUTTON, OnHelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReadFile message handlers

/****************************************************************************
*                       CReadFile::OnChangeBytestoread
* Result: void
*       
* Effect: 
*       Updates displays
****************************************************************************/

void CReadFile::OnChangeBytestoread() 
{
 if(!initialized)
     return;
 updateControls();
	
}

/****************************************************************************
*                         CReadFile::OnSelendokHandle
* Result: void
*       
* Effect: 
*       Updates the global "current handle"
* Notes:
*	It is probably better to put this in the superclass
****************************************************************************/

void CReadFile::OnSelendokHandle() 
{
 CCreateFileSheet * sheet = getSheet();
 sheet->HandleList.setCurrentHandle(c_Handle.GetCurHandle());
 
 updateControls();
}

/****************************************************************************
*                            CReadFile::OnReadfile
* Result: void
*       
* Effect: 
*       Actually executes the ReadFile as specified
****************************************************************************/

void CReadFile::OnReadfile() 
{
 CCreateFileSheet * sheet = getSheet();
 CHandle * ho = sheet->HandleList.getCurrentHandle();

 ReadFileEvent * e = new ReadFileEvent(ho == NULL ? _T("") : ho->Name, 
                                       ho == NULL ? NULL : ho->h, 
 				       c_BytesToRead.GetWindowInt());
 e->execute();
 if(e->result && e->NumberOfBytesRead == 0)
    { /* EOF */
     CString eof;
     eof.LoadString(IDS_EOF);
     c_Status.SetWindowText(eof);
    } /* EOF */
 else
    c_Status.SetWindowText(e->lasterror);

 sheet->log->add(e);

 setEvent(*e);
}

/****************************************************************************
*                              CReadFile::OnHex
* Result: void
*       
* Effect: 
*       Changes the display mode to or from hex bytes
****************************************************************************/

void CReadFile::OnHex() 
{
 if(c_Hex.GetCheck() == BST_CHECKED)
    c_Bytes.toHex();
 else
    c_Bytes.toAscii();
	
}

/****************************************************************************
*                             CReadFile::getEvent
* Inputs:
*       ReadFileEvent & e:
* Result: void
*       
* Effect: 
*       Copies controls to a readfile object
****************************************************************************/

void CReadFile::getEvent(ReadFileEvent & e)
    {
    }

/****************************************************************************
*                             CReadFile::setEvent
* Inputs:
*       ReadFileEvent & e
* Result: void
*       
* Effect: 
*       Transfers contents of event to controls
****************************************************************************/

void CReadFile::setEvent(ReadFileEvent & e)
    {
     c_BytesRead.SetWindowText(e.NumberOfBytesRead);
     if(e.buffer.GetSize() != 0)
        { /* show buffer */
	 BOOL hex = c_Bytes.SetWindowTextHexMaybe(e.buffer);
	 if(hex)
	    c_Hex.SetCheck(BST_CHECKED);
         updateControls();
	} /* show buffer */
    }

/****************************************************************************
*                          CReadFile::updateControls
* Result: void
*       
* Effect: 
*       Updates the controls
****************************************************************************/

void CReadFile::updateControls()
    {
     CString s;
     CCreateFileSheet * sheet = getSheet();
     CHandle * ho = sheet->HandleList.getCurrentHandle();

     ReadFileEvent e(ho == NULL ? _T("") : ho->Name, 
                     ho == NULL ? 0 : ho->h, 
                     c_BytesToRead.GetWindowInt());
     s = e.display();
     c_Text.SetWindowText(s);

     c_ReadFile.EnableWindow(ho != NULL & c_BytesToRead.GetWindowInt() > 0);
     c_Hex.EnableWindow(c_Bytes.canAscii());
    }

/****************************************************************************
*                           CReadFile::OnInitDialog
* Result: BOOL
*       TRUE, always
* Effect: 
*       Dialog initialization
****************************************************************************/

BOOL CReadFile::OnInitDialog() 
{
	CHandlePage::OnInitDialog();
	
	c_SpinBytesToRead.SetRange(0, 1000);
        initialized = TRUE;
        updateControls();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/****************************************************************************
*                           CReadFile::OnSetActive
* Result: BOOL
*       As per parent
* Effect: 
*       (Currently none; left as a placeholder from an earlier version)
****************************************************************************/

BOOL CReadFile::OnSetActive() 
{
     return CHandlePage::OnSetActive();
}

void CReadFile::OnHelp() 
{
 AfxGetApp()->WinHelp(ReadFileHelp, HELP_CONTEXT);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?