📄 playlistdlg.cpp
字号:
fHandled = TRUE;
break;
case ID_DELETED_PLAYLIST:
if (NULL != m_pPlaylist
&& NULL != pManager
&& !pManager->IsValid(m_pPlaylist))
{
m_pPlaylist = NULL;
}
fHandled = TRUE;
break;
case ID_UPDATE_INFO:
UpdateInfo();
fHandled = TRUE;
break;
default:
if (ID_PLAYLIST1_HISTORY <= LOWORD(wParam)
&& LOWORD(wParam) <= ID_PLAYLIST7_HISTORY)
{
m_bOrganizeFavorites = false;
if (m_pPlaylist)
{
m_pPlaylist->Save();
}
if (pManager)
{
m_pPlaylist = pManager->MRUPlaylist(LOWORD(wParam) - ID_PLAYLIST1_HISTORY);
}
else
{
m_pPlaylist = NULL;
}
if (m_pPlaylist)
{
m_pPlaylist->Load();
pManager->SetCurrentPlaylist(m_pPlaylist->GetPath());
//
// If we've played this playlist before, resume playing
//
if (-1 != m_pPlaylist->GetCurrent())
{
SendMessage(m_hwndParent, WM_COMMAND, ID_PLAY_SONG, (LPARAM)m_pPlaylist);
}
}
UpdateInfo();
}
break;
}
break;
case WM_NOTIFY:
fHandled = OnNotify((NMHDR*)lParam);
break;
case WM_MEASUREITEM:
if (0 == wParam)
{
OnMeasureItem((MEASUREITEMSTRUCT *)lParam);
fHandled = TRUE;
}
break;
case WM_DRAWITEM:
if (0 == wParam)
{
OnDrawItem((DRAWITEMSTRUCT*)lParam);
fHandled = TRUE;
}
break;
}
return fHandled;
}
void CPlaylistDialog::OnInitDialog()
{
// Grab the list view's HWND for later use
m_hwndTrackList = GetDlgItem(m_hwndDlg, IDC_TRACK_LIST);
//
// Check to see if the screen is small
//
if (g_bSmallScreen)
{
RECT rcWorkArea;
RECT rcWnd, rcList;
GetWindowRect(m_hwndDlg, &rcWnd);
GetWindowRect(m_hwndTrackList, &rcList);
if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
{
HDC hdc = ::GetDC(NULL);
rcWorkArea.left = 0;
rcWorkArea.top = 0;
rcWorkArea.right = GetDeviceCaps(hdc, HORZRES);
rcWorkArea.bottom = GetDeviceCaps(hdc, VERTRES) - GetSystemMetrics(SM_CYMENU);
::ReleaseDC(NULL, hdc);
}
MoveWindow(m_hwndDlg,
rcWorkArea.left,
rcWorkArea.top,
rcWorkArea.right,
rcWorkArea.bottom,
TRUE);
rcWorkArea.left += rcList.left - rcWnd.left;
rcWorkArea.right -= rcList.left - rcWnd.left;
rcWorkArea.right += rcList.right - rcWnd.right - 2*GetSystemMetrics(SM_CXDLGFRAME);
rcWorkArea.top += rcList.top - rcWnd.top - GetSystemMetrics(SM_CYCAPTION);
rcWorkArea.bottom -= rcList.top - rcWnd.top;
rcWorkArea.bottom += rcList.bottom - rcWnd.bottom;
MoveWindow(m_hwndTrackList,
rcWorkArea.left,
rcWorkArea.top,
rcWorkArea.right,
rcWorkArea.bottom,
TRUE);
}
// Create the menu bar & command bar
HRESULT hr;
hr = CreateBars();
if (FAILED(hr))
{
return;
}
if (m_himgLocationList)
{
ListView_SetImageList(m_hwndTrackList, m_himgLocationList, LVSIL_SMALL);
}
ListView_SetExtendedListViewStyle(m_hwndTrackList, LVS_EX_FULLROWSELECT);
// add the track list's single column
LVCOLUMN lvc;
RECT rc;
GetWindowRect(m_hwndTrackList, &rc);
memset(&lvc, 0, sizeof (lvc));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = rc.right - rc.left;
ListView_InsertColumn(m_hwndTrackList, 0, &lvc);
// update our track list contents according to the current playlist
UpdateInfo();
// We do this after we've done the UpdateInfo, so that we know if there are tracks to show icons/buttons for
EnableMenubarIcons();
// set focus on the list of tracks
SetFocus(m_hwndTrackList);
}
BOOL CPlaylistDialog::OnNotify(NMHDR * pNotifyHeader)
{
NMLISTVIEW * pNotifyListView = (NMLISTVIEW *)pNotifyHeader;
BOOL fHandled = FALSE;
CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
if (TBN_DROPDOWN == pNotifyHeader->code)
{
OnDropdownMenu();
fHandled = TRUE;
}
else if (NM_CUSTOMDRAW == pNotifyHeader->code
&& m_hwndTrackList == pNotifyHeader->hwndFrom)
{
NMLVCUSTOMDRAW *pcd = (NMLVCUSTOMDRAW*)pNotifyHeader;
if (CDDS_PREPAINT == pcd->nmcd.dwDrawStage)
{
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW);
fHandled = TRUE;
}
else if (CDDS_ITEMPREPAINT == pcd->nmcd.dwDrawStage && pManager)
{
CPlaylist * pPlaylist = NULL;
if (NULL != m_pPlaylist)
{
pPlaylist = m_pPlaylist;
}
else if (m_bOrganizeFavorites && pManager)
{
pPlaylist = pManager->GetFavorites();
}
else if (pManager)
{
pPlaylist = pManager->LocalContent();
}
if (NULL != pPlaylist)
{
if ((int)pcd->nmcd.dwItemSpec == pPlaylist->GetCurrent())
{
// Display the current track in bold
SelectObject(pcd->nmcd.hdc, m_hFont);
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, CDRF_NEWFONT);
}
// Gray out tracks whose files don't currently exist
CMediaClip * pClip = pPlaylist->GetTrack((int)pcd->nmcd.dwItemSpec);
if (NULL != pClip
&& pClip->IsAvailable())
{
pcd->clrText = GetSysColor(COLOR_WINDOWTEXT);
}
else
{
pcd->clrText = GetSysColor(COLOR_3DSHADOW);
}
SetBkMode(pcd->nmcd.hdc, OPAQUE);
pcd->clrTextBk = RGB(255, 255, 255);
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, CDRF_NEWFONT);
fHandled = TRUE;
}
}
}
else if (LVN_ITEMCHANGED == pNotifyHeader->code)
{
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, 0);
fHandled = TRUE;
}
else if (LVN_DELETEALLITEMS == pNotifyHeader->code)
{
// Suppress LVN_DELETEITEM notifications
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, TRUE);
fHandled = TRUE;
}
else if (LVN_ITEMACTIVATE == pNotifyHeader->code)
{
SendMessage(m_hwndDlg, WM_COMMAND, ID_PLAY_SONG, 0);
fHandled = TRUE;
}
else if (NM_RCLICK == pNotifyHeader->code)
{
ClientToScreen(m_hwndTrackList, &pNotifyListView->ptAction);
OnContextMenu(pNotifyListView->ptAction);
fHandled = TRUE;
}
else if (GN_CONTEXTMENU == pNotifyHeader->code)
{
if (g_AygshellHelper.Loaded())
{
POINT pt;
BOOL fRet = GetCursorPos(&pt);
ASSERT(fRet);
OnContextMenu(pt);
fHandled = TRUE;
}
}
else if (LVN_BEGINDRAG == pNotifyHeader->code)
{
#ifdef UNDER_CE
SetWindowLong(m_hwndDlg, DWL_MSGRESULT, LVBD_DRAGSELECT);
#endif /* _UNDER_CE */
fHandled = TRUE;
}
EnableMenubarIcons();
return fHandled;
}
void CPlaylistDialog::OnDropdownMenu()
{
HRESULT hr = S_OK;
HMENU hmenu = NULL;
HMENU hmenuPopup = NULL;
MENUITEMINFO mii;
DrawMenuStruct * pMenuStruct = NULL;
BOOL fRestoreText = FALSE;
int cmd = 0;
int i;
CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
DWORD rgIDs[] =
{
ID_ALL_MUSIC,
ID_FAVORITES,
ID_ALL_PLAYLISTS
};
do
{
//
// set the name temporarily
//
if (m_pPlaylist)
{
SetDropdownText((LPTSTR)m_pPlaylist->GetName(), I_PLAYLIST);
}
else
{
SetDropdownText(TEXT("Local Content"), I_ALL_MY_MUSIC);
}
//
// create an empty popup menu
//
hmenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDM_TRACKS_CONTEXT));
if (NULL != hmenu)
{
hmenuPopup = GetSubMenu(hmenu, 1);
}
if (NULL == hmenuPopup)
{
break;
}
//
// add the "All My Music" owner-drawn item
//
mii.cbSize = sizeof (mii);
for (i = 0; i < sizeof (rgIDs)/sizeof (rgIDs[0]); i++)
{
pMenuStruct = new DrawMenuStruct;
if (NULL == pMenuStruct)
{
hr = E_OUTOFMEMORY;
break;
}
pMenuStruct->iImage = I_ALL_MY_MUSIC;
mii.fMask = MIIM_TYPE;
mii.dwTypeData = pMenuStruct->szText;
mii.cch = sizeof (pMenuStruct->szText)/sizeof (pMenuStruct->szText[0]);
if (GetMenuItemInfo(hmenuPopup, rgIDs[i], FALSE, &mii))
{
mii.fMask = MIIM_TYPE | MIIM_DATA;
mii.fType = MFT_OWNERDRAW;
mii.dwTypeData = (LPTSTR)pMenuStruct;
mii.dwItemData = (DWORD)pMenuStruct;
SetMenuItemInfo(hmenuPopup, rgIDs[i], FALSE, &mii);
}
}
//
// Get the menu count and find ID_ALL_PLAYLISTS
//
mii.fMask = MIIM_ID;
int cItems = 0;
while (GetMenuItemInfo(hmenuPopup, cItems, TRUE, &mii))
{
if (ID_ALL_PLAYLISTS == mii.wID)
{
cItems--;
break;
}
cItems++;
}
if (pManager)
{
for (int iMRU = pManager->MRUPlaylistCount() - 1; iMRU >= 0; iMRU--)
{
CPlaylist * pPlaylist = pManager->MRUPlaylist(iMRU);
while (NULL == pPlaylist
&& iMRU < pManager->MRUPlaylistCount())
{
pManager->MRURemove(iMRU);
if (iMRU > 0) iMRU--;
pPlaylist = pManager->MRUPlaylist(iMRU);
}
if (NULL == pPlaylist)
{
break;
}
LPTSTR szName = pManager->GetDisplayName(pPlaylist);
if (!szName)
{
hr = E_OUTOFMEMORY;
break;
}
pMenuStruct = new DrawMenuStruct;
if (NULL == pMenuStruct)
{
delete [] szName;
hr = E_OUTOFMEMORY;
break;
}
pMenuStruct->iImage = I_PLAYLIST;
_tcsncpy(pMenuStruct->szText, szName, 50);
pMenuStruct->szText[49] = 0;
delete [] szName;
szName = NULL;
mii.fMask = MIIM_TYPE | MIIM_DATA;
mii.fType = MFT_OWNERDRAW;
mii.dwTypeData = (LPTSTR)pMenuStruct;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -