www.pudn.com > Sector1.rar > Sector1View.cpp
// Sector1View.cpp : implementation of the CSector1View class // #include "stdafx.h" #include "Sector1.h" #include "Sector1Doc.h" #include "Sector1View.h" #include#include #include"diskinfo.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSector1View IMPLEMENT_DYNCREATE(CSector1View, CView) BEGIN_MESSAGE_MAP(CSector1View, CView) //{{AFX_MSG_MAP(CSector1View) ON_COMMAND(ID_READ, OnRead) ON_COMMAND(ID_RECOVERY, OnRecovery) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSector1View construction/destruction CSector1View::CSector1View() { // TODO: add construction code here buf=new BYTE[1024]; memset(buf,0,512); m_Drive=1; m_StartSector=0; m_Tsector=2; } CSector1View::~CSector1View() { } BOOL CSector1View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CSector1View drawing void CSector1View::OnDraw(CDC* pDC) { CSector1Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here pDC->TextOut(0,0,buf); } ///////////////////////////////////////////////////////////////////////////// // CSector1View printing BOOL CSector1View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CSector1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CSector1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CSector1View diagnostics #ifdef _DEBUG void CSector1View::AssertValid() const { CView::AssertValid(); } void CSector1View::Dump(CDumpContext& dc) const { CView::Dump(dc); } CSector1Doc* CSector1View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSector1Doc))); return (CSector1Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CSector1View message handlers void CSector1View::OnRead() { // TODO: Add your command handler code here //if (bDrive == 0) return 0;// char devName[] = "\\\\.\\A:"; char devName[]="\\\\.\\F:";// devName[4] ='A' + bDrive - 1; HANDLE hDev=CreateFile(devName,GENERIC_READ,FILE_SHARE_WRITE, NULL,OPEN_EXISTING,0,NULL);//获得文件句柄 if(hDev==INVALID_HANDLE_VALUE) return; SetFilePointer(hDev,512*m_StartSector,0,FILE_BEGIN);//设置文件位置指示器 DWORD dwCB; ReadFile(hDev,buf,512*m_Tsector,&dwCB,NULL);//读文件 CloseHandle(hDev); //GetDocument()->UpdateAllViews(0,0); char sbuf[8192]; char *buf2=(char *)buf; char add[64]; unsigned int count=1024; memset(sbuf,0,1024); memset(add,0,64); char text[17]; memset(text,0,17); text[0]=' '; for(unsigned int i=0;i<=count;i++) { if(i == 0) sprintf(add,"第 %d 扇区:\r\n %08X : %02X ",i/512,i,buf[i]); else if((i==8) || i % 16 ==8) sprintf(add,"- %02X ",buf[i]); else if( (i>0) && (i % 16 ==0)) { memcpy(text+1,buf2+(i-16),16); memcpy(add,text,17); if(i==count) goto end; if(i % 512 == 0) sprintf(add+17,"\r\n第 %d 扇区:\r\n %08X : %02X ",i/512,i,buf[i]); else sprintf(add+17,"\r\n %08X : %02X ",i,buf[i]); } else sprintf(add,"%02X ",buf[i]); end : strcat(sbuf,add); memset(add,0,64); } CDC* pDC=GetDC(); for(int k=0;k<64;k++) { char buffer[64]; memcpy(buffer,sbuf+64*k,64); pDC->TextOut(0,32*k,buffer); } ReleaseDC(pDC); return ; } void CSector1View::OnRecovery() { BYTE buffer[512],sbuf[32]; char bclus[4]; DWORD startsec=18171; WORD tosec=1; BYTE hdis='J'; /*char devName[]="\\\\.\\J:";// devName[4] ='A' + bDrive - 1; HANDLE hDev=CreateFile(devName,GENERIC_READ,FILE_SHARE_WRITE, NULL,OPEN_EXISTING,0,NULL);//获得文件句柄 if(hDev==INVALID_HANDLE_VALUE) return; SetFilePointer(hDev,512*startsec,0,FILE_BEGIN);//设置文件位置指示器 DWORD dwCB; ReadFile(hDev,buffer,512*tosec,&dwCB,NULL);//读文件 CloseHandle(hDev);*/ CDiskInfo disk; BOOL i=disk.ReadSector(hdis,startsec,tosec,buffer); memcpy(sbuf,buffer,32); sprintf(bclus,"%d ",sbuf[26]); }