标题:编译组建没错误,但是代码运行不起来
只看楼主
hamuamu0
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-1-25
结帖率:75%
 问题点数:0 回复次数:2 
编译组建没错误,但是代码运行不起来

<sum;i++)


#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
#include <mmsystem.h>
#include <commdlg.h>
#include <fcntl.h>
#include <io.h>

static UINT PresentSongcurSel     = 0;            //当前播放歌曲
static UINT PauseFlag             = 0;            //暂停Flag 时为非暂停
static long CircleListFlag         = 0;            //列表循环Flag
static int totalSecond             = 0;            //当前歌曲播放时长 /s
static int TimerSecond           = 0;            //定时器总时间     /s   
static TCHAR ShortPathName[256];                //文件最短路径
static UINT StylePlay            = 0;            //0 列表循环
                                                //1单曲循环
                                                //2随机播放
                                                //3
static UINT OpenStytle             = 0;            //为1时打开自动播放
static char SongName[256];

void GetSongTime(HWND hwnd);

void RreadList(HWND hwnd);                        //读取歌曲例表声明
void RreadList2(HWND hwnd);
void SsaveList(HWND hwnd);                        //保歌歌曲例表声明
void AddSongs(HWND hwnd);                        //添加歌曲声明
void GetSongsName(HWND hwnd, TCHAR *line, UINT Lenth);

void ClosePrensentSong(HWND hwnd);                //关闭当前播放歌曲
void PlaySong(HWND hwnd, UINT curSel);            //播放选中歌曲
void PausePrensentSong(HWND hwnd);                //暂停当前歌曲
void RePausePrensetSong(HWND hwnd);                //继续当前歌曲
   
void TotletimeSe(HWND hwnd);                    //计算当前歌曲的总时间,并现实



BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
        HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
        HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
