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

📄 convert.cpp

📁 解析BMP文件
💻 CPP
字号:
// Convert.cpp : implementation file
//

#include "stdafx.h"
#include "bmp2txt.h"
#include "Convert.h"
#include "JDib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static char BASED_CODE szBMPFilter[] = "BMP Files(*.bmp)|*.bmp";
static char BASED_CODE szTXTFilter[] = "BMP Files(*.c)|*.c";

/////////////////////////////////////////////////////////////////////////////
// CConvert dialog


CConvert::CConvert(CWnd* pParent /*=NULL*/)
	: CDialog(CConvert::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConvert)
	m_strDest = _T("");
	m_strSrc = _T("");
	//}}AFX_DATA_INIT
}


void CConvert::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConvert)
	DDX_Text(pDX, IDC_EDIT_DEST, m_strDest);
	DDX_Text(pDX, IDC_EDIT_SRC, m_strSrc);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConvert, CDialog)
	//{{AFX_MSG_MAP(CConvert)
	ON_BN_CLICKED(IDC_BUTTON_SRC, OnButtonSrc)
	ON_BN_CLICKED(IDC_BUTTON_DEST, OnButtonDest)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConvert message handlers

void CConvert::OnButtonSrc() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CFileDialog SrcOpenBox(TRUE, "BMP", NULL, OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, szBMPFilter);

	CString strInitPath;
	DWORD	len, n;

	len = ::GetTempPath(MAX_PATH, (LPTSTR)(LPCTSTR)strInitPath);
	ASSERT(len>0);

	n = strInitPath.Find(_T("LOCALS~1"), 0);
	strInitPath = strInitPath.Left(n-1);
	strInitPath = strInitPath.Left(n-1);

	strInitPath += "\\My Documents\\My Pictures";

	SrcOpenBox.m_ofn.lpstrInitialDir = strInitPath;
	SrcOpenBox.m_ofn.lpstrTitle = "Browse";
	if(SrcOpenBox.DoModal() == IDOK)
	{
		m_strSrc = SrcOpenBox.GetPathName();
		if(m_strDest.IsEmpty())
		{
			m_strDest = m_strSrc.Left( m_strSrc.ReverseFind('.') );
			m_strDest += ".c";
		}
	}
	UpdateData(FALSE);
}

void CConvert::OnButtonDest() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CFileDialog DestOpenBox(TRUE, "C", NULL, OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, szTXTFilter);
	DestOpenBox.m_ofn.lpstrInitialDir = "C:\\Documents and Settings\\bxc1998093.BXC\\My Documents\\My Pictures";
	DestOpenBox.m_ofn.lpstrTitle = "Browse";
	if(DestOpenBox.DoModal() == IDOK)
	{
		m_strDest = DestOpenBox.GetPathName();
	}
	UpdateData(FALSE);
}

void CConvert::OnOK() 
{
	// TODO: Add extra validation here
	CJDib JDib;
	JDib.m_strBMPName = m_strSrc;
	JDib.m_strTXTName = m_strDest;
	JDib.ConvertToText();
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

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