⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 richimp3dlg.cpp

📁 完整的MP3播放器源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        
        ::LeaveCriticalSection(&m_css);
    }
}

void CRichiMP3Dlg::OnButtonFirst() 
{
	// TODO: Add your control notification handler code here
	if(m_hThread)
    {
        ::EnterCriticalSection(&m_css);
		m_fppos  = m_fp.GetRangeMin();
		int sec;
		sec = m_fppos*m_pspf/1000;
		ef_b2.Display(0);
		ef_b3.Display(00);
			m_pFile.Goto((m_fppos * m_frmLength / 4) * 4);
        
        ::LeaveCriticalSection(&m_css);
    }
}

void CRichiMP3Dlg::OnButtonForward() 
{
	// TODO: Add your control notification handler code here
	if(m_hThread == 0)
            return;
	int nMax;
	int nMin;
	int nPos;
	nMin = m_fp.GetRangeMin();
	nMax = m_fp.GetRangeMax();
	nPos = m_fp.GetPos();
	int nDelta = (nMax - nMin)/100;
	int nNewPos;
	nNewPos = nPos;
	if((nPos - nDelta)<nMin)
		nNewPos = nMin;
	else
		nNewPos -=nDelta;
	m_fp.SetPos(nNewPos);
	::EnterCriticalSection(&m_css);
			m_fppos  = m_fp.GetPos();
			int sec;
			sec = m_fppos*m_pspf/1000;
			if(sec != 0)
			{
				ef_b2.Display(sec/60);
				ef_b3.Display(sec%60);
			}
			else
			{
				ef_b2.Display(0);
				ef_b3.Display(00);
			}

			m_pFile.Goto((m_fppos * m_frmLength / 4) * 4);
			::LeaveCriticalSection(&m_css);
}

void CRichiMP3Dlg::OnButtonList() 
{
	// TODO: Add your control notification handler code here
	if(pListDlg->GetSafeHwnd()==0)
	{
		pListDlg->Create(IDD_DIALOG_LIST);
		pListDlg->ShowWindow(SW_SHOW);
		CRect rcPosition;
		CRect rcClient;
		GetWindowRect(&rcClient);
		pListDlg->GetWindowRect(&rcPosition);
		
		pListDlg->MoveWindow(rcClient.left,rcClient.bottom,rcPosition.Width(),rcPosition.Height(),TRUE);
	}
	else if(pListDlg->IsWindowVisible())
	{
		pListDlg->ShowWindow(SW_HIDE);
	}
	else 
	{
		pListDlg->ShowWindow(SW_SHOW);
		CRect rcPosition;
		CRect rcClient;
		GetWindowRect(&rcClient);
		pListDlg->GetWindowRect(&rcPosition);
		pListDlg->MoveWindow(rcClient.left,rcClient.bottom,rcPosition.Width(),rcPosition.Height(),TRUE);
	}
	
}

void CRichiMP3Dlg::OnButtonLoop() 
{
	// TODO: Add your control notification handler code here
	bLoop = !bLoop;
	if(bLoop)
	{
//		Button10.SetIcon(IDI_LOOP1);
	//	Button10.Invalidate();
		VERIFY(btnLoop.LoadBitmaps(_T("loop1u"), "loop1d", NULL));
		btnLoop.Invalidate();
	}
	else
	{
	//	Button10.SetIcon(IDI_LOOP);
//		Button10.Invalidate();
		VERIFY(btnLoop.LoadBitmaps(_T("loopu"), "loopd", NULL));
		btnLoop.Invalidate();
	}
}

void CRichiMP3Dlg::OnButtonPause() 
{
	// TODO: Add your control notification handler code here
	if(m_hThread == 0)
		return;
	
	if(bPause)
	{
		nCurPos = m_fp.GetPos();//.GetNumber(nPos);
		bStop = TRUE;
	   ::EnterCriticalSection(&m_css);
        m_break = TRUE;
        ::LeaveCriticalSection(&m_css);
		
	}
	else
	{
		::EnterCriticalSection(&m_css);
			m_fppos  = nCurPos;
		//	ef_b2.Display(m_fp.GetPos());
			int sec;
			sec = m_fppos*m_pspf/1000;
			if(sec != 0)
			{
				ef_b2.Display(sec/60);
				ef_b3.Display(sec%60);
			}
			else
			{
				ef_b2.Display(0);
				ef_b3.Display(00);
			}
			m_pFile.Goto((m_fppos * m_frmLength / 4) * 4);
			::LeaveCriticalSection(&m_css);
	//	m_pFile.Goto((nCurPos * m_frmLength / 4) * 4);

	}
	bPause = !bPause;
}

void CRichiMP3Dlg::OnButtonPlay() 
{
	// TODO: Add your control notification handler code here
	if(m_list.GetCount() == 0 || m_list.GetCurSel() <0)
	{
		AfxMessageBox("请选择播放文件",MB_OK|MB_ICONINFORMATION);
		m_list.SetFocus();
		return;
	}

    if(m_hThread)
    {
		AfxGetApp()->DoWaitCursor(TRUE);
		m_ignoreMsg = TRUE;
        if(!StopPlay())
			m_ignoreMsg = FALSE;
		ResetUI();
        m_fp.SetPos(0);
//		ef_b2.Display(0);
		
        m_fppos = 0;
        
		int sec;
		sec = m_fppos*m_pspf/1000;
		if(sec != 0)
		{
				ef_b2.Display(sec/60);
				ef_b3.Display(sec%60);
		}
		else
		{
				ef_b2.Display(0);
				ef_b3.Display(00);
		}
		m_play = FALSE;
		bStop = TRUE;
		AfxGetApp()->DoWaitCursor(FALSE);
		
    }
    else
    {
			StartPlay();
    }
}

void CRichiMP3Dlg::OnButtonStop() 
{
	// TODO: Add your control notification handler code here
	bStop = !bStop;
	StopPlay();
}

void CRichiMP3Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
/*	CRect rc1;
	CRect rc2;
	CRect rc3;
	CRect rc4;
	GetDlgItem(IDC_STATIC_P1)->GetWindowRect(&rc1);
	GetDlgItem(IDC_STATIC_P2)->GetWindowRect(&rc2);
	GetDlgItem(IDC_STATIC_P3)->GetWindowRect(&rc3);
	GetDlgItem(IDC_STATIC_P4)->GetWindowRect(&rc4);
	ScreenToClient(&rc1);
	ScreenToClient(&rc2);
	ScreenToClient(&rc3);
	ScreenToClient(&rc4);*/
	CRect rcCaption;
	GetClientRect(&rcCaption);
	rcCaption = CRect(rcCaption.left+14,rcCaption.top,rcCaption.right-25,rcCaption.bottom);
	//ScreenToClient(&rcCaption);
/*	if(rc3.PtInRect(point))
	{
		
		return;
	}
	if(rc4.PtInRect(point))
	{
		
		return;
	}
	if(rc2.PtInRect(point))
	{
		return;
	}
	if(rc1.PtInRect(point))
	{
		
			return;
		//PostMessage(WM_SYSCOMMAND,SC_MINIMIZE);
	}*/
	if(rcCaption.PtInRect(point))
	{
		
		SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
		if(pListDlg->GetSafeHwnd()!=0)
		{
			pListDlg->SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
		}
		if(pEqDlg->GetSafeHwnd()!=0)
		{
			pEqDlg->SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
		}
	}
	CBitmapDialog::OnLButtonDown(nFlags, point);
}

void CRichiMP3Dlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
/*	CRect rc1;
	CRect rc2;
	CRect rc3;
	CRect rc4;
	GetDlgItem(IDC_STATIC_P1)->GetWindowRect(&rc1);
	GetDlgItem(IDC_STATIC_P2)->GetWindowRect(&rc2);
	GetDlgItem(IDC_STATIC_P3)->GetWindowRect(&rc3);
	GetDlgItem(IDC_STATIC_P4)->GetWindowRect(&rc4);
	ScreenToClient(&rc1);
	ScreenToClient(&rc2);
	ScreenToClient(&rc3);
	ScreenToClient(&rc4);
	if(rc3.PtInRect(point))
	{
		PostMessage(WM_SYSCOMMAND,SC_MINIMIZE);
		return;
	}
	if(rc4.PtInRect(point))
	{
		PostMessage(WM_SYSCOMMAND,SC_CLOSE);
		return;
	}
	if(rc2.PtInRect(point))
	{
		theApp.WinHelp(0, HELP_FINDER);
		return;
	}
	if(rc1.PtInRect(point))
	{
		RECT rCopy;
			CopyRect(&rCopy,&rc3);
			CMenu cm,*pm;
			cm.LoadMenu(IDR_SYS);
			pm = cm.GetSubMenu(0);
			ClientToScreen(&rCopy);
			pm->TrackPopupMenu(TPM_LEFTALIGN,rCopy.left-3,rCopy.bottom-2,
								this);
			cm.DestroyMenu();
			return;
		//PostMessage(WM_SYSCOMMAND,SC_MINIMIZE);
	}*/
	CBitmapDialog::OnLButtonUp(nFlags, point);
}

