acl/app/jencode/JencodeDlg.cpp

422 lines
9.1 KiB
C++
Raw Normal View History

// JencodeDlg.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "Jencode.h"
#include "Gb2Utf8.h"
#include "AclTrans.h"
#include "IdxTrans.h"
#include "JencodeDlg.h"
#include "DelBOM.h"
#include "JencodeDlg.h"
#include ".\jencodedlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define WM_USER_TRANS_OVER WM_USER + 100
#define WM_USER_TRANS_OVER2 WM_USER + 101
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3>򡰹<EFBFBD><F2A1B0B9>ڡ<EFBFBD><DAA1>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD> CAboutDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
// ʵ<><CAB5>
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CJencodeDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
CJencodeDlg::CJencodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJencodeDlg::IDD, pParent)
, m_sIdxPath(_T(""))
, m_fsPath(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CJencodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CJencodeDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_GB2UTF, OnBnClickedButtonGb2utf)
ON_BN_CLICKED(IDC_BUTTON_UTF2GB, OnBnClickedButtonUtf2gb)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
ON_MESSAGE(WM_USER_TRANS_OVER, OnTransOver)
ON_MESSAGE(WM_USER_TRANS_OVER2, OnTransOver2)
ON_BN_CLICKED(IDC_ACL_TRANS, OnBnClickedAclTrans)
ON_BN_CLICKED(IDC_ACL_RESTORE, OnBnClickedAclRestore)
ON_BN_CLICKED(IDC_IDX_SELECT, OnBnClickedIdxSelect)
ON_BN_CLICKED(IDC_TRANS_IDX, OnBnClickedTransIdx)
ON_BN_CLICKED(IDC_DEL_BOM, OnBnClickedDelBom)
END_MESSAGE_MAP()
// CJencodeDlg <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL CJencodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// <20><>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\<5C><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ϵͳ<CFB5>˵<EFBFBD><CBB5>С<EFBFBD>
// IDM_ABOUTBOX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>Χ<EEB7B6>ڡ<EFBFBD>
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);
}
}
// <20><><EFBFBD>ô˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ǶԻ<C7B6><D4BB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>Զ<EFBFBD>
// ִ<>д˲<D0B4><CBB2><EFBFBD>
SetIcon(m_hIcon, TRUE); // <20><><EFBFBD>ô<EFBFBD>ͼ<EFBFBD><CDBC>
SetIcon(m_hIcon, FALSE); // <20><><EFBFBD><EFBFBD>Сͼ<D0A1><CDBC>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
acl_msg_open("jencode.log", "jencode");
// <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>
int aWidths[2] = {50, -1};
m_wndStatus.Create(WS_CHILD | WS_VISIBLE | WS_BORDER
| CCS_BOTTOM | SBARS_SIZEGRIP,
CRect(0,0,0,0), this, 0);
m_wndStatus.SetParts(2, aWidths);
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_wndStatus.SetText("", 1, 0);
return TRUE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ؼ<CBBF><D8BC>Ľ<EFBFBD><C4BD><EFBFBD><E3A3AC><EFBFBD>򷵻<EFBFBD> TRUE
}
void CJencodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ĵ<EFBFBD>/<2F><>ͼģ<CDBC>͵<EFBFBD> MFC Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
// <20><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ɡ<EFBFBD>
void CJencodeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // <20><><EFBFBD>ڻ<EFBFBD><DABB>Ƶ<EFBFBD><C6B5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// ʹͼ<CAB9><CDBC><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>
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;
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//<2F><><EFBFBD>û<EFBFBD><C3BB>϶<EFBFBD><CFB6><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱϵͳ<CFB5><CDB3><EFBFBD>ô˺<C3B4><CBBA><EFBFBD>ȡ<EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
HCURSOR CJencodeDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CJencodeDlg::ButtonsEnable(void)
{
GetDlgItem(IDC_BUTTON_GB2UTF)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_UTF2GB)->EnableWindow(TRUE);
GetDlgItem(IDC_ACL_TRANS)->EnableWindow(TRUE);
GetDlgItem(IDC_ACL_RESTORE)->EnableWindow(TRUE);
GetDlgItem(IDC_DEL_BOM)->EnableWindow(TRUE);
}
BOOL CJencodeDlg::CheckPath(void)
{
UpdateData(TRUE);
GetDlgItem(IDC_EDIT_SPATH)->GetWindowText(m_sPath);
//MessageBox(m_sPath);
if (m_sPath.GetLength() == 0)
{
MessageBox("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>ԴĿ¼...");
return FALSE;
}
m_dPath = m_sPath;
//GetDlgItem(IDC_EDIT_DPATH)->GetWindowText(m_dPath);
//if (m_dPath.GetLength() == 0)
//{
// MessageBox("<22><>ѡ<EFBFBD><D1A1>Ŀ<EFBFBD><C4BF>Ŀ¼...");
// return FALSE;
//}
return TRUE;
}
void CJencodeDlg::ButtonsDisable(void)
{
GetDlgItem(IDC_BUTTON_GB2UTF)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_UTF2GB)->EnableWindow(FALSE);
GetDlgItem(IDC_ACL_TRANS)->EnableWindow(FALSE);
GetDlgItem(IDC_ACL_RESTORE)->EnableWindow(FALSE);
GetDlgItem(IDC_DEL_BOM)->EnableWindow(FALSE);
}
void CJencodeDlg::OnBnClickedButtonGb2utf()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!CheckPath())
return;
static CGb2Utf8 gb2Utf8("gbk", "utf-8");
gb2Utf8.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2Utf8.OnTransEnd(WM_USER_TRANS_OVER);
gb2Utf8.Run();
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonUtf2gb()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!CheckPath())
{
MessageBox(m_sPath);
return;
}
static CGb2Utf8 utf2gb("utf-8", "gbk");
utf2gb.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
utf2gb.OnTransEnd(WM_USER_TRANS_OVER);
utf2gb.Run();
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButton2()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString sPath;
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = name;
bi.lpszTitle = "Select folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl, sPath.GetBuffer(MAX_PATH));
sPath.ReleaseBuffer();
if (sPath.Right(1) != "\\")
{
sPath += "\\";
}
GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(sPath);
// CFileDialog file(TRUE,"<22>ļ<EFBFBD>","result.txt",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
// if(file.DoModal()==IDOK)
// {
// CString pathname;
//
// pathname=file.GetPathName();
// GetDlgItem(IDC_EDIT_SPATH)->SetWindowText(pathname);
// }
}
void CJencodeDlg::OnBnClickedButton3()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString sPath;
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = name;
bi.lpszTitle = "Select folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl, sPath.GetBuffer(MAX_PATH));
sPath.ReleaseBuffer();
if (sPath.Right(1) != "\\")
{
sPath += "\\";
}
GetDlgItem(IDC_EDIT_DPATH)->SetWindowText(sPath);
}
afx_msg LRESULT CJencodeDlg::OnTransOver(WPARAM uID, LPARAM lEvent)
{
CString msg;
ButtonsEnable();
msg.Format("<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>%d <20><>", time(NULL) - m_nBegin);
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_wndStatus.SetText(msg, 1, 0);
return (0);
}
afx_msg LRESULT CJencodeDlg::OnTransOver2(WPARAM uID, LPARAM lEvent)
{
CString msg;
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(TRUE);
msg.Format("<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>%d <20><>", time(NULL) - m_nBegin);
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", 0, 0);
m_wndStatus.SetText(msg, 1, 0);
return (0);
}
void CJencodeDlg::OnBnClickedAclTrans()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!CheckPath())
return;
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run();
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAclRestore()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!CheckPath())
return;
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run(FALSE);
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedDelBom()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!CheckPath())
return;
static CDelBOM delBom;
delBom.Init(this->GetSafeHwnd(), m_sPath);
delBom.OnDeleted(WM_USER_TRANS_OVER);
delBom.Run();
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedIdxSelect()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CFileDialog file(TRUE,"<EFBFBD>ļ<EFBFBD>","search.idx",OFN_HIDEREADONLY,"FILE(*.*)|*.*||",NULL);
if(file.DoModal()==IDOK)
{
CString pathname;
pathname=file.GetPathName();
GetDlgItem(IDC_IDX_PATH)->SetWindowText(pathname);
}
}
void CJencodeDlg::OnBnClickedTransIdx()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static CIdxTrans idxTrans;
UpdateData(TRUE);
GetDlgItem(IDC_IDX_PATH)->GetWindowText(m_fsPath);
if (m_fsPath.GetLength() == 0)
{
MessageBox("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>...");
return;
}
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(FALSE);
idxTrans.Init(this->GetSafeHwnd(), m_fsPath);
idxTrans.OnTransEnd(WM_USER_TRANS_OVER2);
idxTrans.Run();
m_wndStatus.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_nBegin = time(NULL);
}