MP3c语言源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include
#include
#include "resource.h"
int _GetFileName(TCHAR *FileName, HANDLE hwnd,char *lei)
{//该函数实现“打开文件名填充在FileName数组中, char *lei为需要打开的文件类型,如:mp3, 则传入"mp3"
int i;
int j;
int len;
char c[100]={0};
char a[]="(*.)\0*.\0\0";
OPENFILENAME FileNames;
static char szFileName[MAX_PATH];
static char szTitleName [MAX_PATH] ;
static TCHAR szFilter[100] = {0};
len = strlen(lei);
c[0]=a[0];
c[1]=a[1];
c[2]=a[2];
for(i=0;i
c[3+i]=lei[i];
}
c[3+i]=a[3];
c[4+i]=a[4];
c[5+i]=a[5];
c[6+i]=a[6];
for(j=0;j
c[7+i+j]=lei[j];
}
c[7+i+j]=a[7];
c[8+i+j]=a[8];
memcpy(szFilter, c,100);
FileNames.lStructSize = sizeof (OPENFILENAME) ;
FileNames.hwndOwner = hwnd ;
FileNames.hInstance = NULL ;
FileNames.lpstrFilter = szFilter ;
FileNames.lpstrCustomFilter = NULL ;
FileNames.nMaxCustFilter = 0 ;
FileNames.nFilterIndex = 0 ;
FileNames.lpstrFile = szFileName ;
FileNames.nMaxFile = MAX_PATH ;
FileNames.lpstrFileTitle = szTitleName ;
FileNames.nMaxFileTitle = MAX_PATH ;
FileNames.lpstrInitialDir = NULL ;
FileNames.lpstrTitle = NULL ;
FileNames.Flags = 0 ;
FileNames.nFileOffset = 0 ;
FileNames.nFileExtension = 0 ;
FileNames.lpstrDefExt = NULL;
FileNames.lCustData = 0 ;
FileNames.lpfnHook = NULL ;
FileNames.lpTemplateName = NULL ;
GetOpenFileName(&FileNames);
for(i=0,j=0; szFileName[i]; i++,j++)
{
if(szFileName[i]=='\\')
{
FileName[j++] = szFileName[i];
FileName[j]='\\';
}
else
FileName[j]=szFileName[i];
}
FileName[j] = 0;
return 0;
}
LONG CALLBACK
DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static char FileName[250];
static char buffer[100];
static int iPosition;
static HANDLE hSlider;
static MCI_PLAY_PARMS mciPlay;
static MCI_OPEN_PARMS mciOpen;
static MCI_DGV_SETAUDIO_PARMS mciSetAudioPara;
memset(FileName, 0, sizeof(FileName) );
switch(message)
{
case WM_CLOSE:
EndDialog( hwnd, 0);
return 0;
case WM_INITDIALOG:
hSlider = GetDlgItem(hwnd, IDC_SLIDER1);
SendMessage(hSlider, TBM_SETPOS, TRUE, 20);
mciSetAudioPara.dwValue = 200;
mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;
return 0;
//音量调节的核心代码
case WM_HSCROLL:
switch(LOWORD(wParam) )
{
case SB_THUMBPOSITION:
case SB_PAGERIGHT:
case SB_PAGELEFT:
iPosition = SendMessage(hSlider, TBM_GETPOS, 0, 0);
mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;
mciSetAudioPara.dwValue = iPosition*10;
mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);
return 0;
default:return 0;
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam) )
{
case IDB_SCAN:
_GetFileName(FileName, hwnd, "mp3");//打开文件
SetDlgItemText(hwnd, IDC_EDIT, FileName);
SetFocus(GetDlgItem(hwnd, IDB_PLAY) );
//开始播放
mciOpen.lpstrElementName=(char *)malloc(250*sizeof(char));
GetDlgItemText(hwnd, IDC_EDIT, mciOpen.lpstrElementName, 250);
mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT, (DWORD)&mciOpen);
mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);
//设置初始音量
mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_VALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);
return 0;
//从暂停中恢复播放
case IDB_PLAY:
mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);
return 0;
//暂停
case IDB_PAUSE:
mciSendCommand(mciOpen.wDeviceID, MCI_PAUSE, MCI_NOTIFY, (DWORD)&mciPlay);
return 0;
default:return 0;
}
return 0;
default:return 0;
}
}
LONG WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
InitCommonControls();
DialogBoxParam(hInstance, IDD_DIALOG1, NULL, DlgProc,NULL);
return 0;
}