//        HANDLE_MSG(hWnd,WM_CTLCOLORDLG,rupeng);
    }

    return FALSE;
}
void CALLBACK TimerProc(HWND hwnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
   
    if (PauseFlag == 0)
    {
        TimerSecond++;
        if (TimerSecond >= totalSecond)
        {
            if (StylePlay == 0)
            {   
                PlaySong(hwnd,(PresentSongcurSel+1));
            }
            else if (StylePlay == 1)
            {
                PlaySong(hwnd,PresentSongcurSel);
            }
            else if (StylePlay == 2)
            {
                HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);   
                int sum = ListBox_GetCount(hwndCombo);
                int num = (rand() % sum);
                PlaySong(hwnd,num);
            }
            TimerSecond = 0;
        }
    }
}

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
    RreadList(hwnd);                                //读取歌曲例表,并反回打开播放方式
    RreadList2(hwnd);
    FILE *fp = fopen("E:/泸诚音乐文件1.txt","a+");
    rewind(fp);
    TCHAR str[1];
    str[0] = fgetc(fp);
    str[2] = '\0';

    OpenStytle = atoi(str);
    if (OpenStytle == 1)
    {
        PlaySong(hwnd,0);                                    //打开播放列表第一首歌
    }
    HWND hwndPlayStyle = GetDlgItem(hwnd,IDC_PLAYSTYLE);
    SetWindowText(hwndPlayStyle,"列表");
    return TRUE;
}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
   

    switch(id)
    {
        case IDC_ADDSONG:                                        //列表添加歌曲
        {
            AddSongs(hwnd);     
        }
            break;
        case IDC_PLAY:                                            //播放选中歌曲
        {
            HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
            int curSel = ListBox_GetCurSel(hwndCombo);
            PlaySong(hwnd,curSel);
        }            
        break;
        case IDC_LIST:
        {
            switch(codeNotify)
            {
            case LBN_DBLCLK:                                    //播放双击选中歌曲
            {
                ClosePrensentSong(hwnd);
                HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
                int curSel = ListBox_GetCurSel(hwndCombo);
                PlaySong(hwnd, curSel);
            }
                break;
            }
        }
        break;
        case IDC_UPSONG:                                        //上一首
            {
                ClosePrensentSong(hwnd);
                PlaySong(hwnd,PresentSongcurSel-1);
            }
            break;
        case IDC_DOWNSONG:                                        //下一首
            {
                ClosePrensentSong(hwnd);
                PlaySong(hwnd,PresentSongcurSel+1);
            }
            break;
        case IDC_PAUSE:                                            //暂停当前歌曲
            {

                if (PauseFlag==0)
                {
                    PausePrensentSong(hwnd);
                    HWND hwndCombo = GetDlgItem(hwnd,IDC_PAUSE);
                    SetWindowText(hwndCombo,TEXT(":〈"));                //改变按钮显示
                }
                else
                {
                    RePausePrensetSong(hwnd);
                    SetTimer(hwnd,0,1000,TimerProc);
                    HWND hwndCombo = GetDlgItem(hwnd,IDC_PAUSE);
                    SetWindowText(hwndCombo,TEXT(" :-〉"));                //改变按钮显示
                }
            }
            break;
        case IDC_CLOSE:                                            //关闭当前歌曲
            {        
                ClosePrensentSong(hwnd);
                KillTimer(hwnd, 0);
            }
            break;
        case IDC_SAVESONG:                                        //保存列表
            {   
                SsaveList(hwnd);
            }
            break;
        case IDC_DELETESONG:                                    //删除选中歌曲
        {
            HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
            HWND hwndCombo2 = GetDlgItem(hwnd,IDC_LIST2);
            int curSel = ListBox_GetCurSel(hwndCombo);
            ListBox_DeleteString(hwndCombo,curSel);
            ListBox_SetCurSel(hwndCombo,curSel);
            ListBox_DeleteString(hwndCombo2,curSel);
            ListBox_SetCurSel(hwndCombo2,curSel);
        }
            break;
        case IDC_DELETEALL:                                        //清空列表
            {
                HWND hwndCom = GetDlgItem(hwnd,IDC_LIST);
                HWND hwndCombo2 = GetDlgItem(hwnd,IDC_LIST2);   
                int  k = ListBox_GetCount(hwndCom);
                int i;
                for(i = (k-1);i >= 0;i--)                //*********不能用**********
                {                                                //for(i=0;i<sum;i++)
                    ListBox_DeleteString(hwndCom,i);            //ListBox_DeleteString
                    ListBox_DeleteString(hwndCombo2,i);            //因为从前面开始删,删第一项后,
                }                                            //第二项会成为第一项,在删第二
            }                                                //项时,就没有露了这一项
            break;                                            
        case ID_MENUITEMLIST:                                //列表循环播放
        {
            StylePlay = 0;   
            SetDlgItemText(hwnd,IDC_PLAYSTYLE,"列表循环");
        }
            break;
        case ID_MENUITEMSINGLE:                                    //单曲循环
            {
                StylePlay = 1;   
                SetDlgItemText(hwnd,IDC_PLAYSTYLE, "单曲循环");
            }        
            break;
        case ID_MENUITEMSJ:                                        //随机播放
            {
                StylePlay = 2;   
                SetDlgItemText(hwnd,IDC_PLAYSTYLE, "随机循环");
            }        
            break;
        case ID_MENUITEMSTYTLE:                                    //打开时的播发模式
            {
               
                if (OpenStytle == 0)               
                {
                    FILE *fp;
                    fp = fopen("E:/泸诚音乐文件1.txt","w");
                    rewind(fp);
                    fputc('1',fp);                                //设置打开自动播放
                    fclose(fp);
                }
                else if (OpenStytle == 1)
                {
                    FILE *fp;
                    fp = fopen("E:/泸诚音乐文件1.txt","w");
                    rewind(fp);
                    fputc('0',fp);                                //设置打开不播放
                    fclose(fp);
                }
            }
            break;   

            break;
        default:
        break;
    }
}

void Main_OnClose(HWND hwnd)
{
    EndDialog(hwnd,0);
}

HBRUSH g_hbrush = CreateSolidBrush(RGB(90,180,160));        //创建笔刷
HBRUSH rupeng(HWND hwnd, HDC hdc, HWND hwndChild, int type)
{
    return g_hbrush;
}
//************读取歌曲列表****************
void RreadList(HWND hwnd)
{
    FILE *fp;
    fp = fopen("E:/泸诚音乐文件.txt","a+");
    rewind(fp);
    TCHAR line[256];
    int i=0;
    for (i=0;!feof(fp);i++)                                    
    {
        
        line[i] = fgetc(fp);                                
   
        if (line[i] == '*')
        {
            line[i] = '\0';
            HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
            ListBox_AddString(hwndCombo,line);
            i=(-1);
        }
    }
    if (i != 1)                                                //空文件时,fp会加1,所以读出数
    {
        line[i] = '\0';
        HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
        MessageBox(NULL,line,TEXT("2"),MB_OK);
        ListBox_InsertString(hwndCombo,-1,line);
    }
    fclose(fp);

}

void RreadList2(HWND hwnd)
{
    FILE *fp;
    fp = fopen("E:/泸诚音乐文件2.txt","a+");
    rewind(fp);
    TCHAR line[256];
    int i=0;
    for (i=0;!feof(fp);i++)                                    
    {
        
        line[i] = fgetc(fp);                                
   
        if (line[i] == '*')
        {
            line[i] = '\0';
            HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST2);
            ListBox_AddString(hwndCombo,line);
            i=(-1);
        }
    }
    if (i != 1)                                                //空文件时,fp会加1,所以读出数
    {
        line[i] = '\0';
        HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST2);
        ListBox_InsertString(hwndCombo,-1,line);
    }
    fclose(fp);
}

//************保存歌曲列表****************
void SsaveList(HWND hwnd)
{
    FILE *fp = fopen("E:/泸诚音乐文件.txt","w");
    HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
    int Count = ListBox_GetCount(hwndCombo);
    TCHAR SongPath[256];
    TCHAR SongPathX[256];
    int i = 0;
    for (i = 0; i < Count; i++)
    {
        ListBox_GetText(hwndCombo,i,SongPath);
        wsprintf(SongPathX,"%s*",SongPath);
        fputs(SongPathX,fp);
    }
    fclose(fp);
    FILE *fp2 = fopen("E:/泸诚音乐文件2.txt","w");
    HWND hwndCombo2 = GetDlgItem(hwnd,IDC_LIST2);
    int Count2 = ListBox_GetCount(hwndCombo2);
    TCHAR SongPath2[256];
    TCHAR SongPathX2[256];
    int i2 = 0;
    for (i2 = 0; i2 < Count2; i2++)
    {
        ListBox_GetText(hwndCombo2,i2,SongPath2);
        wsprintf(SongPathX2,"%s*",SongPath2);
        fputs(SongPathX2,fp2);
    }
    fclose(fp2);
}

//************添加歌曲****************
void AddSongs(HWND hwnd)
{
     OPENFILENAME ofn;
     TCHAR szOpenFileNames[80*MAX_PATH];
     TCHAR szPath[MAX_PATH];
     TCHAR szFileName[MAX_PATH];            
     TCHAR szFileNamePath[MAX_PATH];
     TCHAR* p;
     int nLen = 0;
     ZeroMemory( &ofn, sizeof(ofn) );
     ofn.Flags = OFN_EXPLORER | OFN_ALLOWMULTISELECT;
     ofn.lStructSize = sizeof(ofn);
     ofn.lpstrFile = szOpenFileNames;
     ofn.nMaxFile = sizeof(szOpenFileNames);
     ofn.lpstrFile[0] = '\0';
     ofn.lpstrFilter = TEXT("ALL\0*.*\0MP3\0*.MP3\0");
     if( GetOpenFileName( &ofn ) )
     {  
        lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );

        szPath[ ofn.nFileOffset ] = '\0';
        nLen = lstrlen(szPath);
  
        if( szPath[nLen-1] != '\\' )   //如果选了多个文件,则必须加上'\\'
        {
            lstrcat(szPath, TEXT("\\"));
        }
  
        p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
  
        ZeroMemory(szFileName, sizeof(szFileName));
        ZeroMemory(szFileNamePath, sizeof(szFileNamePath));   
        while( *p )
        {   
            lstrcpy(szFileNamePath, szPath);    //给文件加上路径
            lstrcpy(szFileName, p);                //只加上文件名
            lstrcat(szFileNamePath, p);            //给文件加上名字
            HWND hwndCombo2 = GetDlgItem(hwnd,IDC_LIST2);
            ListBox_InsertString(hwndCombo2,-1,szFileNamePath);
             HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);
            ListBox_InsertString(hwndCombo,-1,szFileName);
            p += lstrlen(p) +1;                 //移至下一个文件
        }
     }
}


//******************播放歌曲**********************
void PlaySong(HWND hwnd, UINT curSel)
{
    TCHAR str[256];
    TCHAR strPath[256];
    TCHAR cmd[MAX_PATH +10];

    ClosePrensentSong(hwnd);
    PresentSongcurSel = curSel;
    HWND hwndCombo = GetDlgItem(hwnd,IDC_LIST);   
    UINT sum = ListBox_GetCount(hwndCombo);
    if (PresentSongcurSel < sum)
    {
        HWND hwndCombo2 = GetDlgItem(hwnd,IDC_LIST2);   
        HWND hwndSong = GetDlgItem(hwnd,IDC_SONGNAME);               
        ListBox_GetText(hwndCombo2,curSel,strPath);        
        ListBox_GetText(hwndCombo,curSel,str);
        ListBox_SetCurSel(hwndCombo,PresentSongcurSel);
        SetWindowText(hwndSong,str);                            //显示歌曲名字
        GetShortPathName(strPath,ShortPathName,sizeof(ShortPathName));
        TotletimeSe(hwnd);
        wsprintf(cmd,"play %s",ShortPathName);
        mciSendString(cmd,"",0,NULL);     
        SetTimer(hwnd,0,1000,TimerProc);
        if (PauseFlag == 1)
        {               
            HWND hwndCombo = GetDlgItem(hwnd,IDC_PAUSE);
            SetWindowText(hwndCombo,TEXT(" 播放"));   
        }
    }
    else
    {
        PlaySong(hwnd,0);
    }
}

//*****************暂停当前歌曲********************
void PausePrensentSong(HWND hwnd)
{
    TCHAR cmd[MAX_PATH +10];
    wsprintf(cmd,"pause %s",ShortPathName);
    mciSendString(cmd,"",0,NULL);   
    PauseFlag = 1;   
}

//*****************继续当前歌曲*********************
void RePausePrensetSong(HWND hwnd)
{
    TCHAR cmd[MAX_PATH +10];
    wsprintf(cmd,"resume %s",ShortPathName);
    mciSendString(cmd, NULL, 0, NULL);
    PauseFlag = 0;
}


//*************关闭当前播放歌曲**********************
void ClosePrensentSong(HWND hwnd)
{
    TCHAR cmd[MAX_PATH +10];
    wsprintf(cmd,"close %s",ShortPathName);
    mciSendString(cmd,"",0,NULL);
}

/*****   
函数名称:  MusicTotalTime   
函数功能:    计算一首歌的总时间
*****/
void TotletimeSe(HWND hwnd)
{   
    TCHAR musicTotalLength[256];
    int intSecond;
    int intMinute;
    TCHAR musicTotleTime[256];
    TCHAR cmdL[MAX_PATH +10];

    wsprintf(cmdL,"status %s length",ShortPathName);
    mciSendString(cmdL,musicTotalLength,255,NULL);                    //获得歌曲的长度
    totalSecond = atoi(musicTotalLength)/1000;                        //总时间(毫秒)除以1000得到(整数)总秒数
    intMinute = totalSecond / 60;                                    //总秒数除以6得到(整数)分钟数
    intSecond = (totalSecond - intMinute*60);                        //总秒数减去(整数)分钟*60得到剩余秒数

    wsprintf(musicTotleTime,"%02d:%02d",intMinute,intSecond);        //02s表示时间分钟或秒数共两位数不足补0;               
    HWND hwndSongTime = GetDlgItem(hwnd,IDC_TOTLETIME);
    SetWindowText(hwndSongTime,musicTotleTime);
}

编译组件都没错就是运行不起来,连窗口都不弹出来

</sum;i++)
搜索更多相关主题的帖子: include 歌曲 
2014-02-15 17:24
佳嘉
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:3
帖 子:534
专家分:1383
注 册:2009-11-8
得分:0 
链接错误?
2014-02-15 18:34
hamuamu0
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-1-25
得分:0 
回复 2楼 佳嘉
链接组建都没错误,但就是点运行时程序出不来
2014-02-18 12:40



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




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

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