mfc播放器mfc播放器
class CMyApp:public CWinApp{
public:
virtual BOOL InitInstance();};
class CMainWindow:public CFrameWnd
{
public:
afx_msg void OnMouseMove(UINT nFlags,CPoint point);
protected:
HWND m_hMyMCIWnd;
CListBox ListBox1;
CButton btn;
CButton btn1;
CButton btn2;
CBu...
mfc播放器
class CMyApp:public CWinApp{
public:
virtual BOOL InitInstance();};
class CMainWindow:public CFrameWnd
{
public:
afx_msg void OnMouseMove(UINT nFlags,CPoint point);
protected:
HWND m_hMyMCIWnd;
CListBox ListBox1;
CButton btn;
CButton btn1;
CButton btn2;
CButton btn3;
CButton clo;
CButton open;
CButton loop;
CButton loop1;
CButton loop2;
CButton loop3;
CPalette m_palette;
void DoGradientFill(CDC* pDC,LPRECT pRect);
CString GetSuffix(CString strFileName);
CBrush m_brRedBrush;CBrush m_brush;
CFont font;
CFont font1;
int x,y;
int h;
int work;
int xop,yop;
CString FileString;public:
CMainWindow();
protected:
static const TCHAR szFilters1[];
static const TCHAR szFilters2[];
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnLButtonUp(UINT nFlags,CPoint point);afx_msg BOOL OnMouseWheel(UINT nFlags,short zDelta,CPoint point);
afx_msg int OnCreate(LPCREATESTRUCT lpcs);afx_msg LRESULT OnMCINotify(WPARAM wParam,LPARAM lParam);
afx_msg void OnBtnClick();
afx_msg void OnBtnClick1();
afx_msg void OnBtnClick2();
afx_msg void OnBtnClick3();
afx_msg void OnBtnClick4();
afx_msg void OnBtnClick5();
afx_msg void OnCheckClick();
afx_msg void OnCheckClick1();
afx_msg void OnCheckClick2();
afx_msg void OnCheckClick3();
afx_msg void OnTimer(UINT nTimerID);afx_msg void OnSize(UINT nType,int cx,int cy);afx_msg BOOL OnEraseBkgnd(CDC* pDC);afx_msg HBRUSH OnCtlColor(CDC* pDC,CWnd *pWnd,UINT nCtlColor);
DECLARE_MESSAGE_MAP()
};
//代码窗体Player.cpp
#include
#include "Player.h"
#include "VolumeControl.h"
#include
#include
#include "math.h"
#pragma comment(lib,"vfw32.lib")
#define IDC_LISTBOX 1000
#define IDC_OPEN 1001
#define IDC_OPEN1 1002
#define IDC_OPEN2 1003
#define IDC_OPEN3 1004
#define IDC_OPEN4 1007
#define IDC_CLOSE 1005
#define IDC_MAIN 1006
#define IDC_CHECK 1008
#define IDC_CHECK1 1009
#define IDC_CHECK2 1010
#define IDC_CHECK3 1011
CMyApp myApp;
const TCHAR CMainWindow::szFilters1[]=_T("Sound Files (*.mp3) | *.mp3|
All Files (*.*) | *.*||");
const TCHAR CMainWindow::szFilters2[]=_T("Movie Files (*.avi) | *.avi|All
Files (*.*) | *.*||");
UINT nSound;
CString str1,str,name,filename;
int sign=1,nVolume,length,count=0;ControlWindow *con;
BOOL
Eloop=FALSE,Eloop1=FALSE,Eloop2=FALSE,flag=FALSE,Eloop3=FALSE;
int Index=0;
BOOL CMyApp::InitInstance()
{
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)ON_WM_CREATE()
ON_BN_CLICKED(IDC_OPEN,OnBtnClick)ON_BN_CLICKED(IDC_OPEN1,OnBtnClick1)ON_BN_CLICKED(IDC_OPEN2,OnBtnClick2)ON_BN_CLICKED(IDC_OPEN3,OnBtnClick3)
ON_BN_CLICKED(IDC_CLOSE,OnBtnClick4)ON_BN_CLICKED(IDC_OPEN4,OnBtnClick5) ON_BN_CLICKED(IDC_CHECK,OnCheckClick)ON_BN_CLICKED(IDC_CHECK1,OnCheckClick1)ON_BN_CLICKED(IDC_CHECK2,OnCheckClick2)ON_BN_CLICKED(IDC_CHECK3,OnCheckClick3)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
ON_WM_SIZE()
ON_WM_TIMER()
ON_WM_MOUSEWHEEL()
ON_MESSAGE(MCIWNDF_NOTIFYMODE,OnMCINotify)ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
CMainWindow::CMainWindow()
{
Create(NULL,_T("Player"),WS_POPUPWINDOW,CRect(100,100,620,610),this);
}
int CMainWindow::OnCreate(LPCREATESTRUCT lpcs)
{
if (CFrameWnd::OnCreate(lpcs)==-1)
return -1;
//CoInitializeEx
CClientDC dc(this);
::SetWindowPos(m_hWnd,HWND_TOPMOST,100,100,620,610,WS_EX_TOPMO
ST);
con=new ControlWindow();
//con->ShowWindow(SW_SHOW);
if (dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
{
struct{
LOGPALETTE lp;
PALETTEENTRY ape[63];
}pal;
LOGPALETTE* pLP=(LOGPALETTE*) &pal;
pLP->palVersion=0x300;
pLP->palNumEntries=64;
for (int i=0;i<64;i++)
{
pLP->palPalEntry[i].peRed=0;
pLP->palPalEntry[i].peGreen=0;
pLP->palPalEntry[i].peBlue=255-(i*4);
pLP->palPalEntry[i].peFlags=0;
}
m_palette.CreatePalette(pLP);
}
font1.CreatePointFont(80,_T("MS Sans Serif"));CRect rect;
rect.SetRect(110,450,210,465);
loop.Create("码曲循码",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,rect,this,IDC_CHECK);loop.SetFont(&font1);
rect.SetRect(110,470,210,485);
loop1.Create("列表循码",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,rect,this,IDC_CHECK1);loop1.SetFont(&font1);
rect.SetRect(200,450,300,465);
loop2.Create("码曲播放",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,rect,this,IDC_CHECK2);loop2.SetFont(&font1);
loop2.SetCheck(BST_CHECKED);
rect.SetRect(200,470,300,485);
loop3.Create("码序播放",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,rect,this,IDC_CHECK3);loop3.SetFont(&font1);
rect.SetRect(10,444,50,484);
clo.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON |
BS_ICON | WS_BORDER,rect,this,IDC_CLOSE);clo.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON5")));rect.SetRect(460,444,500,484);
open.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON |
BS_ICON | WS_BORDER,rect,this,IDC_OPEN4);open.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON7")));rect.SetRect(300,444,340,484);
btn.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON |
BS_ICON | WS_BORDER,rect,this,IDC_OPEN);btn.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON1")));
rect.SetRect(340,444,380,484);
btn2.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON | WS_BORDER,rect,this,IDC_OPEN2);
btn2.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON3")));rect.SetRect(380,444,420,484);
btn1.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON | WS_BORDER,rect,this,IDC_OPEN1);
btn1.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON2")));rect.SetRect(420,444,460,484);
btn3.Create(NULL,WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON | WS_BORDER,rect,this,IDC_OPEN3);
btn3.SetIcon(AfxGetApp()->LoadIcon(_T("IDI_ICON4")));//bitmap.m_hObject=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"b.bmp",I
MAGE_BITMAP,110,40,LR_LOADFROMFILE);
//CClientDC dc1(this);
//CBitmap bitmap;
//bitmap.LoadBitmap(_T("IDB_BITMAP1"));
//CBrush brush(&bitmap);
//dc1.FillRect(CRect(390,445,500,485),&brush);rect.SetRect(370,5,505,430);
ListBox1.Create(WS_CHILD | WS_VISIBLE | LBS_STANDARD | WS_BORDER ,rect,this,IDC_LISTBOX);
font.CreatePointFont(100,_T("MS Scans Serif"));
ListBox1.SetFont(&font);
if (!MCIWndRegisterClass()){
MessageBox("初始化未成功");
}
//m_hMyMCIWnd=MCIWndCreate(this-
>m_hWnd,AfxGetInstanceHandle(),MCIWNDF_NOTIFYSIZE | MCIWNDF_NOERRORDLG | MCIWNDF_NOTIFYMODE | WS_CHILD | WS_VISIBLE | WS_BORDER | MCIWNDF_NOMENU,NULL);//m_hMyMCIWnd=MCIWndCreate(this-
>GetSafeHwnd(),AfxGetInstanceHandle(),WS_CHILD | WS_VISIBLE | MCIWNDF_NOPLAYBAR | MCIWNDF_NOMENU |
MCIWNDF_NOTIFYMODE | WS_BORDER,NULL);
//nVolume=MCIWndGetVolume(m_hMyMCIWnd);
}
BOOL CMainWindow::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);
::SetWindowPos(m_hMyMCIWnd,NULL,3,3,3,3,SWP_NOZORDER); CPalette* pOldPalette;
if ((HPALETTE)m_palette!=NULL){
pOldPalette=pDC->SelectPalette(&m_palette,FALSE);
pDC->RealizePalette();
}
DoGradientFill(pDC,&rect);
if ((HPALETTE) m_palette!=NULL)
pDC->SelectPalette(pOldPalette,FALSE);
return TRUE;
}
void CMainWindow::OnBtnClick1()
{
ListBox1.DeleteString(ListBox1.GetCurSel());}
void CMainWindow::OnBtnClick2()
{
CFileDialog dlg(TRUE,_T("avi"),_T("*.avi"),OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,szFilters2);
if (dlg.DoModal()==IDOK){
m_hMyMCIWnd=MCIWndCreate(this-
>GetSafeHwnd(),AfxGetInstanceHandle(),WS_CHILD | WS_VISIBLE | MCIWNDF_NOPLAYBAR | MCIWNDF_NOMENU |
MCIWNDF_NOTIFYMODE | WS_BORDER,NULL);
nVolume=MCIWndGetVolume(m_hMyMCIWnd);
name=dlg.GetFileName();
MCIWndStop(m_hMyMCIWnd);
ListBox1.AddString(name);
filename=name;
if (filename.GetLength()>0 && GetSuffix(filename)=="avi"){
nSound=MCIWndOpen(m_hMyMCIWnd,(LPCSTR)filename,NULL);
::SetWindowPos(m_hMyMCIWnd,NULL,3,3,400,400,SWP_NOZORDER);
HRGN hRgn1=::CreateRoundRectRgn(3,3,400,400,20,20);
::SetWindowRgn(m_hMyMCIWnd,hRgn1,TRUE);
if (nSound==0)
{
MCIWndPlay(m_hMyMCIWnd);
con->m_slider.EnableWindow(TRUE);
con->m_slider1.EnableWindow(TRUE);
SetTimer(1,1000,NULL);
}
}
else{
//MCIWndDestroy(m_hMyMCIWnd);
MessageBox(_T("有码出文件没"),0,MB_OK);
}
}
}
void CMainWindow::OnBtnClick3(){
for(int i=0;iCloseWindow();
this->DestroyWindow();
}
void CMainWindow::OnBtnClick5(){
count++;
if (count%2==0){
con->ShowWindow(SW_SHOW);
open.SetIcon(AfxGetApp()->LoadIcon("IDI_ICON7"));
}
else{
con->ShowWindow(SW_HIDE);
open.SetIcon(AfxGetApp()->LoadIcon("IDI_ICON8"));
}
}
void CMainWindow::OnBtnClick()
{
CFileDialog dlg(TRUE,_T("mp3"),_T("*.mp3"),OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,szFilters1);
if (dlg.DoModal()==IDOK){
m_hMyMCIWnd=MCIWndCreate(this-
>GetSafeHwnd(),AfxGetInstanceHandle(),WS_CHILD | WS_VISIBLE | MCIWNDF_NOPLAYBAR | MCIWNDF_NOMENU |
MCIWNDF_NOTIFYMODE | WS_BORDER,NULL);
nVolume=MCIWndGetVolume(m_hMyMCIWnd);
name=dlg.GetFileName();
MCIWndStop(m_hMyMCIWnd);
ListBox1.AddString(name);
filename=name;
if (filename.GetLength()>0 && GetSuffix(filename)=="mp3"){
nSound=MCIWndOpen(m_hMyMCIWnd,(LPCSTR)filename,NULL);
if (nSound==0){
MCIWndPlay(m_hMyMCIWnd);
con->m_slider.EnableWindow(TRUE);
con->m_slider1.EnableWindow(TRUE);
SetTimer(1,1000,NULL);
}
}
else{
//MCIWndDestroy(m_hMyMCIWnd);
MessageBox(_T("有码出文件没"),0,MB_OK);
}
}
}
CString CMainWindow::GetSuffix(CString strFileName) {
return strFileName.Right(strFileName.GetLength()-strFileName.ReverseFind('.')-1);
}
LRESULT CMainWindow::OnMCINotify(WPARAM wParam,LPARAM lParam)
{
if(wParam==MCI_MODE_STOP)
{
MessageBox("码束");
//MCIWndDestroy(m_hMyMCIWnd);
}
return TRUE;
}
void CMainWindow::DoGradientFill(CDC* pDC,LPRECT pRect)
{
CBrush *brush3[255];
TRY{
CBrush* pBrush[64];
for (int i=0;i<64;i++)
pBrush[i]=new CBrush(PALETTERGB(255-(i*4),0,0));int nWidth=pRect->right-pRect->left;int nHeight=pRect->bottom-pRect->top;CRect rect;
for (int i=0;iFillRect(&rect,pBrush[(i*63)/nHeight]);}
for (int i=0;i<64;i++)
delete pBrush[i];
pDC->SetBkMode(TRANSPARENT);
CBrush brush1(RGB(223,108,215));
pDC->FillRect(CRect(5,400,365,410),&brush1);pDC->SetTextColor(RGB(h,125,32));
pDC->TextOut(120,20+h,FileString,FileString.GetLength());
pDC->TextOut(50,380,str,str.GetLength());pDC->TextOut(5,380,str1,str1.GetLength());CBrush brush(RGB(0,0,0));
pDC->FillRect(CRect(0,440,520,490),&brush);
CBrush br1(RGB(32,235,123));
pDC->FillRect(CRect(70,445,78,485),&br1);HICON hIcon=AfxGetApp()->LoadIcon("IDI_ICON6");pDC->DrawIcon(10,450,hIcon);
pDC->StretchBlt(83,445,16,16,pDC,10,450,36,36,SRCCOPY); CBrush br(RGB(255,0,0));
pDC->FillRect(CRect(71,486-((nVolume*40)/1000),77,484),&br);for (int i=0;i<255;i++){
brush3[i]=new CBrush(PALETTERGB(255-i,255-i,i));}
for (int j=0;j<255;j++){
pDC->FillRect(CRect(6+j,401,110+j,408.9),brush3[j]);}
CBrush brush4(RGB(223,108,215));
pDC->FillRect(CRect(5+work,401,365,408.9),&brush4);for (int i=0;i<255;i++){
delete brush3[i];
}
}CATCH (CException,e){
this->DestroyWindow();
this->CloseWindow();
}
END_CATCH
}
void CMainWindow::OnLButtonDown(UINT nFlags,CPoint point){
flag=TRUE;
x=point.x;
y=point.y;
}
void CMainWindow::OnLButtonUp(UINT nFlags, CPoint point){
flag=FALSE;
}
void CMainWindow::OnMouseMove(UINT nFlags, CPoint point) {
if (flag){
CRect rect;
::GetWindowRect(m_hWnd,rect);
//CRect rect1;
//con->GetWindowRect(rect1);
xop=rect.left+point.x-x;
yop=rect.top+point.y-y;
::SetWindowPos(m_hWnd,NULL,xop,yop,rect.Width(),rect.Height(),SWP_NOSIZ
E);
//if ((rect1.left>rect.left+point.x-x && rect1.leftrect.top+point.y-y+rect.Height()-9 && rect.topm_hWnd,NULL,rect.left+point.x-x+3,rect.top+point.y-y+rect.Height()-9,513,293,SWP_NOZORDER);
//}
}
}
BOOL CMainWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
CClientDC dc(this);
if (zDelta>0){
if (nVolume<1000){
nVolume+=20;
}
}
else{
if (nVolume>0){
nVolume-=20;
}
}
MCIWndSetVolume(m_hMyMCIWnd,nVolume);
return TRUE;
}
void CMainWindow::OnCheckClick(){
if (loop.GetCheck()==BST_CHECKED){
SetTimer(3,1000,NULL);
KillTimer(5);
KillTimer(2);
KillTimer(4);
loop.SetCheck(BST_CHECKED);
Eloop=TRUE;
}
}
void CMainWindow::OnCheckClick1(){
if (loop1.GetCheck()==BST_CHECKED){
SetTimer(2,1000,NULL);
KillTimer(5);
KillTimer(3);
KillTimer(4);
loop1.SetCheck(BST_CHECKED);
Eloop1=TRUE;
}
}
void CMainWindow::OnCheckClick2(){
if (loop2.GetCheck()==BST_CHECKED){
SetTimer(4,1000,NULL);
KillTimer(5);
KillTimer(3);
KillTimer(2);
loop2.SetCheck(BST_CHECKED);
Eloop2=TRUE;
}
}
void CMainWindow::OnCheckClick3(){
if (loop3.GetCheck()==BST_CHECKED){
SetTimer(5,1000,NULL);
KillTimer(4);
KillTimer(3);
KillTimer(2);
loop3.SetCheck(BST_CHECKED);
Eloop3=TRUE;
}
}
void CMainWindow::OnSize(UINT nType,int cx,int cy){
CRect rect;
CFrameWnd::OnSize(nType,cx,cy);
HRGN hRgn1=::CreateRoundRectRgn(3,3,515,500,20,20);::SetWindowRgn(m_hWnd,hRgn1,TRUE);
::SetWindowPos(m_hMyMCIWnd,NULL,3,3,cx-150,cy-120,SWP_NOZORDER);HRGN hRgn2=::CreateRectRgn(3,3,cx-150,cy-150);::SetWindowRgn(m_hMyMCIWnd,hRgn2,TRUE);
//CWnd* pWnd1=GetDlgItem(IDC_LISTBOX);
//pWnd1->SetWindowPos(NULL,cx-145,5,140,cy-70,SWP_NOZORDER);//CWnd* pWnd2=GetDlgItem(IDC_OPEN);
//pWnd2->SetWindowPos(NULL,cx-160,cy-60,cx,cy,SWP_NOSIZE);}
void CMainWindow::OnTimer(UINT nTimerID)
{
if (nTimerID==1){
CClientDC dc(this);
CTime
tm((((MCIWndGetPosition(m_hMyMCIWnd)*60)/MCIWndGetLength(m_hMyMCIWnd) )/60),
(((MCIWndGetPosition(m_hMyMCIWnd)*60)/MCIWndGetLength(m_hMyMCIWnd))%60));
str1=tm.Format("%M:%S");
work=((360*MCIWndGetPosition(m_hMyMCIWnd))/MCIWndGetLength(m_hMyMCIWnd));
CString str;
str.Format("%d",work);
//MessageBox(str);
CTime t((3600/MCIWndGetLength(m_hMyMCIWnd))*60,(1/MCIWndGetLength(m_hMyMCIWnd)));
str=t.Format("%M:%S");
length=(255*MCIWndGetPosition(m_hMyMCIWnd))/MCIWndGetLength(m_hM
yMCIWnd);
h+=20*sign;
if (abs(177-h)>=177)
{
sign=sign*(-1);
}
Invalidate(TRUE);
}
else if (nTimerID==2)
{
if (Eloop1){
if
(MCIWndGetPosition(m_hMyMCIWnd)==MCIWndGetEnd(m_hMyMCIWnd)){
if (Indexm_hWnd){
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkColor(RGB(123,128,248));
m_brRedBrush.CreateSolidBrush(RGB(123,128,248));
return (HBRUSH) m_brRedBrush;
}
else if (loop.m_hWnd==pWnd->m_hWnd){
pDC->SetTextColor(RGB(255,255,255)); pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brRedBrush=(HBRUSH)::GetStockObject(NULL_BRUSH);
return (HBRUSH) m_brRedBrush;
}
else if (loop1.m_hWnd==pWnd->m_hWnd){
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brRedBrush=(HBRUSH)::GetStockObject(NULL_BRUSH);
return (HBRUSH) m_brRedBrush;
}
else if (loop2.m_hWnd==pWnd->m_hWnd){
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brRedBrush=(HBRUSH)::GetStockObject(NULL_BRUSH);
return (HBRUSH) m_brRedBrush;
}
else if (loop3.m_hWnd==pWnd->m_hWnd){
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brRedBrush=(HBRUSH)::GetStockObject(NULL_BRUSH);
return (HBRUSH) m_brRedBrush;
}
}
//码源代码
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.// Used by Player.rc
//
// Next default values for new objects//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 112#define _APS_NEXT_COMMAND_VALUE 40001#define _APS_NEXT_CONTROL_VALUE 1001#define _APS_NEXT_SYMED_VALUE 101#endif
#endif
//音量控制码代码VolumeControl.h
#include
class ControlWindow:public CFrameWnd{
public:
CSliderCtrl m_slider;
CSliderCtrl m_slider1;
protected:
int x,y;
CPalette m_palette;
int SetVolume(int left,int right);
int SetVol(int dwVolume);
void DoGradientFill(CDC* pDC,LPRECT pRect);public:
ControlWindow();
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpcs);afx_msg void OnMouseMove(UINT nFlags,CPoint point); afx_msg void OnLButtonDown(UINT nFlags,CPoint point);afx_msg void OnLButtonUp(UINT nFlags,CPoint point);afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg HBRUSH OnCtlColor(CDC* pDC,CWnd *pWnd,UINT nCtlColor);
afx_msg void OnHScroll(UINT nSBCode,UINT nPos,CScrollBar *pScrollBar);
DECLARE_MESSAGE_MAP()
};
//音量控制子口代码窗VolumeControl.cpp
#include
#include
#include "VolumeControl.h"
#include
#define IDC_CONTROL 1000
#define IDC_VOLUME 1001
#define MAX_VOL_VALUE 65535
BOOL flags=FALSE;
BEGIN_MESSAGE_MAP(ControlWindow,CFrameWnd)ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_CTLCOLOR()
ON_WM_HSCROLL()
END_MESSAGE_MAP()
ControlWindow::ControlWindow()
{
Create(NULL,_T("VolumeControl"),WS_POPUPWINDOW,CRect(100,100,620,40
0));
}
BOOL ControlWindow::OnEraseBkgnd(CDC *pDC){
CRect rect;
GetClientRect(&rect);
CPalette* pOldPalette;
if ((HPALETTE)m_palette!=NULL){
pOldPalette=pDC->SelectPalette(&m_palette,FALSE);
pDC->RealizePalette();
}
DoGradientFill(pDC,&rect);
if ((HPALETTE) m_palette!=NULL)
pDC->SelectPalette(pOldPalette,FALSE);return TRUE;
}
int ControlWindow::OnCreate(LPCREATESTRUCT lpcs) {
if (CFrameWnd::OnCreate(lpcs)==-1){
return -1;
}
HRGN hRgn=::CreateRoundRectRgn(3,3,510,290,20,20);::SetWindowRgn(m_hWnd,hRgn,TRUE);
m_slider.Create(WS_VISIBLE |
TBS_ENABLESELRANGE,CRect(120,50,400,80),this,IDC_CONTROL);
m_slider.SetRange(0, MAX_VOL_VALUE, TRUE);m_slider.SetTic(MAX_VOL_VALUE/2);
m_slider.SetPos(MAX_VOL_VALUE/2);
m_slider.EnableWindow(FALSE);
m_slider1.Create(WS_VISIBLE |
TBS_ENABLESELRANGE,CRect(120,100,400,130),this,IDC_VOLUME);
m_slider1.SetRange(0, MAX_VOL_VALUE, TRUE);m_slider1.SetPos(MAX_VOL_VALUE/2);m_slider1.SetTic(MAX_VOL_VALUE/2);m_slider1.EnableWindow(FALSE);
CClientDC dc(this);
if (dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE){
struct{
LOGPALETTE lp;
PALETTEENTRY ape[63];
}pal;
LOGPALETTE* pLP=(LOGPALETTE*) &pal;
pLP->palVersion=0x300;
pLP->palNumEntries=64;
for (int i=0;i<64;i++)
{
pLP->palPalEntry[i].peRed=0;
pLP->palPalEntry[i].peGreen=0;
pLP->palPalEntry[i].peBlue=255-(i*4); pLP->palPalEntry[i].peFlags=0;
}
m_palette.CreatePalette(pLP);}
return 0;
}
void ControlWindow::OnLButtonDown(UINT nFlags,CPoint point)
{
flags=TRUE;
x=point.x;
y=point.y;
}
void ControlWindow::OnMouseMove(UINT nFlags,CPoint point)
{
if (flags){
CRect rect;
::GetWindowRect(m_hWnd,rect);
::SetWindowPos(m_hWnd,NULL,rect.left+point.x-x,rect.top+point.y-
y,rect.Width(),rect.Height(),SWP_NOSIZE); }
}
void ControlWindow::OnLButtonUp(UINT nFlags, CPoint point){
flags=FALSE;
}
int ControlWindow::SetVolume(int left,int right){
DWORD newVol=(DWORD)MAKEWPARAM(left,right);int err=::waveOutSetVolume((HWAVEOUT)WAVE_MAPPER,newVol);if(err!=0){
return err;
}
}
int ControlWindow::SetVol(int dwVolume)
{
MMRESULT result;
HMIXER hMixer;
MIXERLINE ml={0};
MIXERLINECONTROLS mlc={0};
MIXERCONTROL mc={0};
MIXERCONTROLDETAILS mcd={0};
MIXERCONTROLDETAILS_UNSIGNED mcdu={0};
result=mixerOpen(&hMixer,MIXER_OBJECTF_MIXER,0,0,0);if (MMSYSERR_NOERROR==result){
ml.cbStruct=sizeof(MIXERLINE);
ml.dwComponentType=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
result=mixerGetLineInfo((HMIXEROBJ)hMixer,&ml,MIXER_GETLINEINFOF_
COMPONENTTYPE);
if (MMSYSERR_NOERROR==result){
mlc.cbStruct=sizeof(MIXERLINECONTROLS);
mlc.dwLineID=ml.dwLineID;
mlc.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME;
mlc.cControls=1;
mlc.pamxctrl=&mc;
mlc.cbmxctrl=sizeof(MIXERCONTROL);
result=mixerGetLineControls((HMIXEROBJ)hMixer,&mlc,MIXER_GETLINECO
NTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR==result){
mcdu.dwValue=dwVolume;
mcd.cbStruct=sizeof(MIXERCONTROLDETAILS);
mcd.hwndOwner=0;
mcd.dwControlID=mc.dwControlID;
mcd.paDetails=&mcdu;
mcd.cbDetails=sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mcd.cChannels=1;
result=mixerSetControlDetails((HMIXEROBJ)hMixer,&mcd,MIXER_SETCONTR
OLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == result)
return 1;
else
AfxMessageBox("mixerSetControlDetails() failed"); }else
AfxMessageBox("mixerGetLineControls() failed");
}else
AfxMessageBox("mixerGetLineInfo() failed");
mixerClose(hMixer);
}else
AfxMessageBox("mixerOpen() failed");return 0;
}
void ControlWindow::OnHScroll(UINT nSBCode,UINT nPos,CScrollBar
*pScrollBar)
{
CSliderCtrl *pSlider=(CSliderCtrl *)pScrollBar;int nValue= pSlider->GetPos();
if (m_slider.m_hWnd==pSlider->m_hWnd){
if (nPos>MAX_VOL_VALUE/2)
SetVolume(MAX_VOL_VALUE-nValue,nValue); else if(nPosm_hWnd){
SetVol(nValue);
}
}
HBRUSH ControlWindow::OnCtlColor(CDC *pDC,CWnd *pWnd,UINT
nCtlColor)
{
CFrameWnd::OnCtlColor(pDC,pWnd,nCtlColor);
if (m_slider.m_hWnd==pWnd->m_hWnd){
pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brush=(HBRUSH)::GetStockObject(NULL_BRUSH);
m_brush=CreateSolidBrush(RGB(168,168,168));
return m_brush;
}
else if (m_slider1.m_hWnd==pWnd->m_hWnd){
pDC->SetBkMode(TRANSPARENT);
HBRUSH m_brush=(HBRUSH)::GetStockObject(NULL_BRUSH);
m_brush=CreateSolidBrush(RGB(168,168,168));
return m_brush;
}
}
void ControlWindow::DoGradientFill(CDC* pDC,LPRECT pRect)
{
CBrush *brush3[255];
TRY{
CBrush* pBrush[64];
for (int i=0;i<64;i++)
pBrush[i]=new CBrush(PALETTERGB(255-(i*4),0,0));
int nWidth=pRect->right-pRect->left;
int nHeight=pRect->bottom-pRect->top; CRect rect;
for (int i=0;iFillRect(&rect,pBrush[(i*63)/nHeight]);
}
for (int i=0;i<64;i++)
delete pBrush[i];
HICON hIcon2=AfxGetApp()->LoadIcon("IDI_ICON3");
pDC->DrawIcon(80,50,hIcon2);
HICON hIcon1=AfxGetApp()->LoadIcon("IDI_ICON6");
pDC->DrawIcon(80,100,hIcon1);
}CATCH (CException,e){
this->DestroyWindow();
this->CloseWindow();
}END_CATCH
}
本文档为【mfc播放器】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。