📄 手机维修工具软件集dlg.cpp
字号:
// 手机维修工具软件集Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "手机维修工具软件集.h"
#include "手机维修工具软件集Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_openfile = _T("");
m_savefile = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
DDX_Text(pDX, IDC_EDIT1, m_openfile);
DDX_Text(pDX, IDC_EDIT2, m_savefile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnOpenFile)
ON_BN_CLICKED(IDC_BUTTON2, OnSaveFile)
ON_BN_CLICKED(IDC_BUTTON3, Onzh)
ON_BN_CLICKED(IDC_RADIO1, OnRadioBINS3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_PRO_MSG,OnProMsg)//自定义消息
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_progress1.SetRange(0,100);
m_progress1.SetPos(0);
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(BST_CHECKED);//让第一单选框被选中
gnbz=1;op="二进制文件(*.bin)|*.bin";sa="SER文件(*.s3)|*.s3";
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnOpenFile()
{
xz();
CFileDialog dlg(TRUE, "EC", "",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,op);
if ( dlg.DoModal()!=IDOK ) return;
{
// CString sFileName=dlg.GetPathName();
POSITION pos = dlg.GetStartPosition(); //获取文件的绝对路径最好的方法
CString sFileName=dlg.GetNextPathName(pos);
m_openfile=sFileName;
FilePath=m_openfile;
UpdateData(false);
}
}
void CMyDlg::OnSaveFile()
{
xz();
CString la;
CFileDialog dlg(false, "EC", "",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,sa);
if ( dlg.DoModal()!=IDOK ) return;
{
CString sFileName=dlg.GetPathName();//获取文件的绝对路径
m_savefile=sFileName;
UpdateData(false);
if(m_fileSave.Open(dlg.GetPathName(),CFile::shareCompat|CFile::modeCreate|CFile::modeWrite,NULL))
{
m_fileSave.Close();
}
}
}
void CMyDlg::OpenFile()
{
CMyDlg* mydlg;
if(mydlg->FilePath!="")
{
CFile MyFile1(mydlg->FilePath,CFile::modeRead);
mydlg->Binsize=MyFile1.GetLength();
void far*p=::GlobalAlloc(0,mydlg->Binsize);
if (p==NULL)
{
AfxMessageBox("打开文件错误!");
}
MyFile1.ReadHuge(p,Binsize);
if (mydlg->Binsize%0x10!=0)
{
AfxMessageBox("文件大小有误!");
}
MyFile1.Close();
AfxMessageBox("打开文件ok!");
::GlobalFree(p);
}
}
void CMyDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CMyDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CMyDlg::Onzh()
{
xz();
AfxBeginThread(ZhThread,this)!=NULL;//启动线程
}
UINT CMyDlg::OnProMsg(WPARAM dwMsg,LPARAM dwMsg2)//自定义消息相应函数(接收消息)
{
m_progress1.SetPos(dwMsg);
//AfxMessageBox("发送消息成功!");
return 0;
}
UINT CMyDlg::ZhThread(LPVOID pParam)//工作线程
{
int i,ii;BYTE check;CString tempstr,tempstring;BYTE buffer[16];
CString aa;
DWORD dwRead;
CMyDlg* mydlg=(CMyDlg*)pParam;//定义本类的对象用于该线程
if(mydlg->FilePath=="")
{
AfxMessageBox("请打开文件!");
return 0;
}
if(mydlg->m_savefile=="")
{
AfxMessageBox("请选择保存文件路径!");
return 0;
}
else
{
CFile MyFile1(mydlg->FilePath,CFile::modeRead);
CFile mFile(mydlg->m_savefile,CFile::modeWrite);//定义写文件的对象
mFile.SetLength(0);//将保存的文件设置为0字节,便于重复转换
mydlg->Binsize=MyFile1.GetLength();//获取文件大小
if(mydlg->gnbz==1)//如选择BIN TO S3
{
MyFile1.SeekToBegin;//将文件指针移动到文件头
mFile.Write("S00600004844521B\r\n",18); //s3文件头
for(ii=0;ii<mydlg->Binsize/16;ii++)
{//循环将二进制文件读入缓冲区,每次读入16字节
check=0x00;
dwRead=MyFile1.Read(buffer,16);
tempstr.Format("%08X",ii*16);//地址转字符
tempstring="15"+tempstr;
for (i=0;i<16;i++)// 每16字节为一组转换成字符串
{
tempstr.Format("%02X",buffer[i]);
tempstring+=tempstr;
}
for(i=0;i<tempstring.GetLength();i+=2)
{
aa=tempstring.Mid(i,2);
check+=strtol(aa,NULL,16);//atoi(tempstring.Mid(i,2));
}
tempstr.Format("%02X",(0xff-check));//校验和反码后转字符
tempstring="S3"+tempstring+tempstr;
tempstring+="\r\n";//添加换行符
mFile.SeekToEnd(); //移动到末尾
mFile.Write(tempstring,tempstring.GetLength());
tempstring="";
::PostMessage(AfxGetMainWnd()->m_hWnd, WM_PRO_MSG, (WPARAM)((ii+1)*100)/(mydlg->Binsize/16), 0);
}
if (mydlg->Binsize%0x10!=0)//检查文件是否有非整数据
{
check=0x00;
dwRead=MyFile1.Read(buffer,(mydlg->Binsize%0x10));
for (i=0;i<(mydlg->Binsize%0x10);i++)// 每16字节为一组转换成字符串
{
tempstr.Format("%02X",buffer[i]);
tempstring+=tempstr;
}
tempstr.Format("%08X",ii*16);//计算字节数并转换成字符
tempstring=tempstr+tempstring;
tempstr.Format("%02d",i-1);//计算字节数并转换成字符
tempstring=tempstr+tempstring;
for(i=0;i<tempstring.GetLength();i+=2)//添加字符个数
{
aa=tempstring.Mid(i,2);
check+=strtol(aa,NULL,16);
}
tempstr.Format("%02X",(0xff-check));
tempstring+=tempstr+"\r\n";//添加换行符
tempstring="S3"+tempstring;
mFile.Write(tempstring,tempstring.GetLength()); //将转换后的文本写入文件末尾
}
mFile.Write("S705A002000058\r\n",16);//写入结尾
MyFile1.Close();//关闭文件对象
mFile.Close(); //关闭文件对象
AfxMessageBox("转换成功!");
::PostMessage(AfxGetMainWnd()->m_hWnd, WM_PRO_MSG, (WPARAM)0, 0);
}
else if(mydlg->gnbz==3)//s3 to bin
{
CStdioFile file;
CString str;
CString filepath,strTemp;
int i;
i = 0;
file.Open(mydlg->FilePath, CFile::modeRead); // 有了上句,这里可省略
file.Open(mydlg->FilePath, CFile::modeRead | CFile::typeText);
while (file.GetPosition() < file.GetLength()-1)
{
file.ReadString(str);
//sSql=sSql+s+"\r\n";
TRACE("%s\n", str);
}
file.Close();
strTemp.Format("%02d",i);
AfxMessageBox(strTemp+"行");
}
}
return 1;
}
void CMyDlg::zh()
{
}
void CMyDlg::OnRadioBINS3()
{
}
void CMyDlg::xz()
{
UINT nles=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO10);
switch(nles)
{
case IDC_RADIO1:
gnbz=1;op="二进制文件(*.bin)|*.bin";sa="SER文件(*.s3)|*.s3";
break;
case IDC_RADIO2:
gnbz=2;op="二进制文件(*.bin)|*.bin";sa="BIF文件(*.bif)|*.bif";
break;
case IDC_RADIO3:
gnbz=3;op="S3文件(*.s3)|*.s3";sa="二进制文件(*.bin)|*.bin";
break;
case IDC_RADIO4:
gnbz=4;op="BIF文件(*.bif)|*.bif";sa="二进制文件(*.bin)|*.bin";
break;
case IDC_RADIO5:
gnbz=5;op="二进制文件(*.bin)|*.bin";sa="MOT文件(*.mo)|*.mo";
break;
case IDC_RADIO6://BIN分段
gnbz=5;op="二进制文件(*.bin)|*.bin";sa="二进制文件(*.bin)|*.bin";
break;
case IDC_RADIO7:
gnbz=6;op="MOT文件(*.mo)|*.bif";sa="二进制文件(*.bin)|*.bin";
break;
case IDC_RADIO8:
AfxMessageBox("8");
break;
case IDC_RADIO9:
AfxMessageBox("9");
break;
case IDC_RADIO10:
AfxMessageBox("10");
break;
}
}
void CMyDlg::OnButton4()
{
CString filter(TEXT("ESRI dBASE (*.shp)|*.shp|ESRI dBASE (*.shx)|*.shx|ESRI dBASE (*.dbf)|*.dbf|所有文件 (*.*)|*.*|"));
CFileDialog dlg(TRUE, TEXT(".dbf"), NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, filter);
/*多选文件之用 */
DWORD MAXFILE = 4000;//能打开的所有文件的最大字符数;
char * path;
int nFileCount=0;//记录打开的文件个数;
CFile f;
unsigned char *lp=new unsigned char[100];
dlg.m_ofn.nMaxFile=MAXFILE;
char * pc=new char[MAXFILE];
dlg.m_ofn.lpstrFile =pc;
dlg.m_ofn.lpstrFile[0]=NULL;
CString filepath;
if (dlg.DoModal() == IDOK)
{
POSITION pos=dlg.GetStartPosition();
while (pos!=NULL)
{
filepath=dlg.GetNextPathName(pos);
MessageBox(filepath);
f.Open(filepath,CFile::modeRead,NULL);
f.Read(lp,100);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -