音乐播放器01

来源:互联网 发布:没有usb虚拟打印机端口 编辑:程序博客网 时间:2024/04/27 20:56

    OPENFILENAME ofn;
            char szFile[MAX_PATH];
            ZeroMemory(&ofn,sizeof(ofn));
            ofn.lStructSize     = sizeof(ofn);
            ofn.lpstrFile     = szFile;//得到文件路径
            ofn.lpstrFile[0] = TEXT('/0');
            ofn.nMaxFile     = sizeof(szFile);
            ofn.lpstrFilter  = TEXT("ALL/0*.*/0mp3/0*.mp3/0");
            ofn.nFilterIndex = 1;
            ofn.lpstrFileTitle  = NULL;
            ofn.nMaxFileTitle   = 0;
            ofn.lpstrInitialDir = NULL;
            ofn.hwndOwner = hwnd;
            ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;//可以设置是否同时播放两首或多首歌
            if (GetOpenFileName(&ofn))
            {
                TCHAR shortmath[MAX_PATH];
                GetShortPathName(szFile,shortmath,sizeof(shortmath));//将文件的路径名简化,以减少运行出错率
                char play[MAX_PATH+20];
                wsprintf(play,"play %s",shortmath);
                mciSendString(play,"",0,NULL);
                //一定注意音乐文件不能太大,否则将无法播放
               
            }

利用

#include <commdlg.h>//打开文件窗口选项
#include <mmsystem.h>//播放音乐头文件函数Mcisendstring实现了简单的播放音乐文件的功能O(∩_∩)O~

原创粉丝点击