{"id":139,"date":"2009-08-05T13:04:32","date_gmt":"2009-08-05T05:04:32","guid":{"rendered":"http:\/\/115.29.108.60\/?p=139"},"modified":"2011-09-26T21:36:11","modified_gmt":"2011-09-26T13:36:11","slug":"musicplayer","status":"publish","type":"post","link":"http:\/\/115.29.108.60\/?p=139","title":{"rendered":"MusicPlayer"},"content":{"rendered":"<p>\u6838\u5fc3\u4ee3\u7801\uff1a<br \/>\n#include <commctrl .h>\/\/\u6eda\u52a8\u6761\u63a7\u5236\u65f6\u5305\u542b\u5934\u6587\u4ef6<br \/>\n#include <shlobj .h>\/\/\u6587\u4ef6\u5939\u9009\u62e9\u5bf9\u8bdd\u6846\u5305\u542b\u5934\u6587\u4ef6<\/p>\n<p>TCHAR szFileName[80][MAX_PATH];\/\/\u64ad\u653e\u5217\u8868<br \/>\nint iNum = 0;\/\/\u97f3\u4e50\u6570<br \/>\nint iPlay = 0;\/\/\u64ad\u653e\u72b6\u6001\uff1a0\u672a\u64ad\u653e 1\u6b63\u5728\u64ad\u653e 2\u6682\u505c<br \/>\nint iPlayListIndex = 0;\/\/\u64ad\u653e\u5217\u8868\u7d22\u5f15<br \/>\nint iLength;\/\/\u64ad\u653e\u6587\u4ef6\u65f6\u957f\u79d2\u6570 <\/p>\n<p>Main_Proc\u5904\u7406\u91cc\u6dfb\u52a0\uff1a<br \/>\nHANDLE_MSG(hWnd, WM_HSCROLL, Main_OnHScroll);\/\/\u6c34\u5e73\u6eda\u52a8\u6761\u6d88\u606f\u3002WM_VSCROLL\u5782\u76f4\u6eda\u52a8\u6761\u6d88\u606f\u3002<\/p>\n<p>Main_OnInitDialog\u521d\u59cb\u5316\u6dfb\u52a0\uff1a<br \/>\n\/\/\u97f3\u91cf\u6eda\u52a8\u6761<br \/>\n\/\/\u8bbe\u7f6e\u6eda\u52a8\u6761\u53d6\u503c\u8303\u56f4<br \/>\n\/\/\u53c2\u8003\uff1ahttp:\/\/www.rupeng.com\/forum\/redirect.php?fid=32&#038;tid=601&#038;goto=nextoldset<br \/>\n\/\/http:\/\/hi.baidu.com\/mowm\/blog\/item\/c76d07ee77e5101efcfa3cd0.html<br \/>\nSendMessage(GetDlgItem(hwnd, IDC_TRBVOLUME), TBM_SETRANGEMIN, TRUE, 0);\/\/\u6700\u5c0f\u503c<br \/>\nSendMessage(GetDlgItem(hwnd, IDC_TRBVOLUME), TBM_SETRANGEMAX, TRUE, 1000);\/\/\u6700\u5927\u503c<br \/>\nSendMessage(GetDlgItem(hwnd, IDC_TRBVOLUME), TBM_SETPOS, TRUE, 1000);\/\/\u5f53\u524d\u4f4d\u7f6e <\/p>\n<p>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\n\/\/  Main_OnCommand<br \/>\nvoid Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)<br \/>\n{<br \/>\n    switch(id)<br \/>\n    {<br \/>\n\t\tcase IDC_BTNOPENFILES:\/\/\u6dfb\u52a0\u6587\u4ef6\u6309\u94ae<br \/>\n\t\t\tOpenFiles(hwnd);<br \/>\n\t\t\tbreak;<br \/>\n\t\tcase IDC_BTNSELECTFOLDER:<br \/>\n\t\t\tSelectFolder(hwnd);<br \/>\n\t\t\tbreak;<br \/>\n\t\tcase IDC_BTNPLAY:\/\/\u64ad\u653e\u6682\u505c\u6309\u94ae<br \/>\n\t\t\tif(0 == iPlay)\/\/\u672a\u64ad\u653e<br \/>\n\t\t\t{<br \/>\n\t\t\t\t\/\/\u83b7\u5f97\u9009\u4e2d\u9879\u64ad\u653e\u5217\u8868\u7d22\u5f15<br \/>\n \t\t\t\tiPlayListIndex = SendMessage(GetDlgItem(hwnd, IDC_LST1), LB_GETCURSEL, 0, 0);<br \/>\n \t\t\t\t\/\/\u64ad\u653e\u9009\u4e2d\u9879\uff0c\u6539\u53d8\u64ad\u653e\u72b6\u6001\u3002<br \/>\n \t\t\t\tPlay(hwnd, iPlayListIndex);<br \/>\n \t\t\t\t\/\/\u6539\u53d8\u6309\u94ae\u663e\u793a\u6587\u5b57<br \/>\n\t  \t\t\tSetWindowText(hwndCtl, &#8220;\u6682\u505c&#8221;);<br \/>\n\t\t\t}<br \/>\n\t\t\telse if(1 == iPlay)\/\/\u6b63\u5728\u64ad\u653e<br \/>\n\t\t\t{<br \/>\n\t\t\t\t\/\/\u6682\u505c\u6b63\u5728\u64ad\u653e\u6587\u4ef6<br \/>\n\t\t\t  \tmciSendString(&#8220;pause OpenMusicFile&#8221;, (LPTSTR)NULL, 0, NULL);<br \/>\n\t\t\t  \t\/\/\u6539\u53d8\u64ad\u653e\u72b6\u6001<br \/>\n\t  \t\t\tiPlay = 2;<br \/>\n\t  \t\t\t\/\/\u6539\u53d8\u6309\u94ae\u663e\u793a\u6587\u5b57<br \/>\n\t\t  \t\tSetWindowText(hwndCtl, &#8220;\u64ad\u653e&#8221;);<br \/>\n\t\t\t}<br \/>\n\t\t\telse\/\/\u6682\u505c<br \/>\n\t\t\t{<br \/>\n\t\t\t\t\/\/\u6062\u590d\u6682\u505c\u64ad\u653e\u6587\u4ef6<br \/>\n\t\t\t\tmciSendString(&#8220;play OpenMusicFile&#8221;, (LPTSTR)NULL, 0, NULL);<br \/>\n\t\t\t\t\/\/\u6539\u53d8\u64ad\u653e\u72b6\u6001<br \/>\n\t\t \t\tiPlay = 1;<br \/>\n\t\t \t\t\/\/\u6539\u53d8\u6309\u94ae\u663e\u793a\u6587\u5b57<br \/>\n\t  \t\t\tSetWindowText(hwndCtl, &#8220;\u6682\u505c&#8221;);<br \/>\n\t\t\t}<br \/>\n\t\t\tbreak;<br \/>\n\t\tcase IDC_BTNPREV:\/\/\u4e0a\u4e00\u9996<br \/>\n\t\t\t\/\/\u83b7\u5f97\u4e0a\u4e00\u9996\u64ad\u653e\u5217\u8868\u7d22\u5f15<br \/>\n\t\t\tiPlayListIndex = SendMessage(GetDlgItem(hwnd, IDC_LST1), LB_GETCURSEL, 0, 0) &#8211; 1;<br \/>\n\t\t\tif(iPlayListIndex >= 0)\/\/\u7d22\u5f15\u5728\u8303\u56f4\u5185<br \/>\n\t\t\t{<br \/>\n \t\t\t\tPlay(hwnd, iPlayListIndex);<br \/>\n \t\t\t\t\/\/\u8bbe\u7f6e\u4e0a\u4e00\u9996\u4e3a\u9009\u4e2d\u9879<br \/>\n \t\t\t\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_SETCURSEL, iPlayListIndex, 0);<br \/>\n\t\t\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), &#8220;\u6682\u505c&#8221;);<br \/>\n\t\t\t}<br \/>\n\t\tbreak;<br \/>\n\t\tcase IDC_BTNNEXT:\/\/\u4e0b\u4e00\u9996<br \/>\n\t\t\tiPlayListIndex = SendMessage(GetDlgItem(hwnd, IDC_LST1), LB_GETCURSEL, 0, 0) + 1;<br \/>\n\t\t\tif(iPlayListIndex < iNum)\n\t\t\t{\n \t\t\t\tPlay(hwnd, iPlayListIndex);\n \t\t\t\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_SETCURSEL, iPlayListIndex, 0);\n\t\t\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), \"\u6682\u505c\");\n\t\t\t}\n\t\tbreak;\n        case IDC_LST1:\/\/\u5217\u8868\u6d88\u606f \n        \tswitch(codeNotify)\n        \t{\n        \t\tcase LBN_SELCHANGE:\/\/\u9009\u4e2d\u9879\u6539\u53d8\n        \t\t\t\/\/\u83b7\u5f97\u9009\u4e2d\u9879\u64ad\u653e\u5217\u8868\u7d22\u5f15 \n        \t\t\tint iChange = SendMessage(hwndCtl, LB_GETCURSEL, 0, 0);\n        \t\t\tif(iChange != iPlayListIndex)\/\/\u7d22\u5f15\u6539\u53d8 \n        \t\t\t{\n\t \t\t\t\t\tiPlay = 0;\/\/\u65b0\u6587\u4ef6\u672a\u64ad\u653e \n\t  \t\t\t\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), \"\u64ad\u653e\");\n        \t\t\t}\n        \t\t\telse\/\/\u7d22\u5f15\u672a\u6539\u53d8 \n        \t\t\t{\n        \t\t\t\tiPlay = 1;\/\/\u6587\u4ef6\u6b63\u5728\u64ad\u653e \n        \t\t\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), \"\u6682\u505c\");\n        \t\t\t}\n\t\t\t\t\tbreak;\t\t\t\t\t \n        \t\tcase LBN_DBLCLK:\/\/\u53cc\u51fb\u67d0\u9879 \n\t        \t\tiPlayListIndex = SendMessage(hwndCtl, LB_GETCURSEL, 0, 0);\n\t        \t\tPlay(hwnd, iPlayListIndex);\n\t  \t\t\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), \"\u6682\u505c\"); \n\t        \t\tbreak;\n        \t\tdefault:break;\n\t\t\t}\n\t\t\tbreak;\n        default:break;\n    }\n}\n\nvoid Main_OnHScroll(HWND hwnd, HWND hwndCtl, UINT code, int pos)\/\/\u56fa\u5b9a\u683c\u5f0f? \n{\n\tif(hwndCtl == GetDlgItem(hwnd, IDC_TRBVOLUME))\n\t\tSetVolume(hwnd);\n\telse\n\t\tSetPlayProcess(hwnd);\n}\n\nvoid OpenFiles(HWND hwnd)\n{\n\tOPENFILENAME ofn;\n \tTCHAR szOpenFileNames[80*MAX_PATH];\/\/\u6587\u4ef6\u8def\u5f84 \n \tTCHAR szPath[MAX_PATH];\/\/\u57fa\u8def\u5f84 \n \tTCHAR* p; \n \tZeroMemory(&#038;ofn, sizeof(ofn)); \t\n \tofn.lStructSize = sizeof(ofn);\t\n \tofn.lpstrFile = szOpenFileNames;\n \tofn.lpstrFile[0] = '\\0';\n \tofn.nMaxFile = sizeof(szOpenFileNames);\t\n \tofn.lpstrFilter = TEXT(\"\u97f3\u4e50\u6587\u4ef6(mp3\u3001wma\u3001wav)\\0*.mp3;*.wma;*.wav\\0\u6240\u6709\u6587\u4ef6(*.*)\\0*.*\\0\");\n \tofn.Flags = OFN_EXPLORER | OFN_ALLOWMULTISELECT | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;\n \tif(GetOpenFileName(&#038;ofn))\n \t{  \n\t\t\/\/\u5355\u4e2a\u6587\u4ef6\u7684\u4fdd\u5b58\u5f62\u5f0f\u4e3a\uff1a\u7edd\u5bf9\u8def\u5f84\\0 \n \t\t\/\/\u591a\u4e2a\u6587\u4ef6\u7684\u4fdd\u5b58\u5f62\u5f0f\u4e3a\uff1a\u57fa\u8def\u5f84\\000\u6587\u4ef6\u4e00\\000\u6587\u4ef6\u4e8c\\0\n\t\t\/\/\u6ce8\u610f\u8def\u5f84\"\\\"\u7684\u8f6c\u4e49\u4e3a\"\\\\\" \n  \t\t\/\/\u628a\u8def\u5f84\u590d\u5236\u5230szPath\n  \t\t\/\/\u53c2\u8003\u8d44\u6599\uff1ahttp:\/\/blog.csdn.net\/xuminggang\/archive\/2009\/05\/21\/4206010.aspx \n  \t\tlstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset+1);\n  \t\t\/\/\u6839\u636e\u5355\u4e2a\u548c\u591a\u4e2a\u6587\u4ef6\u4e0d\u540c\u7684\u4fdd\u5b58\u5f62\u5f0f\uff0c\u591a\u6587\u4ef6\u57fa\u8def\u5f84\u9700\u52a0\"\\\\\"\u3002 \n  \t\tszPath[ofn.nFileOffset-1] = '\\\\';\n\t\t\/\/\u628a\u6307\u9488\u79fb\u5230\u7b2c\u4e00\u4e2a\u6587\u4ef6   \n  \t\tp = szOpenFileNames + ofn.nFileOffset;\n\t\tiPlayListIndex = iNum;\/\/\u52a0\u5165\u7684\u7b2c\u4e00\u4e2a\u6587\u4ef6 \n  \t\twhile(*p)\n  \t\t{   \n   \t\t\tlstrcat(szFileName[iNum], szPath);\t\/\/\u57fa\u8def\u5f84  \n   \t\t\tlstrcat(szFileName[iNum], p);    \t\/\/\u57fa\u8def\u5f84+\u6587\u4ef6=\u7edd\u5bf9\u8def\u5f84\n\t\t\t\/\/\u52a0\u5165\u5217\u8868\n\t\t\t\/\/ListBox\u53c2\u8003\uff1ahttp:\/\/www.cnitblog.com\/netssfy\/archive\/2007\/06\/12\/28347.html  \n   \t\t\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_ADDSTRING, 0, (LPARAM)p);\n   \t\t\tp += lstrlen(p) +1;     \t\t\t\/\/\u79fb\u81f3\u4e0b\u4e00\u4e2a\u6587\u4ef6\n   \t\t\tiNum++;\t\t\t\t\t\t\t\t\/\/\u589e\u52a0\u97f3\u4e50\u6570\uff0c\u79fb\u52a8\u51c6\u5907\u63a5\u6536\u4e0b\u4e00\u4e2a\u6587\u4ef6\u8def\u5f84\u3002 \n  \t\t}\n  \t\t\/\/\u8bbe\u7f6e\u9009\u4e2d\u9879 \n\t\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_SETCURSEL, (WPARAM)iPlayListIndex, 0);\n\t\t\/\/\u64ad\u653e\u9009\u4e2d\u9879 \n\t\tPlay(hwnd, iPlayListIndex);\t\n\t}\n}\n\nvoid Play(HWND hwnd, int iPlayListIndex)\n{\n\tTCHAR szMCIInfo[256];\t\t\t\t\/\/MCI\u64cd\u4f5c\u8fd4\u56de\u4fe1\u606f \n\tTCHAR szShortFileName[MAX_PATH];\t\/\/\u77ed\u6587\u4ef6\u540d \n\tZeroMemory(szShortFileName, sizeof(szShortFileName));\n\t\/\/\u5173\u95ed\u6b63\u5728\u64ad\u653e\u7684\u6587\u4ef6\n\t\/\/OpenMusicFile\u662f\u901a\u8fc7MCI Command String\u4e2dalias\u8bbe\u7f6e\u6587\u4ef6\u522b\u540d \n\tmciSendString(\"close OpenMusicFile\", szMCIInfo, sizeof(szMCIInfo), NULL);\n\t\/\/\u53c2\u8003\uff1ahttp:\/\/www.programfan.com\/doc\/vbapi\/GetShortPathName.htm\n\t\/\/http:\/\/topic.csdn.net\/t\/20060926\/15\/5049254.html\n\t\/\/\u5426\u5219\u64ad\u653e\u4e0d\u4e86\u8def\u5f84\u5e26\u7a7a\u683c\u7684\u6587\u4ef6 \n\tGetShortPathName(szFileName[iPlayListIndex], szShortFileName, sizeof(szShortFileName));\n\t\/\/MCI Command String \n\t\/\/\u53c2\u8003\uff1ahttp:\/\/tieba.baidu.com\/f?kz=26410588 \n\tTCHAR szCMD[2*MAX_PATH];\n\twsprintf(szCMD, \"open %s alias OpenMusicFile\", szShortFileName);\n\t\/\/\u6253\u5f00\u6587\u4ef6\t\t\t\t\t\n\tmciSendString(szCMD, szMCIInfo, sizeof(szMCIInfo), NULL);\n\t\/\/\u64ad\u653e\u6587\u4ef6\t\n\tmciSendString(\"play OpenMusicFile\", szMCIInfo, sizeof(szMCIInfo), NULL);\n\tmciSendString(\"status OpenMusicFile length\", szMCIInfo, sizeof(szMCIInfo), NULL);\/\/szMCIInfo\u83b7\u5f97\u64ad\u653e\u65f6\u957f\u6beb\u79d2\u6570\n\tiLength = atoi(szMCIInfo)\/1000;\/\/\u64ad\u653e\u65f6\u957f\u79d2\u6570\n\t\/\/\u8bbe\u7f6e\u8fdb\u5ea6\u6eda\u52a8\u6761\u53d6\u503c\u8303\u56f4 \n\tSendMessage(GetDlgItem(hwnd, IDC_TRBPROCESS), TBM_SETRANGEMIN, TRUE, 0);\n\tSendMessage(GetDlgItem(hwnd, IDC_TRBPROCESS), TBM_SETRANGEMAX, TRUE, iLength);\n\t\/\/\u8bbe\u7f6e\u5b9a\u65f6\u5668\uff0c\u66f4\u65b0\u8fdb\u5ea6\u6eda\u52a8\u6761\u3002 \n\tSetTimer(hwnd, 1, 1000, PlayProcess);\n\t\/\/\u8bbe\u7f6e\u97f3\u91cf \n\tSetVolume(hwnd);\n\t\/\/\u6539\u53d8\u64ad\u653e\u72b6\u6001 \n\tiPlay = 1;\n\t\/\/\u6539\u53d8\u6309\u94ae\u663e\u793a\u6587\u5b57 \n\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), \"\u6682\u505c\");\n}\n\nvoid SetVolume(HWND hwnd)\n{\n\t\/\/\u83b7\u5f97\u97f3\u91cf\u6eda\u52a8\u4f53\u5f53\u524d\u4f4d\u7f6e \n\tint iVolume = SendMessage(GetDlgItem(hwnd, IDC_TRBVOLUME), TBM_GETPOS, 0, 0);\n\t\/\/\u8bbe\u7f6e\u97f3\u91cf \n\tTCHAR szVolume[256];\n\twsprintf(szVolume, \"setaudio OpenMusicFile volume to %d\", iVolume);\n\tmciSendString(szVolume, (LPTSTR)NULL, 0, 0);\n}\n\nvoid SetPlayProcess(HWND hwnd)\n{\n\tif(0 == iPlay)\/\/\u672a\u64ad\u653e\u65f6\u4e0d\u80fd\u62d6\u52a8\u6eda\u52a8\u6761 \n\t\tSendMessage(GetDlgItem(hwnd, IDC_TRBPROCESS), TBM_SETPOS, TRUE, 0);\n\telse if(1 == iPlay)\/\/\u53ea\u80fd\u5728\u64ad\u653e\u65f6\u62d6\u52a8\u8fdb\u5ea6\u6eda\u52a8\u6761 \n\t{\n\t\tTCHAR szPlayProcess[256];\n\t\tint iPosition = SendMessage(GetDlgItem(hwnd, IDC_TRBPROCESS), TBM_GETPOS, 0, 0)*1000;\/\/\u62d6\u52a8\u4f4d\u7f6e\u6beb\u79d2\u6570 \n\t\twsprintf(szPlayProcess, \"play OpenMusicFile from %d\", iPosition);\n\t\tmciSendString(szPlayProcess, (LPTSTR)NULL, 0, 0);\n\t}\n}\n\nvoid CALLBACK PlayProcess(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)\n{\n\tTCHAR szMCIInfo[256];\/\/MCI\u64cd\u4f5c\u8fd4\u56de\u4fe1\u606f \n\tmciSendString(\"status OpenMusicFile position\", szMCIInfo, sizeof(szMCIInfo), NULL);\/\/szMCIInfo\u83b7\u5f97\u64ad\u653e\u5f53\u524d\u4f4d\u7f6e\u6beb\u79d2\u6570\n\tint iPosition = atoi(szMCIInfo)\/1000;\/\/\u64ad\u653e\u5f53\u524d\u4f4d\u7f6e\u79d2\u6570\n\t\/\/\u66f4\u65b0\u64ad\u653e\u65f6\u95f4 \n\tTCHAR* szBuffer;\n\tFormatTime(iLength, iPosition, szBuffer);\n\tSetWindowText(GetDlgItem(hwnd, IDC_STCTIME), szBuffer);\n\tSendMessage(GetDlgItem(hwnd, IDC_TRBPROCESS), TBM_SETPOS, TRUE, iPosition);\/\/\u8bbe\u7f6e\u8fdb\u5ea6\u6eda\u52a8\u6761\u4f4d\u7f6e \n\tif(iPosition == iLength)\/\/\u7ed3\u675f \n\t{\n\t\tmciSendString(\"close OpenMusicFile\", (LPTSTR)NULL, 0, 0);\n\t\tiPlay = 0;\n\t\tSetWindowText(GetDlgItem(hwnd, IDC_BTNPLAY), TEXT(\"\u64ad\u653e\"));\n\t}\n}\n\nvoid FormatTime(int iLength, int iPosition, TCHAR* szBuffer)\n{\n\tint iLengthMinute, iLengthSecond, iPositionMinute, iPositionSecond;\n\tiLengthMinute = iLength\/60;\/\/\u603b\u65f6\u957f\u5206\u949f \n\tiLengthSecond = iLength-iLengthMinute*60;\/\/\u603b\u65f6\u957f\u79d2\u949f \n\tiPositionMinute = iPosition\/60;\/\/\u5f53\u524d\u65f6\u957f\u5206\u949f \n\tiPositionSecond = iPosition - iPositionMinute*60;\/\/\u5f53\u524d\u65f6\u957f\u79d2\u949f \n\t\/\/\u663e\u793a \n\twsprintf(szBuffer, \"%02d:%02d \/ %02d:%02d\", iPositionMinute, iPositionSecond, iLengthMinute, iLengthSecond);\n}\n\n\/\/\u6587\u4ef6\u5939\u9009\u62e9\u5bf9\u8bdd\u6846\n\/\/\u53c2\u8003\uff1ahttp:\/\/blog.csdn.net\/ShardowM\/archive\/2008\/06\/06\/2516213.aspx \n\/\/http:\/\/topic.csdn.net\/t\/20021103\/14\/1143060.html\n\/\/http:\/\/www.programfan.com\/blog\/article.asp?id=19614\nvoid SelectFolder(HWND hwnd)\n{\n\tLPMALLOC lpMalloc = NULL;   \n \tif(SUCCEEDED(SHGetMalloc(&#038;lpMalloc)))   \n  \t{  \n\t\tTCHAR szPath[MAX_PATH];\n\t\tBROWSEINFO bi;\n\t\tLPITEMIDLIST pidl;\n\t\t\/\/LPBYTE pBuf = (LPBYTE)CoTaskMemAlloc(sizeof(bi));\n\t\tZeroMemory(&#038;bi, sizeof(bi));\/\/\u6ce8\u610f\u7ed3\u6784\u4f53\u7684\u7f6e\u96f6 \n\t\tbi.hwndOwner = hwnd;\n\t\tbi.pidlRoot = NULL;\n\t\tbi.pszDisplayName = szPath;\n\t\tbi.lpszTitle = TEXT(\"\u9009\u62e9\u76ee\u5f55\uff1a\");\n\t\tbi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_BROWSEFORCOMPUTER;\n\t\tbi.lpfn = NULL;\n\t\tbi.lParam = 0;\n\t\tbi.iImage = 0;\n\t\tif((pidl = SHBrowseForFolder(&#038;bi)) != NULL)\/\/\u663e\u793a\u6587\u4ef6\u5939\u9009\u62e9\u5bf9\u8bdd\u6846\u5e76\u64cd\u4f5c\n\t\t{ \n\t\t\tSHGetPathFromIDList(pidl, szPath);\/\/\u8f6c\u6362\u6587\u4ef6\u5939\u8def\u5f84   \n\t\t\tFindAllFile(hwnd, szPath, \"*.mp3\");\/\/\u67e5\u627e\u6587\u4ef6\u5939\u4e0bmp3\u6587\u4ef6\n\t\t\tFindAllFile(hwnd, szPath, \"*.wma\");\/\/wma \n\t\t\tFindAllFile(hwnd, szPath, \"*.wav\");\/\/wav\n\t\t\t\/\/MessageBox(NULL, szPath, \"\", MB_OK);\n\t\t}\n\t\t\/\/CoTaskMemFree(pBuf);\n\t\tlpMalloc->Free(pidl);<br \/>\n\t\tlpMalloc->Release();<br \/>\n  \t}<br \/>\n}<\/p>\n<p>\/\/\u662f\u5426\u662f\u6839\u76ee\u5f55<br \/>\n\/\/\u6839\u76ee\u5f55\u8def\u5f84\u5982\uff1aF:\\<br \/>\n\/\/\u975e\u6839\u76ee\u5f55\u8def\u5f84\u5982\uff1aF:\\Music<br \/>\nBOOL IsRoot(LPCTSTR lpszPath)<br \/>\n{<br \/>\n\treturn 3 == lstrlen(lpszPath);<br \/>\n}<\/p>\n<p>\/\/\u904d\u5386\u6587\u4ef6\u5939\uff0c\u627e\u51fa\u6307\u5b9a\u540e\u7f00\u6587\u4ef6\u3002<br \/>\n\/\/\u53c2\u8003\uff1ahttp:\/\/www.programfan.com\/club\/showpost.asp?id=18098<br \/>\n\/\/http:\/\/hi.baidu.com\/csuhkx\/blog\/item\/cb66ff00d82bc610738b6521.html<br \/>\nvoid FindAllFile(HWND hwnd, LPCTSTR lpszPath, LPCTSTR lpszSuffix)<br \/>\n{<br \/>\n\tWIN32_FIND_DATA wfd;<br \/>\n\tTCHAR szPath[MAX_PATH];<br \/>\n\tlstrcpy(szPath, lpszPath);<br \/>\n\tif(!IsRoot(szPath))\/\/\u975e\u6839\u76ee\u5f55\u52a0\u4e0a&#8221;\\\\&#8221;<br \/>\n\t\tlstrcat(szPath, &#8220;\\\\&#8221;);<br \/>\n\tlstrcat(szPath, lpszSuffix);\/\/\u52a0\u4e0a\u540e\u7f00<br \/>\n\tHANDLE hFind = FindFirstFile(szPath, &#038;wfd);<br \/>\n\tif(INVALID_HANDLE_VALUE == hFind)\/\/\u672a\u627e\u5230\u6587\u4ef6\uff0c\u8fd4\u56de\u3002<br \/>\n\t\treturn;<br \/>\n\tdo<br \/>\n\t{<br \/>\n\t\tif(&#8216;.&#8217; == wfd.cFileName[0])<br \/>\n\t\t\tcontinue;<br \/>\n\t\tif(wfd.dwFileAttributes &#038; FILE_ATTRIBUTE_DIRECTORY)\/\/\u5982\u679c\u662f\u76ee\u5f55\uff0c\u9012\u5f52\u8fdb\u5165\u76ee\u5f55\u904d\u5386\u3002<br \/>\n\t\t{<br \/>\n\t\t\tif(IsRoot(lpszPath))\/\/\u6839\u76ee\u5f55<br \/>\n\t\t\t\twsprintf(szPath, &#8220;%s%s&#8221;, lpszPath, wfd.cFileName);<br \/>\n\t\t\telse\/\/\u975e\u6839\u76ee\u5f55<br \/>\n\t\t  \t\twsprintf(szPath, &#8220;%s\\\\%s&#8221;, lpszPath, wfd.cFileName);<br \/>\n \t\t\tFindAllFile(hwnd, szPath, lpszSuffix);<br \/>\n\t\t}<br \/>\n\t\telse<br \/>\n\t\t{<br \/>\n\t\t\tif(IsRoot(lpszPath))\/\/\u6839\u76ee\u5f55<br \/>\n\t\t\t\twsprintf(szPath, &#8220;%s%s&#8221;, lpszPath, wfd.cFileName);<br \/>\n\t\t\telse\/\/\u975e\u6839\u76ee\u5f55<br \/>\n\t\t  \t\twsprintf(szPath, &#8220;%s\\\\%s&#8221;, lpszPath, wfd.cFileName);<br \/>\n\t  \t\tlstrcpy(szFileName[iNum++], szPath);<br \/>\n \t\t\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_ADDSTRING, 0, (LPARAM)wfd.cFileName);<br \/>\n \t\t\t\/\/MessageBox(NULL, szPath, &#8220;&#8221;, MB_OK);<br \/>\n\t\t}<br \/>\n\t}while(FindNextFile(hFind, &#038;wfd));<br \/>\n\tFindClose(hFind);<br \/>\n\tiPlayListIndex = iNum-1;\/\/\u52a0\u5165\u7684\u6700\u540e\u4e00\u4e2a\u6587\u4ef6<br \/>\n\t\/\/\u8bbe\u7f6e\u9009\u4e2d\u9879<br \/>\n\tSendMessage(GetDlgItem(hwnd, IDC_LST1), LB_SETCURSEL, (WPARAM)iPlayListIndex, 0);<br \/>\n\t\/\/\u64ad\u653e\u9009\u4e2d\u9879<br \/>\n\tPlay(hwnd, iPlayListIndex);<br \/>\n}<\/p>\n<p><a href='http:\/\/115.29.108.60\/wp-content\/uploads\/2009\/08\/MusicPlayer.exe'>MusicPlayer<\/a><\/shlobj><\/commctrl><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6838\u5fc3\u4ee3\u7801\uff1a #include \/\/\u6eda\u52a8\u6761\u63a7\u5236\u65f6\u5305\u542b\u5934\u6587\u4ef6 #include \/\/\u6587\u4ef6\u5939\u9009\u62e9\u5bf9\u8bdd\u6846\u5305\u542b\u5934\u6587\u4ef6 T [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":4,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":857,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions\/857"}],"wp:attachment":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}