setfilepointer.cpp
来自「IO函数调用测试」· C++ 代码 · 共 203 行
CPP
203 行
// SetFilePointer.cpp : implementation file
//
#include "stdafx.h"
#include "afxtempl.h"
#include "help.h"
#include "DataArray.h"
#include "HexDisp.h"
#include "IOExplorer.h"
#include "NumericEdit.h"
#include "Status.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 "SetFilePointerEvent.h"
#include "HandlePage.h"
#include "SetFilePointer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSetFilePointer property page
IMPLEMENT_DYNCREATE(CSetFilePointer, CHandlePage)
CSetFilePointer::CSetFilePointer() : CHandlePage(CSetFilePointer::IDD)
{
initialized = FALSE;
//{{AFX_DATA_INIT(CSetFilePointer)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CSetFilePointer::~CSetFilePointer()
{
}
void CSetFilePointer::DoDataExchange(CDataExchange* pDX)
{
CHandlePage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSetFilePointer)
DDX_Control(pDX, IDC_FILE_END, c_FileEnd);
DDX_Control(pDX, IDC_FILE_CURRENT, c_FileCurrent);
DDX_Control(pDX, IDC_FILE_BEGIN, c_FileBegin);
DDX_Control(pDX, IDC_SPIN_POSITION, c_SpinPosition);
DDX_Control(pDX, IDC_SETFILEPOINTER, c_SetFilePointer);
DDX_Control(pDX, IDC_DISTANCETOMOVE, c_DistanceToMove);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSetFilePointer, CHandlePage)
//{{AFX_MSG_MAP(CSetFilePointer)
ON_EN_CHANGE(IDC_DISTANCETOMOVE, OnChangeDistancetomove)
ON_BN_CLICKED(IDC_FILE_BEGIN, OnFileBegin)
ON_BN_CLICKED(IDC_FILE_CURRENT, OnFileCurrent)
ON_BN_CLICKED(IDC_FILE_END, OnFileEnd)
ON_BN_CLICKED(IDC_SETFILEPOINTER, OnSetfilepointer)
ON_BN_CLICKED(IDC_HELPBUTTON, OnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetFilePointer message handlers
void CSetFilePointer::OnChangeDistancetomove()
{
updateControls();
}
void CSetFilePointer::OnFileBegin()
{
updateControls();
}
void CSetFilePointer::OnFileCurrent()
{
updateControls();
}
void CSetFilePointer::OnFileEnd()
{
updateControls();
}
void CSetFilePointer::OnSetfilepointer()
{
CCreateFileSheet * sheet = getSheet();
CHandle * ho = sheet->HandleList.getCurrentHandle();
SetFilePointerEvent * e = new SetFilePointerEvent(
ho == NULL ? _T("") : ho->Name,
ho == NULL ? 0 : ho->h,
c_DistanceToMove.GetWindowInt(),
0, // Not yet implemented
getMode());
e->execute();
if(e->result == 0xFFFFFFFF && e->lasterror != 0) // High-order not yet implemented
{ /* failed */
c_Status.SetWindowText(e->lasterror);
} /* failed */
else
{ /* ok */
c_Status.SetWindowText(e->display_result());
} /* ok */
sheet->log->add(e);
}
/****************************************************************************
* CSetFilePointer::getMode
* Result: DWORD
* FILE_BEGIN, FILE_CURRENT, or FILE_END
****************************************************************************/
DWORD CSetFilePointer::getMode()
{
if(c_FileBegin.GetCheck() == BST_CHECKED)
return FILE_BEGIN;
else
if(c_FileCurrent.GetCheck() == BST_CHECKED)
return FILE_CURRENT;
else
if(c_FileEnd.GetCheck() == BST_CHECKED)
return FILE_END;
ASSERT(FALSE); // should never get here
return FILE_BEGIN;
}
/****************************************************************************
* CSetFilePointer::updateControls
* Result: void
*
* Effect:
* Updates all the controls
****************************************************************************/
void CSetFilePointer::updateControls()
{
if(!initialized)
return;
CCreateFileSheet * sheet = getSheet();
CHandle * ho = sheet->HandleList.getCurrentHandle();
SetFilePointerEvent e(ho == NULL ? _T("") : ho->Name,
ho == NULL ? 0 : ho->h,
c_DistanceToMove.GetWindowInt(),
0, // Not yet implemented
getMode());
CString s = e.display();
c_Text.SetWindowText(s);
c_SetFilePointer.EnableWindow(ho != NULL);
// NYI: c_SpinPosition.SetRange(-filesize, filesize);
}
BOOL CSetFilePointer::OnSetActive()
{
return CHandlePage::OnSetActive();
}
BOOL CSetFilePointer::OnInitDialog()
{
CHandlePage::OnInitDialog();
c_SpinPosition.SetRange(-1000, 1000);
CheckRadioButton(IDC_FILE_BEGIN, IDC_FILE_END, IDC_FILE_BEGIN);
initialized = TRUE;
updateControls();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/****************************************************************************
* CSetFilePointer::OnHelp
* Result: void
*
* Effect:
* Calls help
****************************************************************************/
void CSetFilePointer::OnHelp()
{
AfxGetApp()->WinHelp(SetFilePointerHelp, HELP_CONTEXT);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?