⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bin2txtdlg.cpp

📁 图片转化工具,非常好用的一款软件,将图片转换为十六进制
💻 CPP
字号:
// bin2txtDlg.cpp : implementation file
//

#include "stdafx.h"
#include "bin2txt.h"
#include "bin2txtDlg.h"
#include <fstream>
#include <iomanip>
#include <numeric>
#include <vector>

#include ".\bin2txtdlg.h"

using namespace std;

#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()

/////////////////////////////////////////////////////////////////////////////
// CBin2txtDlg dialog

CBin2txtDlg::CBin2txtDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBin2txtDlg::IDD, pParent)
{
	std::vecter<int> vi;
	//{{AFX_DATA_INIT(CBin2txtDlg)
	m_strDestPath = _T("");
	m_strSourcePath = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBin2txtDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBin2txtDlg)
	DDX_Control(pDX, IDC_BUTTON_CONVERT, m_bnConvert);
	DDX_Text(pDX, IDC_EDIT_DEST, m_strDestPath);
	DDX_Text(pDX, IDC_EDIT_SOURCE, m_strSourcePath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBin2txtDlg, CDialog)
	//{{AFX_MSG_MAP(CBin2txtDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CONVERT, OnButtonConvert)
	ON_BN_CLICKED(IDC_BUTTON_DEST_PATH, OnButtonDestPath)
	ON_BN_CLICKED(IDC_BUTTON_SOURCE_PATH, OnButtonSourcePath)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_TEST, OnBnClickedButtonTest)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBin2txtDlg message handlers

BOOL CBin2txtDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CBin2txtDlg::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 CBin2txtDlg::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 CBin2txtDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CBin2txtDlg::OnButtonConvert() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	if(m_strDestPath.IsEmpty() || m_strSourcePath.IsEmpty())
		return;

	ifstream infile(LPCTSTR (m_strSourcePath), ios::binary | ios::in);
	if(!infile)
		return;

	ofstream outfile(m_strDestPath.operator LPCTSTR() );
//	if(!outfile.is_open())
//		return;

	unsigned char inbuffer[16]={0};
	char outbuffer[128]={0};
	int gcount;

	infile.read((char*)inbuffer,sizeof(inbuffer));

	outfile << std::setw(2);
	outfile << std::setbase(ios_base::hex);
	while( (gcount = infile.gcount()) > 0)
	{
		int count = sprintf(outbuffer,"%02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx %02lx\n",
									inbuffer[0],inbuffer[1],inbuffer[2],inbuffer[3],inbuffer[4],inbuffer[5],inbuffer[6],inbuffer[7],
									inbuffer[8],inbuffer[9],inbuffer[10],inbuffer[11],inbuffer[12],inbuffer[13],inbuffer[14],inbuffer[15]);
		
//		for (int i = 0 ; i < gcount ; ++i)
//		{
//			outfile << inbuffer[i]<<" "; 
//		}
//		outfile<<endl;
		outfile.write(outbuffer,count);
		infile.read((char*)inbuffer,sizeof(inbuffer));
	}

	UpdateData(FALSE);
}

void CBin2txtDlg::OnButtonDestPath() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(FALSE);
	dlg.DoModal();
	m_strDestPath = dlg.GetPathName();
	UpdateData(FALSE);
}

void CBin2txtDlg::OnButtonSourcePath() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE);

	dlg.DoModal();
	m_strSourcePath = dlg.GetPathName();
	UpdateData(FALSE);
}

void CBin2txtDlg::OnBnClickedButtonTest()
{
	int vi[] = {1,2,3,4,5,6};
	int *vip = vi;

	int Sum = accumulate(vip,vip+6,0);


	for(int i = 0 ; i < 6; ++i)
	{
		int a  = accumulate(vip,vip+i,0);
		int b  = accumulate(vip,vip+i+1,0);

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -