【C大事】第七讲:打开文件对话框及播放音乐(下)

直接上代码:

switch(id)
    {
        case IDC_OK:
        {
            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(*.mp3)\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 | OFN_ALLOWMULTISELECT;
 
            if (GetOpenFileName(&ofn))
            {
                TCHAR shortPath[MAX_PATH];
                GetShortPathName(szFile, shortPath, sizeof(shortPath));
            //  MessageBox(hwnd,shortPath, TEXT("哈哈"), MB_OK);
                TCHAR cmd[MAX_PATH + 10];
                wsprintf(cmd, "play %s", shortPath);
                mciSendString(cmd, "", 0, NULL);
            }
 
 
        }
        break;
        default:
        break;
    }


你可能感兴趣的:(【C大事】第七讲:打开文件对话框及播放音乐(下))