标题:谁能帮我看看我的代码哪错了
只看楼主
zxh2013
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-4-2
 问题点数:0 回复次数:0 
谁能帮我看看我的代码哪错了
谁能帮我看看我的代码哪错了。。。


            TCHAR szFilePath_Name[MAX_PATH][256];//存放多个文件的全路径(路径+文件名)
            int pianyi = 0;//打开歌曲时记录歌曲的编号,为了多次打开时编号能连续,所以设为全局变量
            int xuhao = 0;//为列表中的歌曲添加序号

            OPENFILENAME ofn;
            TCHAR szFile[256*MAX_PATH];//文件全路径
            TCHAR szPath[256];//文件纯路径
            char * p;//指向歌曲的名字
            int zk = 0;

            ZeroMemory(&ofn, sizeof(ofn));
            ofn.lStructSize = sizeof(ofn);
            ofn.lpstrFile = szFile;
            ofn.lpstrFile[0] = TEXT('\0');
            ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
            //以上为真正有用的代码(定义打开文件窗口)
            //以下代码为了丰富窗口模块和限定打开文件
            ofn.lpstrTitle = NULL;
            ofn.lpstrFileTitle = TEXT("添加音乐");
            ofn.nMaxFileTitle = 0;
            ofn.hwndOwner = hwnd;
            ofn.lpstrFilter = "音乐文件(.mp3)\0*.mp3\0所有文件(*.*)\0*.*\0";
            ofn.lpstrCustomFilter = NULL;
            ofn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_ALLOWMULTISELECT;
            ofn.lpstrInitialDir =NULL;
            ofn.lpstrDefExt = "*.mp3";

            if(GetOpenFileName(&ofn))
            {
                //MessageBox(hwnd, szFile, TEXT("文件路径"), MB_OK);
                int pathLen = 0;//路径长度
                TCHAR songName[256];
                lstrcpyn(szPath, szFile, ofn.nFileOffset);
                //把第一个文件从szFile中开始到ofn.nFileOffset标记处的路径复制给szPath
                ofn.nFileOffset = '\0';//ofn.nFileOffset为复制时到此结束的标记,即'\0'
                pathLen = lstrlen(szPath);
                if(szPath[pathLen-1] != '\\')
                {
                    lstrcat(szPath, TEXT("\\"));
                }
                p = szFile + ofn.nFileOffset;
                while(*p)
                {
                    lstrcpy(szFilePath_Name[pianyi], szPath);
                    lstrcat(szFilePath_Name[pianyi], p);
                    xuhao++;
                    wsprintf(songName, "%d. %s", xuhao, p);
                    for(int i=0; i<pianyi; i++)
                    {
                        if(lstrcmp(szFilePath_Name[pianyi], szFilePath_Name[i]) == 0)
                        {
                            pianyi --;
                            xuhao --;
                            zk++;
                        }
                    }
                    if(zk == 0)
                    {
                        SendMessage(GetDlgItem(hwnd,IDC_LIST),LB_ADDSTRING,0,(LPARAM)songName);
                        p += lstrlen(p) +1;   //移至下一个文件
                        pianyi++;
                    }
                    else
                       {
                             zk--;   
                          p += lstrlen(p) +1;   //移至下一个文件
                          pianyi++;  
                       }


                }

            }
搜索更多相关主题的帖子: 歌曲 
2013-04-05 23:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-403115-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.075655 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved