1 // CFloatPlaylistDlg.cpp: 实现文件
2 //
3
4 #include "stdafx.h"
5 #include "MusicPlayer2.h"
6 #include "CFloatPlaylistDlg.h"
7 #include "MusicPlayerDlg.h"
8 #include "CRecentList.h"
9
10 // CFloatPlaylistDlg 对话框
11
IMPLEMENT_DYNAMIC(CFloatPlaylistDlg,CBaseDialog)12 IMPLEMENT_DYNAMIC(CFloatPlaylistDlg, CBaseDialog)
13
14 CFloatPlaylistDlg::CFloatPlaylistDlg(int& item_selected, vector<int>& items_selected, CWnd* pParent /*=nullptr*/)
15 : CBaseDialog(IDD_MUSICPLAYER2_DIALOG, pParent), m_item_selected{ item_selected }, m_items_selected{ items_selected }, m_playlist_ctrl{ CPlayer::GetInstance().GetPlayList() }
16 {
17 m_path_edit.SetTooltopText(theApp.m_str_table.LoadText(L"UI_TIP_BTN_RECENT_FOLDER_OR_PLAYLIST").c_str());
18 }
19
~CFloatPlaylistDlg()20 CFloatPlaylistDlg::~CFloatPlaylistDlg()
21 {
22 }
23
RefreshData()24 void CFloatPlaylistDlg::RefreshData()
25 {
26 //刷新播放列表数据
27 m_playlist_ctrl.ShowPlaylist(theApp.m_media_lib_setting_data.display_format);
28
29 CListCache list_cache(LT_CURRENT);
30 list_cache.reload();
31 const ListItem& cur_list = list_cache.at(0);
32
33 m_path_static.SetWindowText(cur_list.GetTypeDisplayName().c_str());
34 m_path_static.SetIcon(cur_list.GetTypeIcon());
35 m_path_edit.SetWindowText(cur_list.GetDisplayName().c_str());
36
37 //播放列表模式下,播放列表工具栏第一个菜单为“添加”,文件夹模式下为“文件夹”
38 if (cur_list.type != LT_FOLDER)
39 {
40 const wstring& menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_ADD");
41 m_playlist_toolbar.ModifyToolButton(0, IconMgr::IconType::IT_Add, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::MainPlaylistAddMenu), true);
42 }
43 else
44 {
45 const wstring& menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_FOLDER");
46 m_playlist_toolbar.ModifyToolButton(0, IconMgr::IconType::IT_Folder, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistToolBarFolderMenu), true);
47 }
48 m_playlist_ctrl.SetCurSel(-1);
49 }
50
ReSizeControl(int cx,int cy)51 void CFloatPlaylistDlg::ReSizeControl(int cx, int cy)
52 {
53 CRect rect_base{ m_layout.margin, m_layout.margin, cx - m_layout.margin, cy - m_layout.margin };
54
55 // 设置IDC_PATH_STATIC/IDC_PATH_EDIT/ID_MEDIA_LIB的位置和大小
56 int static_width = theApp.DPI(32);
57 CMusicPlayerDlg* pDlg = dynamic_cast<CMusicPlayerDlg*>(theApp.m_pMainWnd);
58 if (pDlg != nullptr)
59 static_width = pDlg->GetPathStaticWidth();
60 int edit_height = m_layout.path_edit_height;
61 CRect rect_static{ rect_base.left, rect_base.top, rect_base.left + static_width, rect_base.top + edit_height };
62 CRect rect_media_lib{ rect_base.right - m_medialib_btn_width, rect_base.top - 1, rect_base.right, rect_base.top + edit_height + 1 };
63 CRect rect_edit{ rect_static.right + m_layout.margin, rect_base.top, rect_media_lib.left - m_layout.margin, rect_base.top + edit_height };
64 m_path_static.MoveWindow(rect_static);
65 m_path_edit.MoveWindow(rect_edit);
66 m_media_lib_button.MoveWindow(rect_media_lib);
67
68 rect_base.top += edit_height + m_layout.margin;
69 //设置歌曲搜索框的大小和位置
70 CRect rect_search;
71 m_search_edit.GetWindowRect(rect_search);
72 int search_height = rect_search.Height();
73 rect_search = { rect_base.left, rect_base.top, rect_base.right, rect_base.top + search_height };
74 m_search_edit.MoveWindow(rect_search);
75
76 rect_base.top += search_height + m_layout.margin;
77 //设置播放列表工具栏的大小位置
78 int toolbar_height = m_layout.toolbar_height;
79 CRect rect_toolbar{ rect_base.left, rect_base.top, rect_base.right, rect_base.top + toolbar_height };
80 m_playlist_toolbar.MoveWindow(rect_toolbar);
81 m_playlist_toolbar.Invalidate();
82
83 rect_base.top += toolbar_height + m_layout.margin;
84 // 设置播放列表控件大小和位置(即rect_base剩余空间)
85 m_playlist_ctrl.MoveWindow(rect_base);
86 m_playlist_ctrl.AdjustColumnWidth();
87 }
88
RefreshState(bool highlight_visible)89 void CFloatPlaylistDlg::RefreshState(bool highlight_visible)
90 {
91 m_playlist_ctrl.SetHightItem(CPlayer::GetInstance().GetIndex());
92 if (highlight_visible)
93 m_playlist_ctrl.EnsureVisible(CPlayer::GetInstance().GetIndex(), FALSE);
94 m_playlist_ctrl.Invalidate(FALSE);
95 }
96
GetListCtrl()97 CPlayListCtrl& CFloatPlaylistDlg::GetListCtrl()
98 {
99 return m_playlist_ctrl;
100 }
101
GetPathStatic()102 CStaticEx& CFloatPlaylistDlg::GetPathStatic()
103 {
104 return m_path_static;
105 }
106
GetPathEdit()107 CMenuEditCtrl& CFloatPlaylistDlg::GetPathEdit()
108 {
109 return m_path_edit;
110 }
111
GetSearchBox()112 CSearchEditCtrl& CFloatPlaylistDlg::GetSearchBox()
113 {
114 return m_search_edit;
115 }
116
GetPlaylistItemSelected()117 void CFloatPlaylistDlg::GetPlaylistItemSelected()
118 {
119 if (!m_searched)
120 {
121 m_item_selected = m_playlist_ctrl.GetCurSel(); //获取鼠标选中的项目
122 m_playlist_ctrl.GetItemSelected(m_items_selected); //获取多个选中的项目
123 }
124 else
125 {
126 CString str;
127 str = m_playlist_ctrl.GetItemText(m_playlist_ctrl.GetCurSel(), 0);
128 m_item_selected = _ttoi(str) - 1;
129 m_playlist_ctrl.GetItemSelectedSearched(m_items_selected);
130 }
131
132 }
133
SetDragEnable()134 void CFloatPlaylistDlg::SetDragEnable()
135 {
136 bool enable = CPlayer::GetInstance().IsPlaylistMode() && !theApp.m_media_lib_setting_data.disable_drag_sort && !m_searched; //处于播放列表模式且不处理搜索状态时才允许拖动排序
137 m_playlist_ctrl.SetDragEnable(enable);
138 }
139
EnableControl(bool enable)140 void CFloatPlaylistDlg::EnableControl(bool enable)
141 {
142 m_playlist_ctrl.EnableWindow(enable);
143 m_search_edit.EnableWindow(enable);
144 m_media_lib_button.EnableWindow(enable);
145 m_playlist_toolbar.EnableWindow(enable);
146 m_playlist_toolbar.Invalidate();
147 }
148
UpdateStyles()149 void CFloatPlaylistDlg::UpdateStyles()
150 {
151 if (theApp.m_media_lib_setting_data.float_playlist_follow_main_wnd)
152 {
153 ModifyStyle(WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0);
154 ModifyStyleEx(WS_EX_APPWINDOW, 0);
155 }
156 else
157 {
158 ModifyStyle(0, WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
159 ModifyStyleEx(0, WS_EX_APPWINDOW);
160 }
161 }
162
SetInitPoint(CPoint point)163 void CFloatPlaylistDlg::SetInitPoint(CPoint point)
164 {
165 m_init_point = point;
166 }
167
Initilized() const168 bool CFloatPlaylistDlg::Initilized() const
169 {
170 return m_playlist_ctrl.GetSafeHwnd() != NULL && m_path_static.GetSafeHwnd() != NULL && m_path_edit.GetSafeHwnd() != NULL
171 && m_media_lib_button.GetSafeHwnd() != NULL && m_search_edit.GetSafeHwnd() != NULL/* && m_clear_search_button.GetSafeHwnd() != NULL*/;
172 }
173
GetDialogName() const174 CString CFloatPlaylistDlg::GetDialogName() const
175 {
176 return CString();
177 }
178
InitializeControls()179 bool CFloatPlaylistDlg::InitializeControls()
180 {
181 // 设置最小窗口大小(为需要容纳可能较长的控件文本,调整最小宽度到与主窗口一致)
182 SetMinSize(theApp.DPI(340), theApp.DPI(228));
183 // 设置窗口标题
184 SetWindowTextW(theApp.m_str_table.LoadText(L"TXT_PLAYLIST").c_str());
185 // 测量受翻译字符串影响的控件所需宽度,并应用翻译字符串到控件
186 CString text;
187 text = theApp.m_str_table.LoadText(L"TXT_FOLDER").c_str();
188 m_path_static.SetWindowTextW(text);
189 // 媒体库按钮宽度
190 text = theApp.m_str_table.LoadText(L"UI_TXT_BTN_MEDIA_LIB").c_str();
191 m_media_lib_button.SetWindowTextW(text);
192 int media_lib_width = (std::min)(GetTextExtent(text).Width() + theApp.DPI(40), theApp.DPI(150));
193 m_medialib_btn_width = (std::max)(m_medialib_btn_width, media_lib_width);
194
195 return true;
196 }
197
DoDataExchange(CDataExchange * pDX)198 void CFloatPlaylistDlg::DoDataExchange(CDataExchange* pDX)
199 {
200 CBaseDialog::DoDataExchange(pDX);
201 DDX_Control(pDX, IDC_PLAYLIST_LIST, m_playlist_ctrl);
202 DDX_Control(pDX, IDC_PATH_STATIC, m_path_static);
203 DDX_Control(pDX, IDC_PATH_EDIT, m_path_edit);
204 DDX_Control(pDX, ID_MEDIA_LIB, m_media_lib_button);
205 DDX_Control(pDX, IDC_SEARCH_EDIT, m_search_edit);
206 DDX_Control(pDX, IDC_PLAYLIST_TOOLBAR, m_playlist_toolbar);
207 }
208
209
BEGIN_MESSAGE_MAP(CFloatPlaylistDlg,CBaseDialog)210 BEGIN_MESSAGE_MAP(CFloatPlaylistDlg, CBaseDialog)
211 ON_WM_SIZE()
212 ON_NOTIFY(NM_RCLICK, IDC_PLAYLIST_LIST, &CFloatPlaylistDlg::OnNMRClickPlaylistList)
213 ON_NOTIFY(NM_DBLCLK, IDC_PLAYLIST_LIST, &CFloatPlaylistDlg::OnNMDblclkPlaylistList)
214 ON_EN_CHANGE(IDC_SEARCH_EDIT, &CFloatPlaylistDlg::OnEnChangeSearchEdit)
215 ON_WM_CLOSE()
216 ON_NOTIFY(NM_CLICK, IDC_PLAYLIST_LIST, &CFloatPlaylistDlg::OnNMClickPlaylistList)
217 ON_MESSAGE(WM_INITMENU, &CFloatPlaylistDlg::OnInitmenu)
218 ON_MESSAGE(WM_LIST_ITEM_DRAGGED, &CFloatPlaylistDlg::OnListItemDragged)
219 ON_MESSAGE(WM_SEARCH_EDIT_BTN_CLICKED, &CFloatPlaylistDlg::OnSearchEditBtnClicked)
220 ON_COMMAND(ID_LOCATE_TO_CURRENT, &CFloatPlaylistDlg::OnLocateToCurrent)
221 ON_MESSAGE(WM_MAIN_WINDOW_ACTIVATED, &CFloatPlaylistDlg::OnMainWindowActivated)
222 ON_WM_DROPFILES()
223 ON_WM_COPYDATA()
224 END_MESSAGE_MAP()
225
226
227 // CFloatPlaylistDlg 消息处理程序
228
229
230 BOOL CFloatPlaylistDlg::OnInitDialog()
231 {
232 CBaseDialog::OnInitDialog();
233
234 // TODO: 在此添加额外的初始化
235 SetBackgroundColor(CONSTVAL::BACKGROUND_COLOR);
236 UpdateStyles();
237 SetIcon(IconMgr::IconType::IT_Playlist, FALSE);
238 SetButtonIcon(ID_MEDIA_LIB, IconMgr::IconType::IT_Media_Lib);
239
240 // 为浮动播放列表禁用仅在主窗口使用的控件
241 EnableDlgCtrl(IDC_HSPLITER_STATIC, false);
242 ShowDlgCtrl(IDC_HSPLITER_STATIC, false);
243 EnableDlgCtrl(IDC_UI_STATIC, false);
244 ShowDlgCtrl(IDC_UI_STATIC, false);
245
246 //设置窗口大小和位置
247 if (CMusicPlayerDlg::IsPointValid(m_init_point))
248 SetWindowPos(nullptr, m_init_point.x, m_init_point.y, theApp.m_nc_setting_data.playlist_size.cx, theApp.m_nc_setting_data.playlist_size.cy, SWP_NOZORDER);
249 else
250 SetWindowPos(nullptr, 0, 0, theApp.m_nc_setting_data.playlist_size.cx, theApp.m_nc_setting_data.playlist_size.cy, SWP_NOMOVE | SWP_NOZORDER);
251
252 CRect rect;
253 GetClientRect(rect);
254 ReSizeControl(rect.Width(), rect.Height());
255
256 wstring prompt_str = theApp.m_str_table.LoadText(L"TXT_SEARCH_PROMPT") + L"(F)";
257 m_search_edit.SetCueBanner(prompt_str.c_str(), TRUE);
258 ListItem list_item = CRecentList::Instance().GetCurrentList();
259 m_path_static.SetWindowText(list_item.GetTypeDisplayName().c_str());
260 m_path_static.SetIcon(list_item.GetTypeIcon());
261
262 //初始化播放列表工具栏
263 wstring menu_str;
264 m_playlist_toolbar.SetIconSize(theApp.DPI(20));
265 menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_ADD");
266 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Add, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::MainPlaylistAddMenu), true);
267 menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_DELETE");
268 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Cancel, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::MainPlaylistDelMenu), true);
269 menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_SORT");
270 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Sort_Mode, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::MainPlaylistSortMenu), true);
271 menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_LIST");
272 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Playlist, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistToolBarListMenu), true);
273 menu_str = theApp.m_str_table.LoadText(L"UI_TXT_PLAYLIST_TOOLBAR_EDIT");
274 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Edit, menu_str.c_str(), menu_str.c_str(), theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistToolBarEditMenu), true);
275 menu_str = theApp.m_str_table.LoadText(L"UI_TIP_BTN_LOCATE_TO_CURRENT") + CPlayerUIBase::GetCmdShortcutKeyForTooltips(ID_LOCATE_TO_CURRENT).GetString();
276 m_playlist_toolbar.AddToolButton(IconMgr::IconType::IT_Locate, nullptr, menu_str.c_str(), ID_LOCATE_TO_CURRENT);
277
278 RefreshData();
279 RefreshState();
280
281 SetDragEnable();
282 EnableControl(!CPlayer::GetInstance().m_loading);
283
284 return TRUE; // return TRUE unless you set the focus to a control
285 // 异常: OCX 属性页应返回 FALSE
286 }
287
OnSize(UINT nType,int cx,int cy)288 void CFloatPlaylistDlg::OnSize(UINT nType, int cx, int cy)
289 {
290 CBaseDialog::OnSize(nType, cx, cy);
291
292 if (nType != SIZE_MINIMIZED && Initilized())
293 {
294 ReSizeControl(cx, cy);
295
296 if (nType != SIZE_MAXIMIZED)
297 {
298 CRect rect;
299 GetWindowRect(&rect);
300 theApp.m_nc_setting_data.playlist_size.cx = rect.Width();
301 theApp.m_nc_setting_data.playlist_size.cy = rect.Height();
302
303 if (theApp.m_pMainWnd->IsIconic())
304 theApp.m_pMainWnd->ShowWindow(SW_RESTORE);
305 }
306 }
307 }
308
OnNMRClickPlaylistList(NMHDR * pNMHDR,LRESULT * pResult)309 void CFloatPlaylistDlg::OnNMRClickPlaylistList(NMHDR* pNMHDR, LRESULT* pResult)
310 {
311 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
312 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
313 if (main_wnd != nullptr)
314 main_wnd->SetUiPlaylistSelected(pNMItemActivate->iItem);
315 if (!m_searched)
316 {
317 m_item_selected = pNMItemActivate->iItem; //获取鼠标选中的项目
318 m_playlist_ctrl.GetItemSelected(m_items_selected); //获取多个选中的项目
319 }
320 else
321 {
322 CString str;
323 str = m_playlist_ctrl.GetItemText(pNMItemActivate->iItem, 0);
324 m_item_selected = _ttoi(str) - 1;
325 m_playlist_ctrl.GetItemSelectedSearched(m_items_selected);
326 }
327
328 CMenu* pContextMenu{};
329 if (m_item_selected >= 0)
330 pContextMenu = theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistMenu);
331 else
332 pContextMenu = theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistToolBarMenu);
333 m_playlist_ctrl.ShowPopupMenu(pContextMenu, pNMItemActivate->iItem, this);
334
335 *pResult = 0;
336 }
337
OnNMDblclkPlaylistList(NMHDR * pNMHDR,LRESULT * pResult)338 void CFloatPlaylistDlg::OnNMDblclkPlaylistList(NMHDR* pNMHDR, LRESULT* pResult)
339 {
340 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
341 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
342 if (main_wnd != nullptr)
343 main_wnd->SetUiPlaylistSelected(pNMItemActivate->iItem);
344 if (!m_searched) //如果播放列表不在搜索状态,则当前选中项的行号就是曲目的索引
345 {
346 if (pNMItemActivate->iItem < 0)
347 return;
348 m_item_selected = pNMItemActivate->iItem;
349 }
350 else //如果播放列表处理选中状态,则曲目的索引是选中行第一列的数字-1
351 {
352 int song_index;
353 CString str;
354 str = m_playlist_ctrl.GetItemText(pNMItemActivate->iItem, 0);
355 song_index = _ttoi(str) - 1;
356 if (song_index < 0)
357 return;
358 m_item_selected = song_index;
359 }
360 theApp.m_pMainWnd->SendMessage(WM_COMMAND, ID_PLAY_ITEM);
361
362 *pResult = 0;
363 }
364
OnEnChangeSearchEdit()365 void CFloatPlaylistDlg::OnEnChangeSearchEdit()
366 {
367 CString key_word;
368 m_search_edit.GetWindowText(key_word);
369 m_searched = (key_word.GetLength() != 0);
370 m_playlist_ctrl.QuickSearch(wstring(key_word));
371 m_playlist_ctrl.ShowPlaylist(theApp.m_media_lib_setting_data.display_format, m_searched);
372 SetDragEnable();
373 }
374
375
OnCancel()376 void CFloatPlaylistDlg::OnCancel()
377 {
378 // TODO: 在此添加专用代码和/或调用基类
379 DestroyWindow();
380
381 //CBaseDialog::OnCancel();
382 }
383
OnClose()384 void CFloatPlaylistDlg::OnClose()
385 {
386 theApp.m_pMainWnd->SendMessage(WM_FLOAT_PLAYLIST_CLOSED);
387 // 仅在用户主动关闭浮动播放列表时更改设置,在退出时会直接OnCancel关闭窗口
388 theApp.m_nc_setting_data.float_playlist = false;
389 CBaseDialog::OnClose();
390 }
391
392
OnCommand(WPARAM wParam,LPARAM lParam)393 BOOL CFloatPlaylistDlg::OnCommand(WPARAM wParam, LPARAM lParam)
394 {
395 // TODO: 在此添加专用代码和/或调用基类
396 WORD command = LOWORD(wParam);
397 switch (wParam)
398 {
399 case ID_PLAYLIST_SELECT_ALL:
400 m_playlist_ctrl.SelectAll();
401 GetPlaylistItemSelected();
402 break;
403 case ID_PLAYLIST_SELECT_NONE:
404 m_playlist_ctrl.SelectNone();
405 GetPlaylistItemSelected();
406 break;
407 case ID_PLAYLIST_SELECT_REVERT:
408 m_playlist_ctrl.SelectReverse();
409 GetPlaylistItemSelected();
410 break;
411 default:
412 if (command == ID_MEDIA_LIB || CCommon::IsMenuItemInMenu(theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistMenu), command)
413 || CCommon::IsMenuItemInMenu(theApp.m_menu_mgr.GetMenu(MenuMgr::PlaylistToolBarMenu), command) // 此处使用等价的弹出菜单,含有所有独立的工具栏按钮菜单项
414 || CCommon::IsMenuItemInMenu(theApp.m_menu_mgr.GetMenu(MenuMgr::MainPopupMenu), command)
415 || (command >= ID_ADD_TO_MY_FAVOURITE && command < ID_ADD_TO_MY_FAVOURITE + ADD_TO_PLAYLIST_MAX_SIZE))
416 {
417 theApp.m_pMainWnd->SendMessage(WM_COMMAND, wParam, lParam); //将菜单命令转发到主窗口
418 return TRUE;
419 }
420 break;
421 }
422
423 return CBaseDialog::OnCommand(wParam, lParam);
424 }
425
OnNMClickPlaylistList(NMHDR * pNMHDR,LRESULT * pResult)426 void CFloatPlaylistDlg::OnNMClickPlaylistList(NMHDR* pNMHDR, LRESULT* pResult)
427 {
428 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
429 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
430 if (main_wnd != nullptr)
431 main_wnd->SetUiPlaylistSelected(pNMItemActivate->iItem);
432 GetPlaylistItemSelected();
433 *pResult = 0;
434 }
435
436
PreTranslateMessage(MSG * pMsg)437 BOOL CFloatPlaylistDlg::PreTranslateMessage(MSG* pMsg)
438 {
439 // TODO: 在此添加专用代码和/或调用基类
440 if (pMsg->hwnd != m_search_edit.GetSafeHwnd())
441 {
442 if (WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST)
443 {
444 //响应Accelerator中设置的快捷键
445 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
446 if (main_wnd != nullptr && main_wnd->GetAccel() && ::TranslateAccelerator(m_hWnd, main_wnd->GetAccel(), pMsg))
447 return TRUE;
448 }
449 }
450 if (pMsg->message == WM_KEYDOWN)
451 {
452 if (pMsg->hwnd != m_search_edit.GetSafeHwnd())
453 {
454 if (pMsg->wParam == 'F') //按F键快速查找
455 {
456 m_search_edit.SetFocus();
457 return TRUE;
458 }
459 if (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN) //按ESC/回车退出
460 {
461 OnClose();
462 OnCancel();
463 return TRUE;
464 }
465 }
466 else if (pMsg->wParam == VK_ESCAPE) // 按键按下+在搜索框内+按下Esc 设置浮动播放列表窗口焦点
467 {
468 SetFocus();
469 }
470 }
471
472 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)) //屏蔽按回车键和ESC键退出
473 {
474 return TRUE;
475 }
476
477 return CBaseDialog::PreTranslateMessage(pMsg);
478 }
479
480
OnInitmenu(WPARAM wParam,LPARAM lParam)481 afx_msg LRESULT CFloatPlaylistDlg::OnInitmenu(WPARAM wParam, LPARAM lParam)
482 {
483 theApp.m_pMainWnd->SendMessage(WM_INITMENU, wParam, lParam); //将WM_INITMENU消息转发到主窗口
484 return 0;
485 }
486
487
OnListItemDragged(WPARAM wParam,LPARAM lParam)488 afx_msg LRESULT CFloatPlaylistDlg::OnListItemDragged(WPARAM wParam, LPARAM lParam)
489 {
490 theApp.m_pMainWnd->SendMessage(WM_LIST_ITEM_DRAGGED, wParam, lParam);
491 return 0;
492 }
493
494
OnSearchEditBtnClicked(WPARAM wParam,LPARAM lParam)495 afx_msg LRESULT CFloatPlaylistDlg::OnSearchEditBtnClicked(WPARAM wParam, LPARAM lParam)
496 {
497 if (m_searched)
498 {
499 //清除搜索结果
500 m_searched = false;
501 m_search_edit.SetWindowText(_T(""));
502 m_playlist_ctrl.ShowPlaylist(theApp.m_media_lib_setting_data.display_format, m_searched);
503 m_playlist_ctrl.EnsureVisible(CPlayer::GetInstance().GetIndex(), FALSE); //清除搜索结果后确保正在播放曲目可见
504 }
505 return 0;
506 }
507
508
OnLocateToCurrent()509 void CFloatPlaylistDlg::OnLocateToCurrent()
510 {
511 // TODO: 在此添加命令处理程序代码
512 m_playlist_ctrl.EnsureVisible(CPlayer::GetInstance().GetIndex(), FALSE);
513 }
514
515
OnMainWindowActivated(WPARAM wParam,LPARAM lParam)516 afx_msg LRESULT CFloatPlaylistDlg::OnMainWindowActivated(WPARAM wParam, LPARAM lParam)
517 {
518 /*
519 * WM_MAIN_WINDOW_ACTIVATED消息是当已经有一个MusicPlayer2进程在运行时尝试启动一个新的MusicPlayer2进程时发送
520 * 由于浮动播放列表和主窗口的类名相同(因为主窗口和浮动播放列表使用的是同一对话框资源),因此主窗口可能会不能正常激活,
521 * 在收到此消息时重新激活一次主窗口,并将WM_MAIN_WINDOW_ACTIVATED消息转发给主窗口
522 */
523 theApp.m_pMainWnd->ShowWindow(SW_SHOWNORMAL); //激活并显示窗口
524 theApp.m_pMainWnd->SetForegroundWindow(); //将窗口设置为焦点
525 theApp.m_pMainWnd->SendMessage(WM_MAIN_WINDOW_ACTIVATED);
526 return 0;
527 }
528
529
OnDropFiles(HDROP hDropInfo)530 void CFloatPlaylistDlg::OnDropFiles(HDROP hDropInfo)
531 {
532 // TODO: 在此添加消息处理程序代码和/或调用默认值
533 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
534 if (main_wnd != nullptr)
535 main_wnd->OnDropFiles(hDropInfo);
536 else
537 CBaseDialog::OnDropFiles(hDropInfo);
538 }
539
540
OnCopyData(CWnd * pWnd,COPYDATASTRUCT * pCopyDataStruct)541 BOOL CFloatPlaylistDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
542 {
543 // TODO: 在此添加消息处理程序代码和/或调用默认值
544 //转发给主窗口
545 CMusicPlayerDlg* main_wnd = CMusicPlayerDlg::GetInstance();
546 if (main_wnd != nullptr)
547 return main_wnd->OnCopyData(pWnd, pCopyDataStruct);
548 else
549 return CBaseDialog::OnCopyData(pWnd, pCopyDataStruct);
550 }
551