void CRichiMP3Dlg::OnButtonClose() 
{
	// TODO: Add your control notification handler code here
	PostMessage(WM_SYSCOMMAND,SC_CLOSE);
}

void CRichiMP3Dlg::OnButtonAbout() 
{
	// TODO: Add your control notification handler code here

    CAboutDlg aboutDlg;
	aboutDlg.DoModal();
	
}

void CRichiMP3Dlg::OnButtonMin() 
{
	// TODO: Add your control notification handler code here
	PostMessage(WM_SYSCOMMAND,SC_MINIMIZE);
		
}

void CRichiMP3Dlg::OnButtonHelp() 
{
	// TODO: Add your control notification handler code here
	theApp.WinHelp(0, HELP_FINDER);
		
}
LRESULT CRichiMP3Dlg::OnFileChanged(WPARAM wParam, LPARAM lParam)
{
	if(pListDlg->GetSafeHwnd() != 0)
	{
		int nSel1 = pListDlg->nCurSel;
		UpdateListBox1();
		CListBox *pListBox = (CListBox *)GetDlgItem(IDC_LIST2);
		pListBox->SetCurSel(nSel1);

	}
	return 0L;
}
LRESULT CRichiMP3Dlg::OnIdUpdate(WPARAM wParam, LPARAM lParam)
{
	if(pListDlg->GetSafeHwnd() != 0)
	{
		CListBox *pListBox = (CListBox *)GetDlgItem(IDC_LIST2);
		CPictureObject *pFileObj = pListDlg->pFileObject;
		int idx1 = pListDlg->nCurSel;
		pListBox->SetCurSel(pListDlg->nCurSel);
		if(m_playIdx == idx1)
        return 0L;
		m_playIdx = idx1;
		
		m_ignoreMsg = TRUE;
		if(!StopThread())
		m_ignoreMsg = FALSE;
		ResetUI();

		StartPlay();
	//	AfxMessageBox(pFileObj->GetFileName());
	}
	
	return 0L;
}

void CRichiMP3Dlg::OnDestroy() 
{
	CBitmapDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	m_ignoreMsg = TRUE;
    StopThread();
//	::DeleteObject(m_hbrDlg);
    DeleteCriticalSection(&m_css);    
    m_scope->DestroyWindow();
}
BOOL    CRichiMP3Dlg::StartThread(LPCSTR pFileName)
{
    
    //TRACE("Start\r\n");
    DWORD dw;
    
    ::EnterCriticalSection(&m_css);
    m_break = FALSE;
    ::LeaveCriticalSection(&m_css);


    m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)PlayThread,
                            (void*)this,
                            0,
                            &dw); 
    
    return (m_hThread != 0);

}
int CRichiMP3Dlg::PlayThread(void* pData)
{
    
    ((CRichiMP3Dlg*)pData)->TheadFn();
    return 9; 
}
LRESULT CRichiMP3Dlg::OnFilePlayed(WPARAM wp, LPARAM lp)
{
	if(m_ignoreMsg)
    {
        m_ignoreMsg =FALSE;
        return 0L;
    }
    
    Sleep(600);
	if(0 != m_hThread)
    {
        WaitForSingleObject(m_hThread,INFINITE);
    }
    m_pFile.Close();
    m_Mci.Close();
    CloseHandle(m_hThread);
    m_hThread = 0;


    ResetUI();

	if(bLoop)
	{
	}
	else if(++m_playIdx  > (m_list.GetCount()-1))
    {
        m_playIdx = 0;
    }
    m_list.SetCurSel(m_playIdx);
	if(pListDlg->GetSafeHwnd() != 0)
	{
		pListDlg->nCurSel = m_playIdx;
		pListDlg->SendMessage(WM_PLAYCHANGED);
	}
    OnButtonPlay();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -