www.pudn.com > DiskIOForC_class.rar > DiskIOView.cpp


// DiskIOView.cpp : implementation of the CDiskIOView class 
// 
 
#include "stdafx.h" 
#include "DiskIO.h" 
 
#include "DiskIODoc.h" 
#include "DiskIOView.h" 
 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CDiskIOView 
 
IMPLEMENT_DYNCREATE(CDiskIOView, CFormView) 
 
BEGIN_MESSAGE_MAP(CDiskIOView, CFormView) 
	//{{AFX_MSG_MAP(CDiskIOView) 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3) 
	ON_WM_PAINT() 
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDiskIOView construction/destruction 
 
CDiskIOView::CDiskIOView() 
	: CFormView(CDiskIOView::IDD) 
{ 
	//{{AFX_DATA_INIT(CDiskIOView) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// TODO: add construction code here 
	text_x=200;text_y=55;win_x=490;win_y=345;absX=11;ascX=49; 
	memset(buffer,0,512); 
} 
 
CDiskIOView::~CDiskIOView() 
{ 
} 
 
void CDiskIOView::DoDataExchange(CDataExchange* pDX) 
{ 
	CFormView::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDiskIOView) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BOOL CDiskIOView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CFormView::PreCreateWindow(cs); 
} 
 
void CDiskIOView::OnInitialUpdate() 
{ 
	CFormView::OnInitialUpdate(); 
	GetParentFrame()->RecalcLayout(); 
	ResizeParentToFit(); 
	GetDlgItem(IDC_EDIT5)->SetWindowText("1"); 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDiskIOView diagnostics 
 
#ifdef _DEBUG 
void CDiskIOView::AssertValid() const 
{ 
	CFormView::AssertValid(); 
} 
 
void CDiskIOView::Dump(CDumpContext& dc) const 
{ 
	CFormView::Dump(dc); 
} 
 
CDiskIODoc* CDiskIOView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDiskIODoc))); 
	return (CDiskIODoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CDiskIOView message handlers 
 
void CDiskIOView::OnButton1()  
{ 
	CString cs; 
	IoOpt(0,cs); 
	AfxMessageBox(cs); 
 
} 
 
int CDiskIOView::IoOpt(int mode,CString& csError) 
{ 
	char szTemp[600]; 
	m_diskinfo.drive=0; 
	GetDlgItem(IDC_EDIT1)->GetWindowText(szTemp,512); 
	m_diskinfo.head=atoi(szTemp); 
	GetDlgItem(IDC_EDIT2)->GetWindowText(szTemp,512); 
	m_diskinfo.track=atoi(szTemp); 
	GetDlgItem(IDC_EDIT3)->GetWindowText(szTemp,512); 
	m_diskinfo.sector=atoi(szTemp); 
	GetDlgItem(IDC_EDIT5)->GetWindowText(szTemp,512); 
	m_diskinfo.nsectors =atoi(szTemp); 
 
	if(m_diskinfo.sector==0||m_diskinfo.sector>255) 
	{ 
		csError="扇区号必须在1至255之间"; 
		return -100; 
	} 
	else if(m_diskinfo.head>1) 
	{ 
		csError="磁头号只能为0或1"; 
		return -100; 
	} 
	else if(m_diskinfo.track>84) 
	{ 
		csError="磁道号必须在0至84之间"; 
		return -100; 
	} 
 
 
	int ir=0; 
	switch(mode) 
	{ 
	case 0: 
		memset(buffer,0,512); 
 		ir=diskopt.MakeSector(m_diskinfo.drive, 
		m_diskinfo.head, 
		m_diskinfo.track, 
		m_diskinfo.sector, 
		buffer); 
		break; 
	case 1:		//write 
 
		memset(buffer,0,512); 
		GetDlgItem(IDC_EDIT6)->GetWindowText(szID[1],sizeof(szID[1])); 
		GetDlgItem(IDC_EDIT7)->GetWindowText(szID[2],sizeof(szID[2])); 
		ir=diskopt.WriteSector(m_diskinfo.drive, 
		m_diskinfo.head, 
		m_diskinfo.track, 
		m_diskinfo.sector, 
		buffer); 
		break; 
	case 2:		//read 
		ir=diskopt.ReadSector(m_diskinfo.drive, 
		m_diskinfo.head, 
		m_diskinfo.track, 
		m_diskinfo.sector, 
		buffer); 
		if(ir) 
			memset(buffer,0,512); 
		GetDlgItem(IDC_EDIT6)->SetWindowText(szID[1]); 
		GetDlgItem(IDC_EDIT7)->SetWindowText(szID[2]); 
		InvalidateRect(NULL,TRUE); 
//		InvalidateRect(hwndEdit[4],NULL,TRUE);	 
		break; 
	} 
	diskopt.ErrMsg(ir,szTemp); 
	csError=szTemp; 
	return ir; 
//	AfxMessageBox(szTemp); 
 
} 
 
void CDiskIOView::OnButton2()  
{ 
	CString cs; 
	IoOpt(2,cs); 
	AfxMessageBox(cs); 
 
} 
 
void CDiskIOView::OnButton3()  
{ 
	CString cs; 
	IoOpt(1,cs); 
	AfxMessageBox(cs); 
 
} 
 
void CDiskIOView::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
	CString csSpace; 
	CString cs; 
	CString csValue; 
	char c1=13; 
	char c2=10; 
	char ctemp[20]; 
	csSpace=c1; 
	csSpace+=c2; 
 
	cs.Format("%s",buffer); 
 
	int i,j; 
 
	cs=""; 
	 for(j=0;j<32;j++) 
	 { 
		wsprintf(ctemp,"%03d(%03X)",j*16,j*16); 
		cs+=csSpace; 
		for(i=0;i<16;i++) 
		{ 
			wsprintf(ctemp,"%02X ",buffer[i+j*16]); 
			cs+=ctemp; 
	 } 
 	   
	 } 
	GetDlgItem(IDC_EDIT4)->SetWindowText(cs);	 
 
} 
 
 
void CDiskIOView::OnButton4()  
{ 
	CString cs; 
	if(IoOpt(0,cs)!=0) 
	{ 
		AfxMessageBox(cs); 
		return; 
	} 
	if(IoOpt(1,cs)!=0) 
	{ 
		AfxMessageBox(cs); 
		return; 
	}else 
		AfxMessageBox(cs); 
	 
}