1 // LyricBatchDownloadDlg.cpp : 实现文件
2 //
3
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "LyricBatchDownloadDlg.h"
7 #include "SongDataManager.h"
8 #include "COSUPlayerHelper.h"
9 #include "IniHelper.h"
10
11
12 // CLyricBatchDownloadDlg 对话框
13
IMPLEMENT_DYNAMIC(CLyricBatchDownloadDlg,CBaseDialog)14 IMPLEMENT_DYNAMIC(CLyricBatchDownloadDlg, CBaseDialog)
15
16 CLyricBatchDownloadDlg::CLyricBatchDownloadDlg(CWnd* pParent /*=NULL*/)
17 : CBaseDialog(IDD_LYRIC_BATCH_DOWN_DIALOG, pParent)
18 {
19
20 }
21
~CLyricBatchDownloadDlg()22 CLyricBatchDownloadDlg::~CLyricBatchDownloadDlg()
23 {
24 }
25
GetDialogName() const26 CString CLyricBatchDownloadDlg::GetDialogName() const
27 {
28 return _T("LyricBatchDownloadDlg");
29 }
30
InitializeControls()31 bool CLyricBatchDownloadDlg::InitializeControls()
32 {
33 wstring temp;
34 temp = theApp.m_str_table.LoadText(L"TITLE_LYRIC_BDL");
35 SetWindowTextW(temp.c_str());
36 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_DL_OPT");
37 SetDlgItemTextW(IDC_TXT_LYRIC_BDL_DL_OPT_STATIC, temp.c_str());
38 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SKIP_ALREADY");
39 SetDlgItemTextW(IDC_SKIP_EXIST_CHECK, temp.c_str());
40 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SAVE_ENCODE_SEL");
41 SetDlgItemTextW(IDC_TXT_LYRIC_BDL_SAVE_ENCODE_SEL_STATIC, temp.c_str());
42 // IDC_COMBO1
43 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_WITH_TRANSLATION");
44 SetDlgItemTextW(IDC_DOWNLOAD_TRASNLATE_CHECK2, temp.c_str());
45 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SAVE_DIR_SEL");
46 SetDlgItemTextW(IDC_TXT_LYRIC_BDL_SAVE_DIR_SEL_STATIC, temp.c_str());
47 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SAVE_DIR_LYRIC");
48 SetDlgItemTextW(IDC_SAVE_TO_LYRIC_FOLDER, temp.c_str());
49 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SAVE_DIR_SONG");
50 SetDlgItemTextW(IDC_SAVE_TO_SONG_FOLDER, temp.c_str());
51 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_SONG_LIST");
52 SetDlgItemTextW(IDC_TXT_LYRIC_BDL_SONG_LIST_STATIC, temp.c_str());
53 // IDC_SONG_LIST1
54 temp = L"";
55 SetDlgItemTextW(IDC_PROGRESS_BAR, temp.c_str());
56 SetDlgItemTextW(IDC_INFO_STATIC, temp.c_str());
57 temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_DL_START");
58 SetDlgItemTextW(IDC_START_DOWNLOAD, temp.c_str());
59 // IDCANCEL
60
61 RepositionTextBasedControls({
62 { CtrlTextInfo::L1, IDC_PROGRESS_BAR },
63 { CtrlTextInfo::C0, IDC_INFO_STATIC },
64 { CtrlTextInfo::R1, IDC_START_DOWNLOAD, CtrlTextInfo::W32 },
65 { CtrlTextInfo::R2, IDCANCEL, CtrlTextInfo::W32 }
66 });
67 return true;
68 }
69
SaveConfig() const70 void CLyricBatchDownloadDlg::SaveConfig() const
71 {
72 CIniHelper ini(theApp.m_config_path);
73 ini.WriteInt(L"lyric_batch_download", L"save_as_utf8", static_cast<int>(m_save_code));
74 ini.WriteBool(L"lyric_batch_download", L"download_translate", m_download_translate);
75 ini.WriteBool(L"lyric_batch_download", L"save_to_song_folder", m_save_to_song_folder);
76 ini.Save();
77 }
78
LoadConfig()79 void CLyricBatchDownloadDlg::LoadConfig()
80 {
81 CIniHelper ini(theApp.m_config_path);
82 m_save_code = static_cast<CodeType>(ini.GetInt(L"lyric_batch_download", L"save_as_utf8", 1));
83 m_download_translate = ini.GetBool(L"lyric_batch_download", L"download_translate", true);
84 m_save_to_song_folder = ini.GetBool(L"lyric_batch_download", L"save_to_song_folder", true);
85 }
86
EnableControls(bool enable)87 void CLyricBatchDownloadDlg::EnableControls(bool enable)
88 {
89 m_skip_exist_check.EnableWindow(enable);
90 m_save_code_combo.EnableWindow(enable);
91 m_download_translate_chk.EnableWindow(enable);
92 GetDlgItem(IDC_SAVE_TO_SONG_FOLDER)->EnableWindow(enable);
93 if (m_lyric_path_not_exit)
94 GetDlgItem(IDC_SAVE_TO_LYRIC_FOLDER)->EnableWindow(FALSE);
95 else
96 GetDlgItem(IDC_SAVE_TO_LYRIC_FOLDER)->EnableWindow(enable);
97 GetDlgItem(IDC_START_DOWNLOAD)->EnableWindow(enable);
98 }
99
SaveLyric(const wchar_t * path,const wstring & lyric_wcs,CodeType code_type,bool * char_cannot_convert)100 bool CLyricBatchDownloadDlg::SaveLyric(const wchar_t* path, const wstring& lyric_wcs, CodeType code_type, bool* char_cannot_convert)
101 {
102 string lyric_str = CCommon::UnicodeToStr(lyric_wcs, code_type, char_cannot_convert);
103 ofstream out_put{ path, std::ios::binary };
104 if (out_put.fail())
105 return false;
106 out_put << lyric_str;
107 return true;
108 }
109
DoDataExchange(CDataExchange * pDX)110 void CLyricBatchDownloadDlg::DoDataExchange(CDataExchange* pDX)
111 {
112 CBaseDialog::DoDataExchange(pDX);
113 DDX_Control(pDX, IDC_SKIP_EXIST_CHECK, m_skip_exist_check);
114 DDX_Control(pDX, IDC_COMBO1, m_save_code_combo);
115 DDX_Control(pDX, IDC_SONG_LIST1, m_song_list_ctrl);
116 DDX_Control(pDX, IDC_DOWNLOAD_TRASNLATE_CHECK2, m_download_translate_chk);
117 DDX_Control(pDX, IDC_INFO_STATIC, m_info_static);
118 DDX_Control(pDX, IDC_PROGRESS_BAR, m_progress_bar);
119 }
120
121
BEGIN_MESSAGE_MAP(CLyricBatchDownloadDlg,CBaseDialog)122 BEGIN_MESSAGE_MAP(CLyricBatchDownloadDlg, CBaseDialog)
123 ON_BN_CLICKED(IDC_START_DOWNLOAD, &CLyricBatchDownloadDlg::OnBnClickedStartDownload)
124 ON_BN_CLICKED(IDC_SKIP_EXIST_CHECK, &CLyricBatchDownloadDlg::OnBnClickedSkipExistCheck)
125 ON_WM_DESTROY()
126 ON_CBN_SELCHANGE(IDC_COMBO1, &CLyricBatchDownloadDlg::OnCbnSelchangeCombo1)
127 ON_BN_CLICKED(IDC_DOWNLOAD_TRASNLATE_CHECK2, &CLyricBatchDownloadDlg::OnBnClickedDownloadTrasnlateCheck2)
128 ON_MESSAGE(WM_BATCH_DOWNLOAD_COMPLATE, &CLyricBatchDownloadDlg::OnBatchDownloadComplate)
129 ON_WM_CLOSE()
130 ON_BN_CLICKED(IDC_SAVE_TO_SONG_FOLDER, &CLyricBatchDownloadDlg::OnBnClickedSaveToSongFolder)
131 ON_BN_CLICKED(IDC_SAVE_TO_LYRIC_FOLDER, &CLyricBatchDownloadDlg::OnBnClickedSaveToLyricFolder)
132 END_MESSAGE_MAP()
133
134
135 // CLyricBatchDownloadDlg 消息处理程序
136
137
138 BOOL CLyricBatchDownloadDlg::OnInitDialog()
139 {
140 CBaseDialog::OnInitDialog();
141
142 // TODO: 在此添加额外的初始化
143 SetIcon(IconMgr::IconType::IT_Download_Batch, FALSE);
144 SetIcon(IconMgr::IconType::IT_Download_Batch, TRUE);
145 SetButtonIcon(IDC_START_DOWNLOAD, IconMgr::IconType::IT_Download_Batch);
146
147 CenterWindow();
148
149 LoadConfig();
150
151 //设置列表控件主题颜色
152 //m_song_list_ctrl.SetColor(theApp.m_app_setting_data.theme_color);
153
154 //初始化控件的状态
155 m_skip_exist_check.SetCheck(m_skip_exist);
156 m_save_code_combo.AddString(_T("ANSI"));
157 m_save_code_combo.AddString(_T("UTF-8"));
158 m_save_code_combo.SetCurSel(static_cast<int>(m_save_code));
159 m_download_translate_chk.SetCheck(m_download_translate);
160 if (m_save_to_song_folder)
161 ((CButton*)GetDlgItem(IDC_SAVE_TO_SONG_FOLDER))->SetCheck(TRUE);
162 else
163 ((CButton*)GetDlgItem(IDC_SAVE_TO_LYRIC_FOLDER))->SetCheck(TRUE);
164 //判断歌词文件夹是否存在
165 bool lyric_path_exist = CCommon::FolderExist(theApp.m_lyric_setting_data.lyric_path);
166 if (!lyric_path_exist) //如果歌词文件不存在,则禁用“保存到歌词文件夹”单选按钮,并强制选中“保存到歌曲所在目录”
167 {
168 ((CButton*)GetDlgItem(IDC_SAVE_TO_LYRIC_FOLDER))->EnableWindow(FALSE);
169 ((CButton*)GetDlgItem(IDC_SAVE_TO_LYRIC_FOLDER))->SetCheck(FALSE);
170 ((CButton*)GetDlgItem(IDC_SAVE_TO_SONG_FOLDER))->SetCheck(TRUE);
171 m_save_to_song_folder = true;
172 m_lyric_path_not_exit = true;
173 }
174
175 //初始化歌曲列表控件
176 //设置各列的宽度
177 CRect rect;
178 m_song_list_ctrl.GetWindowRect(rect);
179 int width0, width1, width2, width3, width4;
180 width0 = rect.Width() / 10;
181 width1 = rect.Width() * 2 / 10;
182 width2 = rect.Width() * 2 / 10;
183 width3 = rect.Width() * 3 / 10;
184 width4 = rect.Width() - width0 - width1 - width2 - width3 - theApp.DPI(20) - 1;
185 //插入列
186 m_song_list_ctrl.SetExtendedStyle(m_song_list_ctrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP);
187 m_song_list_ctrl.InsertColumn(0, theApp.m_str_table.LoadText(L"TXT_SERIAL_NUMBER").c_str(), LVCFMT_LEFT, width0); //插入第1列
188 m_song_list_ctrl.InsertColumn(1, theApp.m_str_table.LoadText(L"TXT_TITLE").c_str(), LVCFMT_LEFT, width1); //插入第2列
189 m_song_list_ctrl.InsertColumn(2, theApp.m_str_table.LoadText(L"TXT_ARTIST").c_str(), LVCFMT_LEFT, width2); //插入第3列
190 m_song_list_ctrl.InsertColumn(3, theApp.m_str_table.LoadText(L"TXT_FILE_NAME").c_str(), LVCFMT_LEFT, width3); //插入第3列
191 m_song_list_ctrl.InsertColumn(4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS").c_str(), LVCFMT_LEFT, width4); //插入第4列
192 //插入项目
193 for (size_t i{}; i < m_playlist.size(); i++)
194 {
195 CString tmp;
196 tmp.Format(_T("%d"), i + 1);
197 m_song_list_ctrl.InsertItem(i, tmp);
198 m_song_list_ctrl.SetItemText(i, 1, m_playlist[i].GetTitle().c_str());
199 m_song_list_ctrl.SetItemText(i, 2, m_playlist[i].GetArtist().c_str());
200 m_song_list_ctrl.SetItemText(i, 3, m_playlist[i].GetFileName().c_str());
201 }
202
203 m_progress_bar.SetBackgroundColor(GetSysColor(COLOR_BTNFACE));
204 m_progress_bar.ShowWindow(SW_HIDE);
205
206 return TRUE; // return TRUE unless you set the focus to a control
207 // 异常: OCX 属性页应返回 FALSE
208 }
209
210
OnBnClickedStartDownload()211 void CLyricBatchDownloadDlg::OnBnClickedStartDownload()
212 {
213 // TODO: 在此添加控件通知处理程序代码
214 m_progress_bar.ShowWindow(SW_SHOW);
215
216 //先清除“状态”一列的内容
217 for (size_t i{}; i < m_playlist.size(); i++)
218 {
219 m_song_list_ctrl.SetItemText(i, 4, _T(""));
220 }
221
222 EnableControls(false); //禁用控件
223
224 //设置要向歌词下载工作线程传递的数据
225 m_thread_info.hwnd = GetSafeHwnd();
226 m_thread_info.download_translate = m_download_translate;
227 m_thread_info.save_to_song_folder = m_save_to_song_folder;
228 m_thread_info.skip_exist = m_skip_exist;
229 m_thread_info.save_code = m_save_code;
230 m_thread_info.list_ctrl = &m_song_list_ctrl;
231 m_thread_info.static_ctrl = &m_info_static;
232 m_thread_info.progress_bar = &m_progress_bar;
233 m_thread_info.playlist = &m_playlist;
234 theApp.m_batch_download_dialog_exit = false;
235
236 //创建歌词批量下载的工作线程
237 m_pThread = AfxBeginThread(ThreadFunc, &m_thread_info);
238 }
239
240
OnBnClickedSkipExistCheck()241 void CLyricBatchDownloadDlg::OnBnClickedSkipExistCheck()
242 {
243 // TODO: 在此添加控件通知处理程序代码
244 m_skip_exist = (m_skip_exist_check.GetCheck() != 0);
245 }
246
247
OnDestroy()248 void CLyricBatchDownloadDlg::OnDestroy()
249 {
250 CBaseDialog::OnDestroy();
251
252 // TODO: 在此处添加消息处理程序代码
253 SaveConfig();
254
255 }
256
257
OnCbnSelchangeCombo1()258 void CLyricBatchDownloadDlg::OnCbnSelchangeCombo1()
259 {
260 // TODO: 在此添加控件通知处理程序代码
261 //获取组合框中选中的编码格式
262 switch (m_save_code_combo.GetCurSel())
263 {
264 case 1: m_save_code = CodeType::UTF8; break;
265 default: m_save_code = CodeType::ANSI; break;
266 }
267 }
268
269
OnBnClickedDownloadTrasnlateCheck2()270 void CLyricBatchDownloadDlg::OnBnClickedDownloadTrasnlateCheck2()
271 {
272 // TODO: 在此添加控件通知处理程序代码
273 m_download_translate = (m_download_translate_chk.GetCheck() != 0);
274 }
275
276 //工作线程函数
ThreadFunc(LPVOID lpParam)277 UINT CLyricBatchDownloadDlg::ThreadFunc(LPVOID lpParam)
278 {
279 CCommon::SetThreadLanguageList(theApp.m_str_table.GetLanguageTag());
280 ThreadInfo* pInfo = (ThreadInfo*)lpParam;
281
282 //依次下载列表中每一首歌曲的歌词
283 for (size_t i{}; i < pInfo->playlist->size(); i++)
284 {
285 if (theApp.m_batch_download_dialog_exit)
286 return 0;
287 int percent = i * 100 / pInfo->playlist->size();
288 wstring info = theApp.m_str_table.LoadTextFormat(L"TXT_LYRIC_BDL_INFO_DOWNLOADING_INFO", { percent });
289 pInfo->static_ctrl->SetWindowText(info.c_str());
290 pInfo->progress_bar->SetProgress(percent);
291
292 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_DOWNLOADING").c_str());
293 pInfo->list_ctrl->EnsureVisible(i, FALSE);
294
295 //设置要保存的歌词的路径
296 wstring lyric_path;
297 wstring file_name;
298 wstring dir;
299 dir = CFilePathHelper(pInfo->playlist->at(i).file_path).GetDir();
300 if (!pInfo->playlist->at(i).is_cue && !COSUPlayerHelper::IsOsuFile(pInfo->playlist->at(i).file_path))
301 file_name = pInfo->playlist->at(i).GetFileName();
302 else
303 {
304 file_name = pInfo->playlist->at(i).artist + L" - " + pInfo->playlist->at(i).title + L".lrc";
305 CCommon::FileNameNormalize(file_name);
306 }
307 if (pInfo->save_to_song_folder)
308 lyric_path = dir + file_name;
309 else
310 lyric_path = theApp.m_lyric_setting_data.lyric_path + file_name;
311 size_t index = lyric_path.rfind(L'.'); //查找文件名最后一个点
312 lyric_path = lyric_path.substr(0, index + 1) + L"lrc"; //将文件名的扩展名改为lrc
313
314 //判断歌词是否已经存在
315 bool lyric_exist = CCommon::FileExist(lyric_path) || (!pInfo->playlist->at(i).lyric_file.empty());
316 if (pInfo->skip_exist && lyric_exist) //如果设置了跳过已存在歌词的曲目,并且歌词已经存在,则跳过它
317 {
318 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_SKIPPED").c_str());
319 continue;
320 }
321
322 //设置搜索关键字
323 wstring search_result; //查找歌曲返回的结果
324 wstring lyric_str; //下载好的歌词
325 wstring keyword; //查找的关键字
326 if (pInfo->playlist->at(i).IsTitleEmpty()) //如果没有标题信息,就把文件名设为搜索关键字
327 {
328 keyword = pInfo->playlist->at(i).GetFileName();
329 size_t index = keyword.rfind(L'.'); //查找最后一个点
330 keyword = keyword.substr(0, index); //去掉扩展名
331 }
332 else if (pInfo->playlist->at(i).IsArtistEmpty()) //如果有标题信息但是没有艺术家信息,就把标题设为搜索关键字
333 {
334 keyword = pInfo->playlist->at(i).title;
335 }
336 else //否则将“艺术家 标题”设为搜索关键字
337 {
338 keyword = pInfo->playlist->at(i).artist + L' ' + pInfo->playlist->at(i).title;
339 }
340
341 //搜索歌曲
342 wstring keyword_url = CInternetCommon::URLEncode(keyword); //将搜索关键字转换成URL编码
343 CString url;
344 url.Format(L"http://music.163.com/api/search/get/?s=%s&limit=20&type=1&offset=0", keyword_url.c_str());
345 int rtn = CInternetCommon::HttpPost(wstring(url), search_result); //向网易云音乐的歌曲搜索API发送http的POST请求
346 if (theApp.m_batch_download_dialog_exit) //由于CLyricDownloadCommon::HttpPost函数执行的时间比较长,所有在这里执行判断是否退出线程的处理
347 return 0;
348 if (rtn != 0)
349 {
350 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_NETWORK_FAILED").c_str());
351 continue;
352 }
353
354 //处理返回结果
355 SongInfo song_info_ori{ CSongDataManager::GetInstance().GetSongInfo3(pInfo->playlist->at(i)) };
356 vector<CInternetCommon::ItemInfo> down_list;
357 CInternetCommon::DisposeSearchResult(down_list, search_result); //处理返回的查找结果,并将结果保存在down_list容器里
358 if (down_list.empty())
359 {
360 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_CANNOT_FIND_THIS_SONG").c_str());
361 song_info_ori.SetNoOnlineLyric(true);
362 CSongDataManager::GetInstance().AddItem(song_info_ori);
363 continue;
364 }
365
366 //计算最佳选择项
367 wstring title = pInfo->playlist->at(i).title;
368 wstring artist = pInfo->playlist->at(i).artist;
369 wstring album = pInfo->playlist->at(i).album;
370 if (theApp.m_str_table.LoadText(L"TXT_EMPTY_TITLE") == title) title.clear();
371 if (theApp.m_str_table.LoadText(L"TXT_EMPTY_ARTIST") == artist) artist.clear();
372 if (theApp.m_str_table.LoadText(L"TXT_EMPTY_ALBUM") == album) album.clear();
373 int best_matched = CInternetCommon::SelectMatchedItem(down_list, title, artist, album, pInfo->playlist->at(i).GetFileName(), true);
374 if (best_matched < 0)
375 {
376 song_info_ori.SetNoOnlineLyric(true);
377 CSongDataManager::GetInstance().AddItem(song_info_ori);
378 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_NO_MATCHED_LYRIC").c_str());
379 continue;
380 }
381
382 //下载歌词
383 CLyricDownloadCommon::DownloadLyric(down_list[best_matched].id, lyric_str, pInfo->download_translate);
384 if (lyric_str.empty())
385 {
386 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_DOWNLOAD_FAILED").c_str());
387 continue;
388 }
389
390 //处理歌词文本
391 if (!CLyricDownloadCommon::DisposeLryic(lyric_str))
392 {
393 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_SONG_NO_LYRIC").c_str());
394 continue;
395 }
396
397 song_info_ori.SetSongId(down_list[best_matched].id);
398 CSongDataManager::GetInstance().AddItem(song_info_ori);
399
400 //在歌词前面添加标签
401 CLyricDownloadCommon::AddLyricTag(lyric_str, down_list[best_matched].id, down_list[best_matched].title, down_list[best_matched].artist, down_list[best_matched].album);
402
403 //保存歌词
404 bool char_cannot_convert;
405 if (CLyricBatchDownloadDlg::SaveLyric(lyric_path.c_str(), lyric_str, pInfo->save_code, &char_cannot_convert))
406 {
407 if (char_cannot_convert)
408 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_ENCODE_WARNING").c_str()); //char_cannot_convert为true,则说明有无法转换的Unicode字符
409 else
410 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_SUCCEEDED").c_str());
411 }
412 else
413 {
414 pInfo->list_ctrl->SetItemText(i, 4, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_STATUS_SUCCEEDED").c_str());
415 }
416
417 if (pInfo->download_translate)
418 {
419 CLyrics lyrics{ lyric_path, CLyrics::LyricType::LY_LRC_NETEASE }; //打开保存过的歌词
420 lyrics.SaveLyric2(theApp.m_general_setting_data.download_lyric_text_and_translation_in_same_line);
421 }
422
423 }
424 ::PostMessage(pInfo->hwnd, WM_BATCH_DOWNLOAD_COMPLATE, 0, 0);
425 return 0;
426 }
427
428
OnBatchDownloadComplate(WPARAM wParam,LPARAM lParam)429 afx_msg LRESULT CLyricBatchDownloadDlg::OnBatchDownloadComplate(WPARAM wParam, LPARAM lParam)
430 {
431 SetDlgItemText(IDC_INFO_STATIC, theApp.m_str_table.LoadText(L"TXT_LYRIC_BDL_INFO_COMPLETE").c_str());
432 //下载完成后重新载入歌词
433 CPlayer::GetInstance().SearchLyrics(true);
434 CPlayer::GetInstance().IniLyrics();
435 EnableControls(true); //启用控件
436 m_progress_bar.SetProgress(100);
437 return 0;
438 }
439
440
OnClose()441 void CLyricBatchDownloadDlg::OnClose()
442 {
443 // TODO: 在此添加消息处理程序代码和/或调用默认值
444
445 CBaseDialog::OnClose();
446 }
447
448
OnCancel()449 void CLyricBatchDownloadDlg::OnCancel()
450 {
451 // TODO: 在此添加专用代码和/或调用基类
452 //对话框将要关闭时,将退出标志置为true
453 theApp.m_batch_download_dialog_exit = true;
454 if (m_pThread != nullptr)
455 {
456 int rtn = WaitForSingleObject(m_pThread->m_hThread, 2000); //等待线程退出
457 // std::wstringstream wss;
458 // wss << std::hex << std::uppercase << L"0x" << rtn;
459 // MessageBox(wss.str().c_str(), NULL, MB_ICONINFORMATION);
460
461 }
462 DestroyWindow();
463 //CBaseDialog::OnCancel();
464 }
465
466
OnOK()467 void CLyricBatchDownloadDlg::OnOK()
468 {
469 // TODO: 在此添加专用代码和/或调用基类
470 //对话框将要关闭时,将退出标志置为true
471 theApp.m_batch_download_dialog_exit = true;
472 if (m_pThread != nullptr)
473 WaitForSingleObject(m_pThread->m_hThread, 2000); //等待线程退出
474
475 CBaseDialog::OnOK();
476 }
477
478
OnBnClickedSaveToSongFolder()479 void CLyricBatchDownloadDlg::OnBnClickedSaveToSongFolder()
480 {
481 // TODO: 在此添加控件通知处理程序代码
482 m_save_to_song_folder = true;
483 }
484
485
OnBnClickedSaveToLyricFolder()486 void CLyricBatchDownloadDlg::OnBnClickedSaveToLyricFolder()
487 {
488 // TODO: 在此添加控件通知处理程序代码
489 m_save_to_song_folder = false;
490 }
491