📄 charviewview.cpp
字号:
// CharViewView.cpp : implementation of the CCharViewView class
//
#include "stdafx.h"
#include "CharView.h"
#include "CharViewDoc.h"
#include "CharViewView.h"
#include "code.h"
#include "DLGOption.h"
#include "math.h"
#include "DLGOption.h"
#define ZERO 0
#define ONE 1
#define TWO 2
#define TEN 10
#define ELEVEN 11
#define TWELVE 12
#define THIRTEEN 13
#define FORTEEN 14
#define FIFTEEN 15
#define SEVENTY 70
#define NINTY 90
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int htoi( LPCTSTR s);
long strHexToInt(char* strSource);
long StrToData(CString strData,int jz);
long npf(int d,int n);
BOOL isRightData(char c,int jz);
/////////////////////////////////////////////////////////////////////////////
// CCharViewView
IMPLEMENT_DYNCREATE(CCharViewView, CScrollView)
BEGIN_MESSAGE_MAP(CCharViewView, CScrollView)
//{{AFX_MSG_MAP(CCharViewView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_SETUP, OnSetup)
ON_COMMAND(IDR_FONT, OnFont)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCharViewView construction/destruction
CCharViewView::CCharViewView()
{
// TODO: add construction code here
}
CCharViewView::~CCharViewView()
{
}
BOOL CCharViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCharViewView drawing
void CCharViewView::OnDraw(CDC* pDC)
{
CCharViewDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int Length = m_CodeList.GetSize();
int x = TEN;
int y = ZERO;
// int z = TWENTYFIVE;
char code[7] ;
CCode* p;
COLORREF crColor ;
CFont* pFont = new CFont() ;
pFont->CreateFontIndirect(&m_OptionParm.m_lf);
pDC->SelectObject( pFont );
for(long i = ZERO; i < Length; i++ )
{
p = m_CodeList.GetAt(i);
//OnlyCode
if(m_OptionParm.m_CodeMode == COptionParm::DRAW_ONLYCODE)
{
if( m_OptionParm.m_CodeTop == -1 )
{
sprintf( code, "0x%04x", p->m_data );
if(i % TEN != ZERO)
{
x += SEVENTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
TextOut(pDC->GetSafeHdc(), x, y, code, strlen(code) );
}
if(m_OptionParm.m_CodeTop != -1)
{
if(p->m_data >= m_OptionParm.m_CodeDown && p->m_data <= m_OptionParm.m_CodeTop)
{
sprintf( code, "0x%04x", p->m_data );
if(i % TEN != ZERO)
{
x += SEVENTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
TextOut(pDC->GetSafeHdc(), x, y, code, strlen(code) );
}
}
}
//OnlyChar
if(m_OptionParm.m_CodeMode == COptionParm::DRAW_ONLYCHAR)
{
if( m_OptionParm.m_CodeTop == -1 )
{
if(i % TEN != ZERO)
{
x += SEVENTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
char c[3];
c[0] = HIBYTE(p->m_data);
c[1] = LOBYTE(p->m_data);
c[2] = ZERO;
TextOut(pDC->GetSafeHdc(), x, y, c, 2 );
}
if(m_OptionParm.m_CodeTop != -1)
{
if(p->m_data >= m_OptionParm.m_CodeDown && p->m_data <= m_OptionParm.m_CodeTop)
{
if(i % TEN != ZERO)
{
x += SEVENTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
char c[3];
c[0] = HIBYTE(p->m_data);
c[1] = LOBYTE(p->m_data);
c[2] = ZERO;
TextOut(pDC->GetSafeHdc(), x, y, c, 2 );
}
}
}
//Char and Code
if(m_OptionParm.m_CodeMode == COptionParm::DRAW_CODECHAR)
{
if( m_OptionParm.m_CodeTop == -1 )
{
if(i % TEN != ZERO)
{
x += NINTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
char c[3];
c[0] = HIBYTE(p->m_data);
c[1] = LOBYTE(p->m_data);
c[2] = ZERO;
TextOut(pDC->GetSafeHdc(), x, y, c, 2 );
sprintf( code, "0x%04x", p->m_data );
TextOut(pDC->GetSafeHdc(), x + 20, y,code, strlen(code));
}
if(m_OptionParm.m_CodeTop != -1)
{
if(p->m_data >= m_OptionParm.m_CodeDown && p->m_data <= m_OptionParm.m_CodeTop)
{
sprintf( code, "0x%04x", p->m_data );
if(i % TEN != ZERO)
{
x += NINTY;
}
if(i % TEN == ZERO)
{
x = TEN;
y += FIFTEEN;
}
char c[3];
c[0] = HIBYTE(p->m_data);
c[1] = LOBYTE(p->m_data);
c[2] = ZERO;
TextOut(pDC->GetSafeHdc(), x, y,code, strlen(code));
TextOut(pDC->GetSafeHdc(), x, y, c, 2 );
}
}
}
}
delete pFont;
}
/////////////////////////////////////////////////////////////////////////////
// CCharViewView printing
BOOL CCharViewView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCharViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCharViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCharViewView diagnostics
#ifdef _DEBUG
void CCharViewView::AssertValid() const
{
CScrollView::AssertValid();
}
void CCharViewView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CCharViewDoc* CCharViewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCharViewDoc)));
return (CCharViewDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCharViewView message handlers
void CCharViewView::OnFileOpen()
{
// TODO: Add your command handler code here
CFileDialog* pcBrowse;
pcBrowse = new CFileDialog(TRUE, "mdb", NULL, NULL,
"Jet Database Files(*.mdb) | *.mdb |Text Files(*.txt) | *.txt||", NULL);
if ( IDOK != pcBrowse->DoModal() )
{
delete pcBrowse;
// AfxMessageBox(pcBrowse->GetPathName() );
return;
}
//char Flag[8];
CString FileName = pcBrowse->GetPathName() ;
CStdioFile mFile( FileName, CFile::modeRead );
CString str;
while(mFile.ReadString( str ) )
{
str = str.Right(str.GetLength() - 2);
CString Sstr( str );
//Sstr = Sstr.Left(str.GetLength() - 1);
int i = Sstr.Find(" ");
if ( i >= ZERO)
Sstr = Sstr.Left( i );
int Buffer = strHexToInt(Sstr.GetBuffer(0));
CCode* pCode = new CCode(Buffer);
//pCode->m_data = Flag;
m_CodeList.Add(pCode);
//mFile.ReadString( Flag, 6 );
// mFile.Seek(2, CFile::current);
}
// CString str;
str.Format( "%d", m_CodeList.GetSize() );
AfxMessageBox( str );
CSize size( ZERO, m_CodeList.GetSize()* 20 );
SetScrollSizes( MM_TEXT, size );
this->Invalidate();
delete pcBrowse;
}
/* convert hex string to int */
long strHexToInt(char* strSource)
{
long nTemp=0;
CString strTemp;
strTemp=strSource;
for(char cc='G',dd='g'; cc<='Z',dd<='z'; cc++,dd++) //判断输入的字符串是否合法
{
if(strTemp.Find(cc,ZERO) !=-1 || strTemp.Find(dd,ZERO) !=-1)
{
::MessageBox(NULL,"请输入正确的16进制字符串!","输入错误",MB_ICONEXCLAMATION);
return -1;
}
}
for(long i = ZERO; i<(long)::strlen(strSource); i++)
{
long nDecNum;
switch(strSource[i])
{
case 'a':
case 'A': nDecNum = TEN; break;
case 'b':
case 'B': nDecNum = ELEVEN; break;
case 'c':
case 'C': nDecNum = TWELVE; break;
case 'd':
case 'D': nDecNum = THIRTEEN; break;
case 'e':
case 'E': nDecNum = FORTEEN; break;
case 'f':
case 'F': nDecNum = FIFTEEN; break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': nDecNum = strSource[i] - '0'; break;
default: return ZERO;
}
nTemp += nDecNum * (long)::pow(16,::strlen(strSource)-i -1);
}
return nTemp;
}
/*int htoi( LPCTSTR str)
{
char* s = new char[ strlen(str) + 1];
strcpy( s, str );
char *digits="0123456789ABCDEF";
if (islower (s[0])) s[0]=toupper(s[0]);
if (islower (s[1])) s[1]=toupper(s[1]);
int result = 16 * (strchr(digits, s[0]) -strchr (digits,'0'))
+(strchr(digits,s[1])-strchr(digits,'0'));
delete[] s;
return result;
}
*/
void CCharViewView::OnSetup()
{
// TODO: Add your command handler code here
CDLGOption* pOptinon;
pOptinon = new CDLGOption();
if ( IDOK != pOptinon->DoModal() )
{
delete pOptinon;
return;
}
//UpdateData(TRUE);
m_OptionParm.m_CodeDown = StrToData(pOptinon->m_StartCode,16);
m_OptionParm.m_CodeTop = StrToData(pOptinon->m_EndCode,16);
switch(pOptinon->m_DrawType)
{
case ZERO :
m_OptionParm.m_CodeMode = COptionParm::DRAW_ONLYCHAR;
break;
case ONE :
m_OptionParm.m_CodeMode = COptionParm::DRAW_ONLYCODE;
break;
case TWO :
m_OptionParm.m_CodeMode = COptionParm::DRAW_CODECHAR;
break;
default :
m_OptionParm.m_CodeMode = COptionParm::DRAW_ONLYCHAR;
}
delete pOptinon;
this->Invalidate();
}
void CCharViewView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize size( 0, 0 );
SetScrollSizes( MM_TEXT, size );
}
void CCharViewView::OnFont()
{
// TODO: Add your command handler code here
CFontDialog* SelectFont;
SelectFont = new CFontDialog( NULL, CF_EFFECTS | CF_SCREENFONTS, NULL, NULL );
if ( IDOK == SelectFont->DoModal() )
{
SelectFont->GetCurrentFont( &m_OptionParm.m_lf );
SelectFont->GetColor();
this->Invalidate();
}
delete SelectFont;
return;
}
//CString to Int
long StrToData(CString strData,int jz)
{
int l=strData.GetLength();
long IntValue=0;
int bitValue;
int i;
for(i=0;i<l;i++)
{
if(isRightData(strData[i],jz))
{
if(isdigit(strData[i]))
bitValue=strData[i]-0x30;
else
{
switch(strData[i])
{
case 'a':
bitValue=0x0a;
break;
case 'b':
bitValue=0x0b;
break;
case 'c':
bitValue=0x0c;
break;
case 'd':
bitValue=0x0d;
break;
case 'e':
bitValue=0x0e;
break;
case 'f':
bitValue=0x0f;
break;
case 'A':
bitValue=0x0a;
break;
case 'B':
bitValue=0x0b;
break;
case 'C':
bitValue=0x0c;
break;
case 'D':
bitValue=0x0d;
break;
case 'E':
bitValue=0x0e;
break;
case 'F':
bitValue=0x0f;
break;
}
}
IntValue=bitValue*npf(jz,l-i-1)+IntValue;
}
else
return -1;
}
return IntValue;
}
long npf(int d,int n)
{
int i;
long m=1;
for(i=0;i<n;i++)
m*=d;
return m;
}
BOOL isRightData(char c,int jz)
{
if((jz<2)||(jz>16))
return FALSE;
char ch[]="00112233445566778899aAbBcCdDeEfF";
int i=0;
for(i=0;i<jz;i++)
{
if(c==ch[i*2])return TRUE;
if(c==ch[i*2+1])return TRUE;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -