📄 hexshowview.cpp
字号:
}
//look_length
//szBuf
}
//**************************************************************************
if (look_length<=0)//十六进制输入为空:采用文本
{
look_length=look_data.GetLength();
if (look_length<=0)
{
AfxMessageBox("数据长度不对!!!");
return;
}
i=0;
while(i<look_length)
{szBuf[i]=look_data.GetAt(i);
i++;
}
}
//***************************开始查找
// str=szBuf;
// AfxMessageBox("查找内容"+str);
lOffset=m_ten_begin;
i=0;
while(lOffset<m_ten_end)//filelength)
{
//AfxMessageBox("5");
filedata=pDoc->ReadFiledata(lOffset);
if (filedata==szBuf[i])
{
i++;
if (i==look_length)
{
str.Format("%x",lOffset);
AfxMessageBox("目标地址 "+str);
break;
}
}
else
{i=0;
}
lOffset++;
}
nLine=lOffset;
nLine=int(nLine/16)-1;
AfxMessageBox("查找结束");
//**********************************************
OnUpdate(NULL,NULL,NULL);
}
void CHexShowView::OnIdFileModify()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
CHexShowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_pHexFile==NULL)
{
AfxMessageBox("文件未打开");
return;}
CString m_modify;//修改内容
//CString m_address;//地址
long m_address=0;//地址
CString str;
Cmodify dlg;
// m_lFileLength=m_pHexFile->GetLength();
int data_length;
int * p_modify;
int szBuf[10];
unsigned char Char[10];
int i=0;
int k=0;
int nResponse = dlg.DoModal();
if (nResponse == IDCANCEL)
{return;
}
m_modify=dlg.m_modify;
str=dlg.m_address;
if( str.GetLength()<=0)
{
AfxMessageBox("目标地址错!!");
return;
}
m_address=Chex_long(str);
if(m_address<0)
{
AfxMessageBox("目标地址错!!");
return;
}
k=m_modify.GetLength();
if (k>20)
{
AfxMessageBox("数据太长!!!");
return;
}
if (int(k/2)*2!=k)
{
AfxMessageBox("数据长度不是偶数!!!");
return;
}
data_length=int(k/2);
if(m_address<0)
{
AfxMessageBox("目标地址出错!!!");
return;
}
p_modify=Chex_int_array(m_modify);
i=0;
while(i<k/2)
{
szBuf[i]=*p_modify;
p_modify++;
i++;
}
if(szBuf[0]<0)
{
AfxMessageBox("数据出错!!");
return;
}
i=0;
while(i<k/2)
{
Char[i]=szBuf[i];
i++;
}
//********************************
//data_length;
//Char[i]
//m_address
pDoc->Write(Char, data_length, m_address);
OnUpdate(NULL,NULL,NULL);
}
//********************
void CHexShowView::OnIdCharacterCode()
{
// TODO: Add your command handler code here
CString str;
CString str1;
CString str2;
CString CharCString;
unsigned short int CharCode;
WCHAR wb[4];//转UNICODE时用
Cgbkunicode dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDCANCEL)
{return;
}
CharCString=dlg.m_character;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
if(CharCString.GetLength()<1)//输入了空
return;
if(CharCString.GetLength()<2)//输入ASCII码
{
CharCode=CharCString.GetAt(0);
CharCode=CharCode&0XFF;
str1.Format("%x",CharCode);
AfxMessageBox("ASCII码 "+CharCString+" 十六进制GBK码 "+str1);
}
else//输入了汉字
{
CharCode=CharCString.GetAt(0);
CharCode=CharCode&0XFF;
if(CharCode<128)
return;//输入了两个ASCII码
str1.Format("%x",CharCode);
CharCode=CharCString.GetAt(1);
CharCode=CharCode&0XFF;
str2.Format("%x",CharCode);
AfxMessageBox("汉字 "+CharCString+" 十六进制GBK码 "+str1+str2);
//将GBK汉字的内码转成UNICODE的内码
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,CharCString,2,wb,2);
CharCode=wb[0];
str.Format("%x",CharCode);
AfxMessageBox("汉字 "+CharCString+" 十六进制UNICODE码 "+str);
}
//**************************************************
}
void CHexShowView::OnIdCodeCharacter()
{
// Cunicodegbk
CString str;
CString str1;
CString str2;
CString CharCString;
unsigned short int CharCode;
TCHAR tb[2];
WCHAR wb[4];//转UNICODE时用
Cunicodegbk dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDCANCEL)
{return;
}
CharCString=dlg.m_character;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
CharCString.MakeUpper();
if(CharCString.GetLength()<4)//输入少于四个字符
return;
if( Chex_long(CharCString)<0)//出错
return;
CharCode=Chex_long(CharCString);
if(CharCode<128)//ACII码不要转换
return;
wb[0]=CharCode;
WideCharToMultiByte(CP_ACP,0,wb,2,tb,2,NULL,NULL);
CharCode=tb[0];
CharCode=CharCode&0XFF;
str1.Format("%X",CharCode);
//AfxMessageBox(str);
CharCode=tb[1];
CharCode=CharCode&0XFF;
str2.Format("%X",CharCode);
//AfxMessageBox(str);
CharCString=tb;
CharCString=CharCString.Left(2);
AfxMessageBox("高位 "+str1+" 低位 "+str2+" " + CharCString);
}
void CHexShowView::OnIdDataMove() //移动数据
{
// TODO: Add your command handler code here
CHexShowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_pHexFile==NULL)
{
AfxMessageBox("文件未打开");
return;}
CString data_source;
CString data_target;
long address_data_source;
long address_data_target;
long data_length;
bool m_bResult;//函数返回结果
// CString str;
// CString str1;
// CString str2;
CString CharCString;
// unsigned short int CharCode;
// TCHAR tb[2];
// WCHAR wb[4];//转UNICODE时用
Cdatamove dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDCANCEL)
{return;
}
data_source=dlg.m_data_source;
data_target=dlg.m_data_target;
data_length=dlg.m_length;
if(data_length<=0)
{
AfxMessageBox("数据长度错误!!!");
return;
}
//Chex_long(CString str)
CharCString=data_source;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
CharCString.MakeUpper();
if( CharCString.GetLength()<=0)
{
AfxMessageBox("数据源地址空缺!!!");
return;
}
address_data_source=Chex_long(CharCString);
if(address_data_source<=0)
{
AfxMessageBox("数据源地址错误!!!");
return;
}
CharCString=data_target;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
CharCString.MakeUpper();
if( CharCString.GetLength()<=0)
{
AfxMessageBox("数据目的地址空缺!!!");
return;
}
address_data_target=Chex_long(CharCString);
if(address_data_target<=0)
{
AfxMessageBox("数据目的地址错误!!!");
return;
}
m_bResult=MoveData_bool(pDoc->m_pHexFile,address_data_source,address_data_target,data_length);
if( m_bResult==true)
{
AfxMessageBox("数据移动成功!!!");
return;
}
else
{
AfxMessageBox("数据目的移动失败!!!");
return;
}
}
bool CHexShowView::MoveData_bool(CFile * m_pCFile,long m_lAddressSource,long m_lAddressTarget,int m_intDataLength)
{
if(m_pCFile==NULL)
{
AfxMessageBox("文件未打开!!!");
return false;
}
if(m_lAddressSource<=0)
{
AfxMessageBox("要移动的数据原地址出错!!!");
return false;
}
if(m_lAddressTarget<=0)
{
AfxMessageBox("要移动的数据目标地址出错!!!");
return false;
}
if(m_intDataLength<=0)
{
AfxMessageBox("要移动的数据长度出错!!!");
return false;
}
long m_lPosition;//文件指针位置
long m_lDataLength;//数据长度
m_lPosition=m_pCFile->Seek(m_lAddressSource,CFile::begin);
BYTE * pbytes=new BYTE[m_intDataLength];
m_lDataLength=m_pCFile->Read(pbytes,m_intDataLength);
m_lPosition=m_pCFile->Seek(m_lAddressTarget,CFile::begin);
m_pCFile->Write(pbytes,m_intDataLength);
return true;
//return false;
}
void CHexShowView::OnIdDataSave()
{
// TODO: Add your command handler code here
CHexShowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(pDoc->m_pHexFile==NULL)
{
AfxMessageBox("文件未打开");
return;
}
CString CharCString;
int i=0;
long m_lAddressBegin;//数据开始地址
long m_lAddressEnd;//数据结束地址
CSaveData dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDCANCEL)
{
return;
}
//***************************
CharCString=dlg.m_addressbegin;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
CharCString.MakeUpper();
if( CharCString.GetLength()<=0)
{
AfxMessageBox("数据开始地址空缺!!!");
return;
}
m_lAddressBegin=Chex_long(CharCString);;//开始地址
CharCString=dlg.m_addressend;
CharCString.TrimLeft();
CharCString.TrimRight();
CharCString.Replace(" ","");
CharCString.MakeUpper();
if( CharCString.GetLength()<=0)
{
AfxMessageBox("数据结束地址空缺!!!");
return;
}
m_lAddressEnd=Chex_long(CharCString);//结束地址
if((m_lAddressBegin<0)||(m_lAddressEnd<0)||(m_lAddressBegin>=m_lAddressEnd))
{
AfxMessageBox("数据地址出错!!!");
return;
}
if (SaveData_bool(pDoc->m_pHexFile, m_lAddressBegin, m_lAddressEnd)==false)
{ AfxMessageBox("保存数据不成功!!!");
}
else
{ AfxMessageBox("OK");
}
}
bool CHexShowView::SaveData_bool(CFile* m_pCFile,long m_lAddressBegin,long m_lAddressEnd)
{
if(m_pCFile==NULL)
{
AfxMessageBox("文件未打开");
return false;
}
if((m_lAddressBegin<0)||(m_lAddressEnd<0)||(m_lAddressBegin>=m_lAddressEnd))
{
AfxMessageBox("数据地址出错!!!");
return false;
}
CString m_sPathName;//从文件对话框中取得完整路径和文件名
CFile * m_pCFileSave;
long m_lPosition;//文件指针位置
long m_lDataLength;//数据长度
int m_intDataLength;//数据长度
int i=0;
CString m_sFilter="*.*";
CFileDialog dlgSave(FALSE,0,0,OFN_OVERWRITEPROMPT, m_sFilter,this);
int nResponse = dlgSave.DoModal();
if (nResponse == IDCANCEL)
{
return false;
}
m_intDataLength=m_lAddressEnd-m_lAddressBegin+1;
m_sPathName=dlgSave.GetPathName();
m_pCFileSave=new CFile(m_sPathName,CFile::modeCreate |CFile::modeWrite);
if (!m_pCFileSave)
{
AfxMessageBox("保存文件出错!!");
return false;
}
BYTE * pbytes=new BYTE[10];
for (i=0;i<m_intDataLength;i++)
{
m_lPosition=m_pCFile->Seek(m_lAddressBegin+i,CFile::begin);
m_lDataLength=m_pCFile->Read(pbytes,10);
m_lPosition=m_pCFileSave->Seek(0+i,CFile::begin);
m_pCFileSave->Write(pbytes,1);
}
m_pCFileSave->Close();
delete m_pCFileSave;
m_pCFileSave=NULL;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -