1 Create this program step by step with Visualc++.net or VisualC++ 6.0
We open a file to view the content in hex mode
void ChexdumpView::OnDraw(CDC* /*pDC*/)
void ChexdumpView::OnDraw(CDC* pDC)info: with VisualC++ 6.0 this line needs no change
void ChexdumpView::OnDraw(CDC* pDC) { ChexdumpDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here pDC->TextOut(100,10,"Hexdump file data"); // ==>> code 01 }
// hexdumpDoc.cpp : implementation of the ChexdumpDoc class #include "stdafx.h" #include "hexdump.h" #include "hexdumpDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #endif unsigned int iFileSize; char cBuffer[100000];
void ChexdumpDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here iFileSize = ar.Read(cBuffer,100000); } }
// hexdumpView.cpp : implementation of the ChexdumpView class // #include "stdafx.h" #include "hexdump.h" #include "hexdumpDoc.h" #include "hexdumpView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif extern unsigned int iFileSize; extern char cBuffer[]; char *ptr1,*ptr2; int xx,yy; int ii,iLineNumber; CString str1,strLine; unsigned char chx; char cInfoText[20];
// ==>> code 01 if(iFileSize == 0) return; ptr1 = cBuffer; ptr2 = ptr1 + iFileSize; // ==>> code 02
// ==>> code 02 strLine.Format("addr "); ii=0; while(ii < 16) {str1.Format("%02X ", ii++); strLine+=str1;} xx=10; yy=30; pDC->TextOut(xx,yy,strLine); yy+=25; // ==>> code 03
// ==>> code 03 iLineNumber=0; while(iLineNumber < 20) { strLine.Format("%04X ",iLineNumber*16); ii=0; while(ii < 16) { chx=*ptr1++; str1.Format("%02X ", chx); strLine+=str1; if(isalnum(chx)) cInfoText[ii]= chx; else cInfoText[ii]= '.'; ii++; } str1.Format(" %s", cInfoText); strLine+=str1; pDC->TextOut(xx,yy,strLine); yy+=18; iLineNumber++; }
void ChexdumpView::OnDraw(CDC* pDC) { ChexdumpDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here pDC->TextOut(100,10,"Hexdump file data"); // ==>> code 01 if(iFileSize == 0) return; ptr1 = cBuffer; ptr2 = ptr1 + iFileSize; // ==>> code 02 strLine.Format("addr "); ii=0; while(ii < 16) {str1.Format("%02X ", ii++); strLine+=str1;} xx=10; yy=30; pDC->TextOut(xx,yy,strLine); yy+=25; // ==>> code 03 iLineNumber=0; while(iLineNumber < 20) { strLine.Format("%04X ",iLineNumber*16); ii=0; while(ii < 16) { chx=*ptr1++; str1.Format("%02X ", chx); strLine+=str1; if(isalnum(chx)) cInfoText[ii]= chx; else cInfoText[ii]= '.'; ii++; } str1.Format(" %s", cInfoText); strLine+=str1; pDC->TextOut(xx,yy,strLine); yy+=18; iLineNumber++; } }
ChexdumpDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; pDC->TextOut(100,10,"Hexdump file data"); pDC->SelectObject(&m_font); //only this line
void ChexdumpView::OnInitialUpdate() { CView::OnInitialUpdate(); if (iFontFlag==0) { memset(&logfont,0,sizeof(logfont)); logfont.lfHeight=14; logfont.lfWidth=10; CString szFont; szFont="Courier New"; lstrcpy(logfont.lfFaceName,szFont); VERIFY(m_font.CreateFontIndirect(&logfont)); SetFont(&m_font); iFontFlag=1; } }
CFont m_font; LOGFONT logfont;
public: virtual void OnInitialUpdate();