xref: /MusicPlayer2/MusicPlayer2/CoverDownloadDlg.cpp (revision a87de17200448923cd61634f894b94d41827fa4c)
1 // CoverDownloadDlg.cpp: 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "Player.h"
7 #include "CoverDownloadDlg.h"
8 #include "SongDataManager.h"
9 #include "IniHelper.h"
10 
11 
12 // CCoverDownloadDlg 对话框
13 
IMPLEMENT_DYNAMIC(CCoverDownloadDlg,CBaseDialog)14 IMPLEMENT_DYNAMIC(CCoverDownloadDlg, CBaseDialog)
15 
16 CCoverDownloadDlg::CCoverDownloadDlg(CWnd* pParent /*=nullptr*/)
17     : CBaseDialog(IDD_COVER_DOWNLOAD_DIALOG, pParent)
18 {
19 
20 }
21 
~CCoverDownloadDlg()22 CCoverDownloadDlg::~CCoverDownloadDlg()
23 {
24 }
25 
SongSearchThreadFunc(LPVOID lpParam)26 UINT CCoverDownloadDlg::SongSearchThreadFunc(LPVOID lpParam)
27 {
28     CCommon::SetThreadLanguageList(theApp.m_str_table.GetLanguageTag());
29     CCoverDownloadDlg* pThis = (CCoverDownloadDlg*)lpParam;
30     wstring search_result;
31     wstring m_search_url = pThis->m_search_url;
32     bool m_search_rtn = CInternetCommon::HttpPost(m_search_url, search_result);     //向网易云音乐的歌曲搜索API发送http的POST请求
33     if (theApp.m_cover_download_dialog_exit)
34         return 0;
35     pThis->m_search_rtn = m_search_rtn;
36     pThis->m_search_result = search_result;
37     ::PostMessage(pThis->m_hWnd, WM_SEARCH_COMPLATE, 0, 0);		//搜索完成后发送一个搜索完成的消息
38     return 0;
39 }
40 
CoverDownloadThreadFunc(LPVOID lpParam)41 UINT CCoverDownloadDlg::CoverDownloadThreadFunc(LPVOID lpParam)
42 {
43     CCommon::SetThreadLanguageList(theApp.m_str_table.GetLanguageTag());
44     CCoverDownloadDlg* pThis = (CCoverDownloadDlg*)lpParam;
45     CInternetCommon::ItemInfo match_item = pThis->m_down_list[pThis->m_item_selected];
46     wstring song_id = match_item.id;
47     if (song_id.empty())
48         return 0;
49     wstring cover_url = CCoverDownloadCommon::GetAlbumCoverURL(song_id);
50     if (cover_url.empty())
51     {
52         const wstring& info = theApp.m_str_table.LoadText(L"MSG_NETWORK_COVER_DOWNLOAD_FAILED");
53         AfxMessageBox(info.c_str(), MB_ICONWARNING | MB_OK);
54     }
55 
56     //获取要保存的专辑封面的文件路径
57     CFilePathHelper cover_file_path;
58     wstring album_name;
59     if (match_item.album == pThis->m_song.album)        // 如果在线搜索结果的唱片集名称和歌曲的相同,则以“唱片集”为文件名保存
60         album_name = match_item.album;
61     else                                                // 否则以歌曲文件名为文件名保存
62         album_name = pThis->m_song.GetFileName();
63     CCommon::FileNameNormalize(album_name);
64     CFilePathHelper url_path(cover_url);
65     cover_file_path.SetFilePath(pThis->GetSavedDir() + album_name + url_path.GetFileExtension(false, true));
66 
67     //下面专辑封面
68     if (CCommon::FileExist(cover_file_path.GetFilePath()))
69         ::DeleteFile(cover_file_path.GetFilePath().c_str());
70     if (CCommon::FileExist(pThis->m_org_album_cover_path))
71         ::DeleteFile(pThis->m_org_album_cover_path.c_str());
72     URLDownloadToFile(0, cover_url.c_str(), cover_file_path.GetFilePath().c_str(), 0, NULL);
73 
74     //将下载的专辑封面改为隐藏属性
75     if (pThis->m_save_to_song_folder)
76         SetFileAttributes(cover_file_path.GetFilePath().c_str(), FILE_ATTRIBUTE_HIDDEN);
77 
78     ::PostMessage(pThis->m_hWnd, WM_DOWNLOAD_COMPLATE, 0, 0);		//下载完成后发送一个搜索完成的消息
79 
80     return 0;
81 }
82 
SaveConfig() const83 void CCoverDownloadDlg::SaveConfig() const
84 {
85     CIniHelper ini(theApp.m_config_path);
86     ini.WriteBool(L"album_download", L"save_to_song_folder", m_save_to_song_folder);
87     ini.Save();
88 }
89 
LoadConfig()90 void CCoverDownloadDlg::LoadConfig()
91 {
92     CIniHelper ini(theApp.m_config_path);
93     m_save_to_song_folder = ini.GetBool(L"album_download", L"save_to_song_folder", true);
94 }
95 
SetID(wstring id)96 void CCoverDownloadDlg::SetID(wstring id)
97 {
98     SongInfo song_info_ori{ CSongDataManager::GetInstance().GetSongInfo3(m_song) };
99     song_info_ori.SetSongId(id);
100     CSongDataManager::GetInstance().AddItem(song_info_ori);
101 }
102 
GetSavedDir()103 wstring CCoverDownloadDlg::GetSavedDir()
104 {
105     if (m_save_to_song_folder || !CCommon::FolderExist(theApp.m_app_setting_data.album_cover_path))
106         return CFilePathHelper(m_song.file_path).GetDir();
107     else
108         return theApp.m_app_setting_data.album_cover_path;
109 }
110 
GetSongInfo() const111 SongInfo CCoverDownloadDlg::GetSongInfo() const
112 {
113     return CPlayer::GetInstance().GetCurrentSongInfo();
114 }
115 
GetDialogName() const116 CString CCoverDownloadDlg::GetDialogName() const
117 {
118     return _T("CoverDownloadDlg");
119 }
120 
InitializeControls()121 bool CCoverDownloadDlg::InitializeControls()
122 {
123     SetIcon(IconMgr::IconType::IT_Album_Cover, FALSE);
124     wstring temp;
125     temp = theApp.m_str_table.LoadText(L"TITLE_COVER_DL");
126     SetWindowTextW(temp.c_str());
127     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_TITLE");
128     SetDlgItemTextW(IDC_TXT_COVER_DL_TITLE_STATIC, temp.c_str());
129     // IDC_TITLE_EDIT
130     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_SEARCH");
131     SetDlgItemTextW(IDC_SEARCH_BUTTON, temp.c_str());
132     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_ARTIST");
133     SetDlgItemTextW(IDC_TXT_COVER_DL_ARTIST_STATIC, temp.c_str());
134     // IDC_ARTIST_EDIT
135     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_INFO");
136     SetDlgItemTextW(IDC_STATIC_INFO, temp.c_str());
137     temp = L"<a>" + theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_UNLINK") + L"</a>";
138     SetDlgItemTextW(IDC_UNASSOCIATE_LINK, temp.c_str());
139     // IDC_COVER_DOWN_LIST
140     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_OPT");
141     SetDlgItemTextW(IDC_DOWNLOAD_OPTION_GROUPBOX, temp.c_str());
142     temp = theApp.m_str_table.LoadText(L"TXT_COVER_DL_LOCATION_SEL");
143     SetDlgItemTextW(IDC_COVER_LOCATION_STATIC, temp.c_str());
144     temp = theApp.m_str_table.LoadText(L"TXT_COVER_DL_LOCATION_FOLDER_SONG");
145     SetDlgItemTextW(IDC_SAVE_TO_SONG_FOLDER2, temp.c_str());
146     temp = theApp.m_str_table.LoadText(L"TXT_COVER_DL_LOCATION_FOLDER_COVER");
147     SetDlgItemTextW(IDC_SAVE_TO_ALBUM_FOLDER2, temp.c_str());
148     temp = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_SEL_DL");
149     SetDlgItemTextW(IDC_DOWNLOAD_SELECTED, temp.c_str());
150 
151     SetButtonIcon(IDC_SEARCH_BUTTON, IconMgr::IconType::IT_Find);
152     SetButtonIcon(IDC_DOWNLOAD_SELECTED, IconMgr::IconType::IT_Download);
153 
154     RepositionTextBasedControls({
155         { CtrlTextInfo::L1, IDC_TXT_COVER_DL_TITLE_STATIC },
156         { CtrlTextInfo::C0, IDC_TITLE_EDIT },
157         { CtrlTextInfo::R1, IDC_SEARCH_BUTTON, CtrlTextInfo::W32 },
158         { CtrlTextInfo::L1, IDC_TXT_COVER_DL_ARTIST_STATIC },
159         { CtrlTextInfo::C0, IDC_ARTIST_EDIT }
160         }, CtrlTextInfo::W64);
161     RepositionTextBasedControls({
162         { CtrlTextInfo::C0, IDC_STATIC_INFO },
163         { CtrlTextInfo::R1, IDC_UNASSOCIATE_LINK }
164         }, CtrlTextInfo::W128);
165     RepositionTextBasedControls({
166         { CtrlTextInfo::R1, IDC_DOWNLOAD_SELECTED, CtrlTextInfo::W32 },
167         { CtrlTextInfo::R2, IDCANCEL, CtrlTextInfo::W32 }
168         });
169     return true;
170 }
171 
DoDataExchange(CDataExchange * pDX)172 void CCoverDownloadDlg::DoDataExchange(CDataExchange* pDX)
173 {
174     CBaseDialog::DoDataExchange(pDX);
175     DDX_Control(pDX, IDC_COVER_DOWN_LIST, m_down_list_ctrl);
176     DDX_Control(pDX, IDC_UNASSOCIATE_LINK, m_unassciate_lnk);
177 }
178 
ShowDownloadList()179 void CCoverDownloadDlg::ShowDownloadList()
180 {
181     m_down_list_ctrl.DeleteAllItems();
182     for (size_t i{}; i < m_down_list.size(); i++)
183     {
184         CString tmp;
185         tmp.Format(_T("%d"), i + 1);
186         m_down_list_ctrl.InsertItem(i, tmp);
187         m_down_list_ctrl.SetItemText(i, 1, m_down_list[i].title.c_str());
188         m_down_list_ctrl.SetItemText(i, 2, m_down_list[i].artist.c_str());
189         m_down_list_ctrl.SetItemText(i, 3, m_down_list[i].album.c_str());
190     }
191 }
192 
193 
BEGIN_MESSAGE_MAP(CCoverDownloadDlg,CBaseDialog)194 BEGIN_MESSAGE_MAP(CCoverDownloadDlg, CBaseDialog)
195     ON_BN_CLICKED(IDC_SEARCH_BUTTON, &CCoverDownloadDlg::OnBnClickedSearchButton)
196     ON_MESSAGE(WM_SEARCH_COMPLATE, &CCoverDownloadDlg::OnSearchComplate)
197     ON_BN_CLICKED(IDC_DOWNLOAD_SELECTED, &CCoverDownloadDlg::OnBnClickedDownloadSelected)
198     ON_NOTIFY(NM_CLICK, IDC_COVER_DOWN_LIST, &CCoverDownloadDlg::OnNMClickCoverDownList)
199     ON_NOTIFY(NM_DBLCLK, IDC_COVER_DOWN_LIST, &CCoverDownloadDlg::OnNMDblclkCoverDownList)
200     ON_NOTIFY(NM_RCLICK, IDC_COVER_DOWN_LIST, &CCoverDownloadDlg::OnNMRClickCoverDownList)
201     ON_MESSAGE(WM_DOWNLOAD_COMPLATE, &CCoverDownloadDlg::OnDownloadComplate)
202     ON_EN_CHANGE(IDC_TITLE_EDIT, &CCoverDownloadDlg::OnEnChangeTitleEdit)
203     ON_EN_CHANGE(IDC_ARTIST_EDIT, &CCoverDownloadDlg::OnEnChangeArtistEdit)
204     ON_NOTIFY(NM_CLICK, IDC_UNASSOCIATE_LINK, &CCoverDownloadDlg::OnNMClickUnassociateLink)
205     ON_WM_DESTROY()
206     ON_BN_CLICKED(IDC_SAVE_TO_SONG_FOLDER2, &CCoverDownloadDlg::OnBnClickedSaveToSongFolder2)
207     ON_BN_CLICKED(IDC_SAVE_TO_ALBUM_FOLDER2, &CCoverDownloadDlg::OnBnClickedSaveToAlbumFolder2)
208 END_MESSAGE_MAP()
209 
210 
211 // CCoverDownloadDlg 消息处理程序
212 
213 
214 BOOL CCoverDownloadDlg::OnInitDialog()
215 {
216     CBaseDialog::OnInitDialog();
217 
218     // TODO:  在此添加额外的初始化
219     LoadConfig();
220 
221     m_song = GetSongInfo(); // 初始化复制Songinfo使用,防止随着播放GetSongInfo获取到另一首
222     m_org_album_cover_path = CPlayer::GetInstance().GetAlbumCoverPath();
223 
224     m_title = m_song.title;
225     m_artist = m_song.artist;
226     m_album = m_song.album;
227 
228     if (m_song.IsTitleEmpty())    // 如果没有标题信息,就把文件名设为标题
229     {
230         m_title = m_song.GetFileName();
231         size_t index = m_title.rfind(L'.');
232         m_title = m_title.substr(0, index);
233     }
234     if (m_song.IsArtistEmpty())	//没有艺术家信息,清空艺术家的文本
235     {
236         m_artist.clear();
237     }
238     if (m_song.IsAlbumEmpty())	//没有唱片集信息,清空唱片集的文本
239     {
240         m_album.clear();
241     }
242     m_file_name = m_song.GetFileName();
243 
244     SetDlgItemText(IDC_TITLE_EDIT, m_title.c_str());
245     SetDlgItemText(IDC_ARTIST_EDIT, m_artist.c_str());
246 
247     ////设置列表控件主题颜色
248     //m_down_list_ctrl.SetColor(theApp.m_app_setting_data.theme_color);
249 
250     //初始化搜索结果列表控件
251     CRect rect;
252     m_down_list_ctrl.GetWindowRect(rect);
253     int width0, width1, width2, width3;
254     width0 = rect.Width() / 10;
255     width1 = rect.Width() * 3 / 10;
256     width2 = rect.Width() * 2 / 10;
257     width3 = rect.Width() - theApp.DPI(20) - 1 - width0 - width1 - width2;
258 
259     m_down_list_ctrl.SetExtendedStyle(m_down_list_ctrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP);
260     m_down_list_ctrl.InsertColumn(0, theApp.m_str_table.LoadText(L"TXT_SERIAL_NUMBER").c_str(), LVCFMT_LEFT, width0);
261     m_down_list_ctrl.InsertColumn(1, theApp.m_str_table.LoadText(L"TXT_TITLE").c_str(), LVCFMT_LEFT, width1);
262     m_down_list_ctrl.InsertColumn(2, theApp.m_str_table.LoadText(L"TXT_ARTIST").c_str(), LVCFMT_LEFT, width2);
263     m_down_list_ctrl.InsertColumn(3, theApp.m_str_table.LoadText(L"TXT_ALBUM").c_str(), LVCFMT_LEFT, width3);
264 
265     m_unassciate_lnk.ShowWindow(SW_HIDE);
266 
267     if (m_save_to_song_folder)
268         ((CButton*)GetDlgItem(IDC_SAVE_TO_SONG_FOLDER2))->SetCheck(TRUE);
269     else
270         ((CButton*)GetDlgItem(IDC_SAVE_TO_ALBUM_FOLDER2))->SetCheck(TRUE);
271 
272     //判断封面文件夹是否存在
273     bool lyric_path_exist = CCommon::FolderExist(theApp.m_app_setting_data.album_cover_path);
274     if (!lyric_path_exist)		//如果封面文件夹不存在,则禁用“保存到封面文件夹”单选按钮,并强制选中“保存到歌曲所在目录”
275     {
276         ((CButton*)GetDlgItem(IDC_SAVE_TO_ALBUM_FOLDER2))->EnableWindow(FALSE);
277         ((CButton*)GetDlgItem(IDC_SAVE_TO_ALBUM_FOLDER2))->SetCheck(FALSE);
278         ((CButton*)GetDlgItem(IDC_SAVE_TO_SONG_FOLDER2))->SetCheck(TRUE);
279         m_save_to_song_folder = true;
280     }
281 
282     return TRUE;  // return TRUE unless you set the focus to a control
283                   // 异常: OCX 属性页应返回 FALSE
284 }
285 
286 
OnBnClickedSearchButton()287 void CCoverDownloadDlg::OnBnClickedSearchButton()
288 {
289     // TODO: 在此添加控件通知处理程序代码
290     SetDlgItemText(IDC_STATIC_INFO, theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_INFO_SEARCHING").c_str());    // 这里使用的是歌词下载对话框的字符串
291     GetDlgItem(IDC_SEARCH_BUTTON)->EnableWindow(FALSE);		//点击“搜索”后禁用该按钮
292     wstring keyword = CInternetCommon::URLEncode(m_artist + L' ' + m_title);	//搜索关键字为“艺术家 标题”,并将其转换成URL编码
293     CString url;
294     url.Format(L"http://music.163.com/api/search/get/?s=%s&limit=%d&type=1&offset=0", keyword.c_str(), 30);
295     //int rtn = CLyricDownloadCommon::HttpPost(buff, m_search_result);		//向网易云音乐的歌曲搜索API发送http的POST请求
296     m_search_url = url;
297     theApp.m_cover_download_dialog_exit = false;
298     m_pSearchThread = AfxBeginThread(SongSearchThreadFunc, this);
299 }
300 
301 
OnSearchComplate(WPARAM wParam,LPARAM lParam)302 afx_msg LRESULT CCoverDownloadDlg::OnSearchComplate(WPARAM wParam, LPARAM lParam)
303 {
304     //响应WM_SEARCH_CONPLATE消息
305     GetDlgItem(IDC_SEARCH_BUTTON)->EnableWindow(TRUE);	//搜索完成之后启用该按钮
306     switch (m_search_rtn)
307     {
308     case CInternetCommon::FAILURE:
309     {
310         const wstring& info = theApp.m_str_table.LoadText(L"MSG_NETWORK_SEARCH_FAILED");
311         MessageBox(info.c_str(), NULL, MB_ICONWARNING);
312         return 0;
313     }
314     case CInternetCommon::OUTTIME:
315     {
316         const wstring& info = theApp.m_str_table.LoadText(L"MSG_NETWORK_SEARCH_TIME_OUT");
317         MessageBox(info.c_str(), NULL, MB_ICONWARNING);
318         return 0;
319     }
320     default: break;
321     }
322 
323     CInternetCommon::DisposeSearchResult(m_down_list, m_search_result);		//处理返回的结果
324     ShowDownloadList();			//将搜索的结果显示在列表控件中
325 
326     //计算搜索结果中最佳匹配项目
327     int best_matched;
328     bool id_releated{ false };
329     CSongDataManager::GetInstance().GetSongID(m_song, m_song.song_id);  // 从媒体库读取id
330     if (m_song.song_id != 0)        // 如果当前歌曲已经有关联的ID,则根据该ID在搜索结果列表中查找对应的项目
331     {
332         for (size_t i{}; i < m_down_list.size(); i++)
333         {
334             if (m_song.GetSongId() == m_down_list[i].id)
335             {
336                 id_releated = true;
337                 best_matched = i;
338                 break;
339             }
340         }
341     }
342     if (!id_releated)
343         best_matched = CInternetCommon::SelectMatchedItem(m_down_list, m_title, m_artist, m_album, m_file_name, true);
344     wstring info;
345     m_unassciate_lnk.ShowWindow(SW_HIDE);
346     if (m_down_list.empty())
347         info = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_INFO_SEARCH_NO_SONG");
348     else if (best_matched == -1)
349         info = theApp.m_str_table.LoadText(L"TXT_LYRIC_DL_INFO_SEARCH_NO_MATCHED");
350     else if (id_releated)
351     {
352         info = theApp.m_str_table.LoadTextFormat(L"TXT_LYRIC_DL_INFO_SEARCH_RELATED", { best_matched + 1 });
353         m_unassciate_lnk.ShowWindow(SW_SHOW);
354     }
355     else
356         info = theApp.m_str_table.LoadTextFormat(L"TXT_LYRIC_DL_INFO_SEARCH_BEST_MATCHED", { best_matched + 1 });
357     SetDlgItemText(IDC_STATIC_INFO, info.c_str());
358     //自动选中列表中最佳匹配的项目
359     m_down_list_ctrl.SetFocus();
360     m_down_list_ctrl.SetItemState(best_matched, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);	//选中行
361     m_down_list_ctrl.EnsureVisible(best_matched, FALSE);		//使选中行保持可见
362     m_item_selected = best_matched;
363     return 0;
364 }
365 
366 
OnBnClickedDownloadSelected()367 void CCoverDownloadDlg::OnBnClickedDownloadSelected()
368 {
369     // TODO: 在此添加控件通知处理程序代码
370     if (m_item_selected < 0 || m_item_selected >= static_cast<int>(m_down_list.size())) return;
371     GetDlgItem(IDC_DOWNLOAD_SELECTED)->EnableWindow(FALSE);     // 点击“下载选中项”后禁用该按钮
372     SetID(m_down_list[m_item_selected].id);                     // 将选中项目的歌曲ID关联到歌曲
373     m_pDownThread = AfxBeginThread(CoverDownloadThreadFunc, this);
374 }
375 
376 
OnNMClickCoverDownList(NMHDR * pNMHDR,LRESULT * pResult)377 void CCoverDownloadDlg::OnNMClickCoverDownList(NMHDR* pNMHDR, LRESULT* pResult)
378 {
379     LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
380     // TODO: 在此添加控件通知处理程序代码
381     m_item_selected = pNMItemActivate->iItem;
382     *pResult = 0;
383 }
384 
385 
OnNMDblclkCoverDownList(NMHDR * pNMHDR,LRESULT * pResult)386 void CCoverDownloadDlg::OnNMDblclkCoverDownList(NMHDR* pNMHDR, LRESULT* pResult)
387 {
388     LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
389     // TODO: 在此添加控件通知处理程序代码
390     m_item_selected = pNMItemActivate->iItem;
391     if (m_item_selected >= 0 && m_item_selected < static_cast<int>(m_down_list.size()))
392     {
393         OnBnClickedDownloadSelected();
394     }
395     *pResult = 0;
396 }
397 
398 
OnNMRClickCoverDownList(NMHDR * pNMHDR,LRESULT * pResult)399 void CCoverDownloadDlg::OnNMRClickCoverDownList(NMHDR* pNMHDR, LRESULT* pResult)
400 {
401     LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
402     // TODO: 在此添加控件通知处理程序代码
403     m_item_selected = pNMItemActivate->iItem;
404     *pResult = 0;
405 }
406 
407 
OnOK()408 void CCoverDownloadDlg::OnOK()
409 {
410     // TODO: 在此添加专用代码和/或调用基类
411     theApp.m_cover_download_dialog_exit = true;
412     if (m_pSearchThread != nullptr)
413         WaitForSingleObject(m_pSearchThread->m_hThread, 1000);	//等待线程退出
414     if (m_pDownThread != nullptr)
415         WaitForSingleObject(m_pDownThread->m_hThread, 1000);	//等待线程退出
416 
417     CBaseDialog::OnOK();
418 }
419 
420 
OnCancel()421 void CCoverDownloadDlg::OnCancel()
422 {
423     // TODO: 在此添加专用代码和/或调用基类
424     theApp.m_cover_download_dialog_exit = true;
425     if (m_pSearchThread != nullptr)
426         WaitForSingleObject(m_pSearchThread->m_hThread, 1000);	//等待线程退出
427     if (m_pDownThread != nullptr)
428         WaitForSingleObject(m_pDownThread->m_hThread, 1000);	//等待线程退出
429 
430     CBaseDialog::OnCancel();
431 }
432 
433 
OnDestroy()434 void CCoverDownloadDlg::OnDestroy()
435 {
436     CBaseDialog::OnDestroy();
437 
438     // TODO: 在此处添加消息处理程序代码
439     SaveConfig();
440 }
441 
442 
OnDownloadComplate(WPARAM wParam,LPARAM lParam)443 afx_msg LRESULT CCoverDownloadDlg::OnDownloadComplate(WPARAM wParam, LPARAM lParam)
444 {
445     //重新从本地获取专辑封面
446     if (CPlayer::GetInstance().GetCurrentSongInfo().IsSameSong(m_song))
447     {
448         CPlayer::GetInstance().SearchOutAlbumCover();
449         CPlayer::GetInstance().AlbumCoverGaussBlur();
450     }
451     GetDlgItem(IDC_DOWNLOAD_SELECTED)->EnableWindow(TRUE);		//下载完成后启用该按钮
452     const wstring& info = theApp.m_str_table.LoadText(L"MSG_NETWORK_DOWNLOAD_COMPLETE");
453     MessageBox(info.c_str(), NULL, MB_ICONINFORMATION | MB_OK);
454     return 0;
455 }
456 
457 
OnEnChangeTitleEdit()458 void CCoverDownloadDlg::OnEnChangeTitleEdit()
459 {
460     // TODO:  如果该控件是 RICHEDIT 控件,它将不
461     // 发送此通知,除非重写 CBaseDialog::OnInitDialog()
462     // 函数并调用 CRichEditCtrl().SetEventMask(),
463     // 同时将 ENM_CHANGE 标志“或”运算到掩码中。
464 
465     // TODO:  在此添加控件通知处理程序代码
466     CString tmp;
467     GetDlgItemText(IDC_TITLE_EDIT, tmp);
468     m_title = tmp;
469 }
470 
471 
OnEnChangeArtistEdit()472 void CCoverDownloadDlg::OnEnChangeArtistEdit()
473 {
474     // TODO:  如果该控件是 RICHEDIT 控件,它将不
475     // 发送此通知,除非重写 CBaseDialog::OnInitDialog()
476     // 函数并调用 CRichEditCtrl().SetEventMask(),
477     // 同时将 ENM_CHANGE 标志“或”运算到掩码中。
478 
479     // TODO:  在此添加控件通知处理程序代码
480     CString tmp;
481     GetDlgItemText(IDC_ARTIST_EDIT, tmp);
482     m_artist = tmp;
483 }
484 
485 
OnNMClickUnassociateLink(NMHDR * pNMHDR,LRESULT * pResult)486 void CCoverDownloadDlg::OnNMClickUnassociateLink(NMHDR* pNMHDR, LRESULT* pResult)
487 {
488     // TODO: 在此添加控件通知处理程序代码
489     SetID(wstring());
490     m_unassciate_lnk.ShowWindow(SW_HIDE);
491 
492     *pResult = 0;
493 }
494 
495 
496 
OnBnClickedSaveToSongFolder2()497 void CCoverDownloadDlg::OnBnClickedSaveToSongFolder2()
498 {
499     // TODO: 在此添加控件通知处理程序代码
500     m_save_to_song_folder = true;
501 }
502 
503 
OnBnClickedSaveToAlbumFolder2()504 void CCoverDownloadDlg::OnBnClickedSaveToAlbumFolder2()
505 {
506     // TODO: 在此添加控件通知处理程序代码
507     m_save_to_song_folder = false;
508 }
509