📄 mp3listbox.cpp
字号:
* 输出参数:无
* 返回值 :COLORREF, 选定列表项的文字颜色
*/
COLORREF CMP3ListBox::GetSelectedTextColor() const
{
return this->m_crSelectedText;
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:SetHotTextColor
* 函数介绍:设定Hot列表项的文字颜色
* 输入参数:COLORREF, Hot列表项的文字颜色
* 输出参数:无
* 返回值 :无
*/
void CMP3ListBox::SetHotTextColor(COLORREF crColor)
{
this->m_crHotText=crColor;
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:GetHotTextColor
* 函数介绍:查询Hot列表项的文字颜色
* 输入参数:无
* 输出参数:无
* 返回值 :COLORREF, Hot列表项的文字颜色
*/
COLORREF CMP3ListBox::GetHotTextColor() const
{
return this->m_crHotText;
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:CtlColor
* 函数介绍:响应WM_CTLCOLOR_REFLECT消息,重画自己的背景
* 输入参数:CDC* pDC, UINT nCtlColor
* 输出参数:无
* 返回值 :HBRUSH
*/
HBRUSH CMP3ListBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return this->m_hBrush;
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:OnContextMenu
* 函数介绍:显示快捷菜单
* 输入参数:CWnd* pWnd, CPoint point
* 输出参数:无
* 返回值 :无
*/
void CMP3ListBox::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
// CG: This block was added by the Pop-up Menu component
//选定了乐曲才显示快捷菜单
if (this->GetSelCount()!=0)
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_MY_LIST_CTRL));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
// Menu's parent window should be "this", so the menu command be handled by self.
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
this);
}
}
void CMP3ListBox::OnListmenuDelete()
{
// TODO: Add your command handler code here
if (GetSelCount()<1)
{
return;
}
GetParent()->SendMessage(MYWM_LISTITEMDELETE, 0);
// Wait until the message is handled.
// MSG msg;
// while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
// DispatchMessage(&msg);
this->DeleteSelectedFiles();
GetParent()->SendMessage(MYWM_LISTITEMDELETE, 1);
}
void CMP3ListBox::OnListmenuInfo()
{
// TODO: Add your command handler code here
if (GetSelCount()<1)
{
return;
}
int iSelItem;
GetSelItems(1, &iSelItem);
ASSERT(iSelItem > -1);
CID3TAGDlg dlg(GetPath(iSelItem), GetParent());
if (dlg.DoModal() == IDOK)
{
UpdateSongInfo(iSelItem);
// 由于不可能改变正在播放项,故不必改变父窗口的m_Title
}
}
void CMP3ListBox::OnListmenuPlay()
{
// TODO: Add your command handler code here
if (GetSelCount()<1)
{
return;
}
GetParent()->SendMessage(MYWM_LISTITEMPLAY);
}
void CMP3ListBox::OnDblclk()
{
// TODO: Add your control notification handler code here
OnListmenuPlay();
}
void CMP3ListBox::OnDestroy()
{
int i;
int iItemCount = GetCount();
ASSERT(iItemCount!=LB_ERR);
// TODO: Add your message handler code here
for (i=0; i<iItemCount; i++)
{
m_pItem = (CMP3ListBoxItem *)GetItemData(i);
delete m_pItem;
}
CListBox::ResetContent();
CListBox::OnDestroy();
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:OnSetCursor
* 函数介绍:拖动列表项时改变鼠标指针
* 输入参数:CWnd* pWnd, UINT nHitTest, UINT message
* 输出参数:无
* 返回值 :BOOL
*/
BOOL CMP3ListBox::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
//Display a different cursor while dragging.
if (m_bDragging)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_MOVECURSOR));
return TRUE;
}
return CListBox::OnSetCursor(pWnd, nHitTest, message);
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:PreTranslateMessage
* 函数介绍:处理快捷键
* 输入参数:MSG* pMsg
* 输出参数:无
* 返回值 :BOOL
*/
BOOL CMP3ListBox::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (::TranslateAccelerator(this->GetSafeHwnd(), m_hAccTable, pMsg))
{
return(TRUE);
}
return CListBox::PreTranslateMessage(pMsg);
}
///////////////////////////以下三个函数实现拖动列表项的功能/////////////////////////////
void CMP3ListBox::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
BOOL bOutside;
int i=ItemFromPoint(point, bOutside);
CString str;
str.Format("Mouse in:%d\n", i);
TRACE(str);
RECT rLast;
GetItemRect(GetCount()-1, &rLast);
// 按在了空白处:全不选...
if (point.y>rLast.bottom ||
i==0)
{
SetSel(-1, false);
m_bMouseDown = false;
CListBox::OnLButtonDown(nFlags, point);
return;
}
if (!GetSel(i)) // 鼠标按下的项未被选定...
{
m_bMouseDown = false;
CListBox::OnLButtonDown(nFlags, point);
}
else // 鼠标按下的项已被选定(可能会被拖动)...
{
m_bMouseDown = true;
GetItemRect(i, &m_rItem);
m_nCurrentItem = i;
}
}
void CMP3ListBox::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int iItem; // 鼠标当前指向的项
BOOL bOutside;
int i;
// 鼠标按在选定项并拖动出该项范围才启动拖动操作...
if (m_bMouseDown)
{
// Mouse在m_rItem的范围以外...
if (point.y < m_rItem.top || point.y > m_rItem.bottom)
{
m_bMouseDown = false;
// 启动拖动操作...
{
m_bDragging = true;
// 改变mouse指针...
// 为m_pSelItems和m_pSelValues申请空间并填充...
m_nSelCount = GetSelCount();
m_pSelItems = new int[m_nSelCount];
m_pSelValues = new CMP3ListBoxItem*[m_nSelCount];
GetSelItems(m_nSelCount, m_pSelItems);
for (i=0; i<m_nSelCount; i++)
{
*(m_pSelValues+i) = (CMP3ListBoxItem *)GetItemData(*(m_pSelItems+i));
}
}
TRACE("Drag begins!\n");
return;
}
}
TRACE("%d\n", ((::GetKeyState(VK_LBUTTON) & 0xf0) >> 4));
// 正在拖动...
if (m_bDragging)
{
// 正在拖动, 但是鼠标没有按下(可能是由于鼠标在拖动时在LISTBOX外释放)...
if (!HIWORD(::GetKeyState(VK_LBUTTON)))
{
this->OnLButtonUp(nFlags, point);
return;
}
// 判断mouse指向的项是否合法, 不合法则什么都不做...
// 不合法: iItem为当前项 或 待定项<当前项-第一选定项 或 总项数-待定项<=最后选定项-当前项
iItem = ItemFromPoint(point, bOutside);
if (iItem == m_nCurrentItem ||
iItem < m_nCurrentItem - *(m_pSelItems + 0) ||
GetCount() - iItem
<= *(m_pSelItems + m_nSelCount - 1) - m_nCurrentItem
)
{
return;
}
// 移动列表项...
if (iItem < m_nCurrentItem) // 向上移...
{
for (i=0; i<m_nSelCount; i++)
{
// 移动列表项...
CListBox::SetItemData(*(m_pSelItems+i), GetItemData(*(m_pSelItems+i)+iItem-m_nCurrentItem));
CListBox::SetItemData(*(m_pSelItems+i)+iItem-m_nCurrentItem, (DWORD)(*(m_pSelValues+i)));
// 改变选定状态...
SetSel(*(m_pSelItems+i), false);
SetSel(*(m_pSelItems+i)+iItem-m_nCurrentItem, true);
// 移动了HotItem...
if (*(m_pSelItems+i) == m_iHotItemID)
{
SetHotItem(*(m_pSelItems+i)+iItem-m_nCurrentItem);
GetParent()->SendMessage(MYWM_LISTOPENEDITEMMOVE, *(m_pSelItems+i)+iItem-m_nCurrentItem);
}
else if(*(m_pSelItems+i)+iItem-m_nCurrentItem == m_iHotItemID)
{
SetHotItem(*(m_pSelItems+i));
GetParent()->SendMessage(MYWM_LISTOPENEDITEMMOVE, *(m_pSelItems+i));
}
// 更新m_pSelItems...
*(m_pSelItems+i) += iItem-m_nCurrentItem;
}
}
else // 向下移...
{
for (i=m_nSelCount-1; i>-1; i--)
{
// 移动列表项...
CListBox::SetItemData(*(m_pSelItems+i), GetItemData(*(m_pSelItems+i)+iItem-m_nCurrentItem));
CListBox::SetItemData(*(m_pSelItems+i)+iItem-m_nCurrentItem, (DWORD)(*(m_pSelValues+i)));
// 改变选定状态...
SetSel(*(m_pSelItems+i), false);
SetSel(*(m_pSelItems+i)+iItem-m_nCurrentItem, true);
// 移动了HotItem...
if (*(m_pSelItems+i) == m_iHotItemID)
{
SetHotItem(*(m_pSelItems+i)+iItem-m_nCurrentItem);
GetParent()->SendMessage(MYWM_LISTOPENEDITEMMOVE, *(m_pSelItems+i)+iItem-m_nCurrentItem);
}
else if(*(m_pSelItems+i)+iItem-m_nCurrentItem == m_iHotItemID)
{
SetHotItem(*(m_pSelItems+i));
GetParent()->SendMessage(MYWM_LISTOPENEDITEMMOVE, *(m_pSelItems+i));
}
// 更新m_pSelItems...
*(m_pSelItems+i) += iItem-m_nCurrentItem;
}
}
// 滚动窗口...
// ...
m_nCurrentItem = iItem;
}
else
{
CListBox::OnMouseMove(nFlags, point);
}
}
void CMP3ListBox::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// 按在了选定项,但又没有拖动出该项(拖动操作没有启动)...
// 模拟正常的鼠标按下效果:只选定该项
if (m_bMouseDown)
{
BOOL bOutside;
int i=ItemFromPoint(point, bOutside);
SetSel(-1, false);
SetSel(i, true);
}
if (m_bDragging)
{
// 结束拖动...
m_bDragging = false;
// 改变mouse指针...
// 清理工作...
delete [] m_pSelItems;
delete [] m_pSelValues;
}
m_bMouseDown = false;
CListBox::OnLButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -