-
Notifications
You must be signed in to change notification settings - Fork 939
/
Copy pathJencodeDlg.cpp
454 lines (372 loc) · 10.9 KB
/
JencodeDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
// JencodeDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "Jencode.h"
#include "Gb2Utf8.h"
#include "AclTrans.h"
#include "IdxTrans.h"
#include "JencodeDlg.h"
#include "DelBOM.h"
#include "AddBOM.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
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
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 对话框
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)
ON_BN_CLICKED(IDC_BUTTON_GB2UNI, &CJencodeDlg::OnBnClickedButtonGb2uni)
ON_BN_CLICKED(IDC_ADD_BOM, &CJencodeDlg::OnBnClickedAddBom)
END_MESSAGE_MAP()
// CJencodeDlg 消息处理程序
BOOL CJencodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将\“关于...\”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
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);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
acl::log::open("jencode.log", "jencode");
logger("started!");
//freopen("CONOUT$","w+t",stdout);
// 添加状态栏
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("就绪", 0, 0);
m_wndStatus.SetText("", 1, 0);
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
void CJencodeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
CAboutDlg dlgAbout;
dlgAbout.DoModal();
} else {
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CJencodeDlg::OnPaint()
{
if (IsIconic()) {
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
} else {
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
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);
GetDlgItem(IDC_ADD_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("请选择源目录...");
return FALSE;
}
m_dPath = m_sPath;
//GetDlgItem(IDC_EDIT_DPATH)->GetWindowText(m_dPath);
//if (m_dPath.GetLength() == 0)
//{
// MessageBox("请选择目的目录...");
// 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);
GetDlgItem(IDC_ADD_BOM)->EnableWindow(FALSE);
}
void CJencodeDlg::OnBnClickedButtonGb2utf()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
return;
}
static CGb2Utf8 gb2Utf8("gbk", "UTF-8");
gb2Utf8.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2Utf8.OnTransEnd(WM_USER_TRANS_OVER);
gb2Utf8.start();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonUtf2gb()
{
// TODO: 在此添加控件通知处理程序代码
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.start();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButtonGb2uni()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
MessageBox(m_sPath);
return;
}
return;
static CGb2Utf8 gb2uni("gbk", "UCS2LE");
gb2uni.Init(this->GetSafeHwnd(), m_sPath, m_dPath);
gb2uni.OnTransEnd(WM_USER_TRANS_OVER);
gb2uni.start();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
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,"文件","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: 在此添加控件通知处理程序代码
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("耗时:%d 秒", time(NULL) - m_nBegin);
m_wndStatus.SetText("完成", 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("耗时:%d 秒", time(NULL) - m_nBegin);
m_wndStatus.SetText("完成!", 0, 0);
m_wndStatus.SetText(msg, 1, 0);
return 0;
}
void CJencodeDlg::OnBnClickedAclTrans()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
return;
}
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAclRestore()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
return;
}
static CAclTrans aclTrans;
aclTrans.Init(this->GetSafeHwnd(), m_sPath);
aclTrans.OnTransEnd(WM_USER_TRANS_OVER);
aclTrans.Run(FALSE);
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedDelBom()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
return;
}
static CDelBOM delBom;
delBom.Init(this->GetSafeHwnd(), m_sPath);
delBom.OnDeleted(WM_USER_TRANS_OVER);
delBom.start();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedAddBom()
{
// TODO: 在此添加控件通知处理程序代码
if (!CheckPath()) {
return;
}
static CAddBOM addBom;
addBom.Init(this->GetSafeHwnd(), m_sPath);
addBom.OnAdded(WM_USER_TRANS_OVER);
addBom.start();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
ButtonsDisable();
}
void CJencodeDlg::OnBnClickedIdxSelect()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog file(TRUE,"文件","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: 在此添加控件通知处理程序代码
static CIdxTrans idxTrans;
UpdateData(TRUE);
GetDlgItem(IDC_IDX_PATH)->GetWindowText(m_fsPath);
if (m_fsPath.GetLength() == 0) {
MessageBox("请选择索引文件...");
return;
}
GetDlgItem(IDC_TRANS_IDX)->EnableWindow(FALSE);
idxTrans.Init(this->GetSafeHwnd(), m_fsPath);
idxTrans.OnTransEnd(WM_USER_TRANS_OVER2);
idxTrans.Run();
m_wndStatus.SetText("运行", 0, 0);
m_nBegin = time(NULL);
}