// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "GftToImage.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
BEGIN_MESSAGE_MAP(CMainFrame, CUIWnd)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_BN_CLICKED(IDC_BTN_LOGO, OnBtnLogo)
ON_BN_CLICKED(IDC_RAD_SOURCE_FOLDER, OnRadSourceFolder)
ON_BN_CLICKED(IDC_RAD_SOURCE_FILE, OnRadSourceFile)
ON_BN_CLICKED(IDC_BTN_BROWSE_GFT, OnBtnBrowseGft)
ON_BN_CLICKED(IDC_BTN_BROWSE_IMAGE, OnBtnBrowseImage)
ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
END_MESSAGE_MAP()
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_pStaTitle = NULL;
m_pBtnMin = NULL;
m_pBtnClose = NULL;
m_pBtnLogo = NULL;
m_pRadSourceFolder = NULL;
m_pRadSourceFile = NULL;
m_pStaGft = NULL;
m_pEdtGftFolder = NULL;
m_pBtnBrowseGft = NULL;
m_pStaSaveto = NULL;
m_pEdtSaveto = NULL;
m_pBtnBrowseImage = NULL;
m_pChkDeleteGft = NULL;
m_pChkSubFolder = NULL;
m_pBtnStart = NULL;
m_strGftFolder = _T("");
m_strSaveto = _T("");
m_bSubFolder = TRUE;
m_bDeleteGft = TRUE;
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
void CMainFrame::DoDataExchange(CDataExchange* pDX)
{
CUIWnd::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDT_GFT_FOLDER, m_strGftFolder);
DDX_Text(pDX, IDC_EDT_SAVETO, m_strSaveto);
DDX_Check(pDX, IDC_CHK_SUB_FOLDER, m_bSubFolder);
DDX_Check(pDX, IDC_CHK_DELETE_GFT, m_bDeleteGft);
}
//////////////////////////////////////////////////////////////////////////
// protected
int CMainFrame::InitControls()
{
m_pStaTitle = (CSkinStatic *)GetDlgItem(IDC_STA_TITLE);
m_pBtnMin = (CSkinButton *)GetDlgItem(IDC_BTN_MIN);
m_pBtnClose = (CSkinButton *)GetDlgItem(IDC_BTN_CLOSE);
m_pBtnLogo = (CSkinButton *)GetDlgItem(IDC_BTN_LOGO);
m_pRadSourceFolder = (CSkinButton *)GetDlgItem(IDC_RAD_SOURCE_FOLDER);
m_pRadSourceFile = (CSkinButton *)GetDlgItem(IDC_RAD_SOURCE_FILE);
m_pStaGft = (CSkinStatic *)GetDlgItem(IDC_STA_GFT);
m_pEdtGftFolder = (CSkinEdit *)GetDlgItem(IDC_EDT_GFT_FOLDER);
m_pBtnBrowseGft = (CSkinButton *)GetDlgItem(IDC_BTN_BROWSE_GFT);
m_pStaSaveto = (CSkinStatic *)GetDlgItem(IDC_STA_SAVETO);
m_pEdtSaveto = (CSkinEdit *)GetDlgItem(IDC_EDT_SAVETO);
m_pBtnBrowseImage = (CSkinButton *)GetDlgItem(IDC_BTN_BROWSE_IMAGE);
m_pChkSubFolder = (CSkinButton *)GetDlgItem(IDC_CHK_SUB_FOLDER);
m_pBtnStart = (CSkinButton *)GetDlgItem(IDC_BTN_START);
m_pChkDeleteGft = (CSkinButton *)GetDlgItem(IDC_CHK_DELETE_GFT);
return 0;
}
int CMainFrame::SwitchSource()
{
BOOL bRet = UpdateData();
if (!bRet)
return -1;
int nChecked = m_pRadSourceFolder->GetCheck();
BOOL bEnableSourceFolder = TRUE;
if (nChecked != BST_CHECKED)
{
bEnableSourceFolder = FALSE;
}
m_pStaSaveto->ShowWindow(bEnableSourceFolder ? SW_HIDE : SW_SHOW);
m_pEdtSaveto->ShowWindow(bEnableSourceFolder ? SW_HIDE : SW_SHOW);
m_pBtnBrowseImage->ShowWindow(bEnableSourceFolder ? SW_HIDE : SW_SHOW);
m_pChkSubFolder->SetCheck(bEnableSourceFolder ? BST_CHECKED : BST_UNCHECKED);
m_pChkSubFolder->ShowWindow(bEnableSourceFolder ? SW_SHOW : SW_HIDE);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CUIWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (InitControls() != 0)
return -1;
CenterWindow();
// TODO: Add your message handler code here
UpdateData(FALSE);
m_pRadSourceFolder->SetCheck(BST_CHECKED);
OnRadSourceFolder();
return 0;
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// TODO: Add your message handler code here and/or call default
lpMMI->ptMinTrackSize.x = 480;
lpMMI->ptMinTrackSize.y = 350;
lpMMI->ptMaxSize.x = 1024;
lpMMI->ptMaxSize.y = 600;
CUIWnd::OnGetMinMaxInfo(lpMMI);
}
void CMainFrame::OnBtnLogo()
{
ShellExecute(NULL, _T("Open"), _T("http://www.iuishop.com"), NULL, NULL, SW_SHOW);
}
void CMainFrame::OnRadSourceFolder()
{
SwitchSource();
}
void CMainFrame::OnRadSourceFile()
{
SwitchSource();
}
void CMainFrame::OnBtnBrowseGft()
{
BOOL bRet = UpdateData();
if (!bRet)
return;
int nChecked = m_pRadSourceFolder->GetCheck();
if (nChecked == BST_CHECKED)
{
BROWSEINFO bInfo;
LPITEMIDLIST pidl;
CString strPath;
ZeroMemory ((PVOID)&bInfo, sizeof(BROWSEINFO));
bInfo.hwndOwner = this->GetSafeHwnd();
bInfo.pszDisplayName = strPath.GetBuffer(MAX_PATH);
bInfo.lpszTitle = _T("Browse");
bInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bInfo.lpfn = NULL;
bInfo.lParam = (LPARAM)this;
if ((pidl = ::SHBrowseForFolder(&bInfo) ) == NULL)
{
return;
}
if (::SHGetPathFromIDList(pidl, strPath.GetBuffer(MAX_PATH)) == FALSE)
{
return;
}
// to use bInfo.pszDisplayName
m_strGftFolder = bInfo.pszDisplayName;
}
else
{
TCHAR szFilters[]= _T("Tencent Gft Files (*.gft)|*.gft|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg(TRUE, _T("gft"), _T("*.gft"), OFN_FILEMUSTEXIST, szFilters);
int nRet = fileDlg.DoModal();
if (nRet == IDOK)
{
m_strGftFolder = fileDlg.GetPathName();
m_strSaveto = GetFilePath(m_strGftFolder);
}
}
UpdateData(FALSE);
}
void CMainFrame::OnBtnBrowseImage()
{
BOOL bRet = UpdateData();
if (!bRet)
return;
BROWSEINFO bInfo;
LPITEMIDLIST pidl;
CString strPath;
ZeroMemory ((PVOID)&bInfo, sizeof(BROWSEINFO));
bInfo.hwndOwner = this->GetSafeHwnd();
bInfo.pszDisplayName = strPath.GetBuffer(MAX_PATH);
bInfo.lpszTitle = _T("Browse");
bInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bInfo.lpfn = NULL;
bInfo.lParam = (LPARAM)this;
if ((pidl = ::SHBrowseForFolder(&bInfo) ) == NULL)
{
return;
}
if (::SHGetPathFromIDList(pidl, strPath.GetBuffer(MAX_PATH) ) == FALSE)
{
return;
}
// to use bInfo.pszDisplayName
m_strSaveto = bInfo.pszDisplayName;
UpdateData(FALSE);
}
enum IMAGE_TYPE
{
IT_UNKNOWN,
IT_BITMAP,
IT_PNG
};
#define E_GFT_FILE_OPEN -1
#define E_NOT_GFT_FILE -2
#define E_NO_IMAGE_DATA -3
#define E_NOT_SUPPORT_IMAGE -4
#define E_CREATE_IMAGE_FILE -5
int ConvertGft2Image(const CString &strGftFile, const CString &strImageFolder, BOOL bDeleteGft)
{
// Png and bmp file header
BYTE btPngHeader[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
WORD wBmpHeader = 0x4D42;
// Open gft file
FILE *fpGft = TFOPEN(strGftFile, _T("rb"));
if (fpGft == NULL)
return E_GFT_FILE_OPEN;
// Get Gft file length.
fseek(fpGft, 0, SEEK_END);
int nGftFileLength = ftell(fpGft);
// The byte of address 0x00000010 of gft file is specify the offset of image.
if (nGftFileLength < 17)
return E_NOT_GFT_FILE;
// Get image offset
fseek(fpGft, 0x00000010, SEEK_SET); // Seek to byte that specify the offset of image.
BYTE btImageOffset = 0;
fread(&btImageOffset, sizeof(BYTE), 1, fpGft);
if (btImageOffset + 2 >= nGftFileLength)
return E_NO_IMAGE_DATA;
// Check the image type.
IMAGE_TYPE eImageType = IT_UNKNOWN;
fseek(fpGft, btImageOffset, SEEK_SET);
WORD wHeader = 0;
fread(&wHeader, sizeof(WORD), 1, fpGft);
if (wHeader == wBmpHeader)
{
eImageType = IT_BITMAP;
}
else
{
if (btImageOffset + 8 >= nGftFileLength)
return E_NO_IMAGE_DATA;
fseek(fpGft, btImageOffset, SEEK_SET);
BYTE btHeader[8] = {0};
fread(btHeader, 8, 1, fpGft);
int nRet = memcmp(btPngHeader, btHeader, 8);
if (nRet == 0)
eImageType = IT_PNG;
}
if (eImageType == IT_UNKNOWN)
return E_NOT_SUPPORT_IMAGE;
// Convert gft to image file
CString strImageFile = strImageFolder;
if (strImageFile.Right(1) != _T("\\") && strImageFile.Right(1) != _T("/"))
st
psbeond
- 粉丝: 127
- 资源: 9
最新资源
- 《铭仕基本法》(2006年定稿版)-17页.doc
- 海尔企业文化手册.doc
- xx有限公司企业文化手册.doc
- 【案例分析】企业文化案例精选.doc
- 陕西省地方电力集团公司企业文化手册道德礼仪规范.doc
- 微信小程序 实现计算器代码
- 01-【目标体系构建】-企业文化建设规划与实施细则方案撰写指导说明.doc
- 03-【目标体系构建】-企业文化建设工作任务分解与工作推进表.docx
- 02-【目标体系构建】-企业文化建设三年实施规划甘特图.docx
- 04-【识别体系构建】-员工行为规范制定指导书.doc
- 07-【保障体系构建】-职务说明书——企业文化专员.doc
- 06-【保障体系构建】-职务说明书——企业文化建设职能部门(负责人).doc
- 08-【保障体系构建】-企业文化建设经费预算表(年度).doc.docx
- 12-【保障体系构建】-企业文化培训成本费用预算表.doc.docx
- 10-【保障体系构建】-企业文化培训效果综合评估表.doc.docx
- 11-【保障体系构建】-企业文化培训计划表.doc.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页