项目: 用C语言写一个精美图形化的音乐播放器【C++ / C】
生活随笔
收集整理的這篇文章主要介紹了
项目: 用C语言写一个精美图形化的音乐播放器【C++ / C】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 最終效果
- 代碼
- 資源地址
最終效果
代碼
/************ 1開頭的是周杰倫的歌 2開頭的是林俊杰的歌 3開頭的是許嵩的歌 *************/ #include<stdio.h> #include<windows.h> #include<mmsystem.h> #pragma comment(lib,"Winmm.lib") #include<graphics.h> #include<stdlib.h> #include<conio.h>void zhoujielun(); void menu_zhou(); void linjunjie(); void menu_linjunjie(); void xusong(); void menu_xusong(); void qita(); void menu_qita(); void menu();#define width 400//窗口的大小 #define height 500int i=0;void zhoujielun()//周杰倫歌曲 {char input;menu_zhou();//加載周杰倫曲目圖像IMAGE imga,imgb,imgc,imgd;loadimage(&imga,"1愛的飛行日記.png",145,42); loadimage(&imgb,"1稻香.png",145,42);loadimage(&imgc,"1七里香.png",145,42);loadimage(&imgd,"1晴天.png",145,42);while(1){if(kbhit())//判斷是否有輸入{mciSendString("close bkmusic", NULL, 0, NULL);//關閉歌曲 input=getch();if(input=='e')break;switch(input){case 'a':mciSendString("open 1愛的飛行日記.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); //循環播放音樂putimage(6,465,&imga);break;case 'b':mciSendString("open 1稻香.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgb);break;case 'c':mciSendString("open 1七里香.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgc);break;case 'd':mciSendString("open 1晴天.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgd);break;}}} } void menu_zhou() {char input;IMAGE mg;cleardevice();loadimage(&mg,"周杰倫.png",400,500);putimage(0,0,&mg);settextcolor(CYAN);settextstyle(28,0,"宋體");outtextxy(130,20,"周杰倫曲目");settextstyle(24,0,"宋體");outtextxy(122,90,"a. 愛的飛行日記");outtextxy(124,170,"b. 稻香");outtextxy(124,240,"c. 七里香");outtextxy(124,310,"d. 晴天");outtextxy(124,380,"e. 返回主菜單");settextstyle(18,0,"宋體");outtextxy(6,440,"help:請輸入你想聽的歌曲所對應的字母"); } void linjunjie()//林俊杰歌曲 {char input;IMAGE imga,imgb,imgc,imgd;menu_linjunjie();loadimage(&imga,"2被風吹過的夏天.png",145,42); loadimage(&imgb,"2心墻.png",145,42);loadimage(&imgc,"2她說.png",145,42);loadimage(&imgd,"2愛笑的眼睛.png",145,42);while(1){if(kbhit())//判斷是否有輸入{mciSendString("close bkmusic", NULL, 0, NULL);//關閉歌曲 input=getch();if(input=='e')break;switch(input){case 'a':mciSendString("open 2被風吹過的夏天.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imga);break;case 'b':mciSendString("open 2心.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgb);break;case 'c':mciSendString("open 2她說.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgc);break;case 'd':mciSendString("open 2愛笑的眼睛.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgd);break;}}} } void menu_linjunjie() {char input;IMAGE mg;cleardevice();loadimage(&mg,"林俊杰.png",400,500);putimage(0,0,&mg);settextcolor(GREEN);settextstyle(28,0,"宋體");outtextxy(135,20,"林俊杰曲目");settextstyle(24,0,"宋體");outtextxy(122,90,"a. 被風吹過的夏天 ");outtextxy(124,160,"b. 心墻");outtextxy(124,230,"c. 她說");outtextxy(124,300,"d. 愛笑的眼睛");outtextxy(124,370,"e. 返回主菜單");settextstyle(18,0,"宋體");outtextxy(6,440,"help:請輸入你想聽的歌曲所對應的字母"); } void xusong()//許嵩歌曲 {char input;menu_xusong();IMAGE imga,imgb,imgc,imgd;loadimage(&imga,"3幻聽.png",145,42); loadimage(&imgb,"3素顏.png",145,42);loadimage(&imgc,"3灰色頭像.png",145,42);loadimage(&imgd,"3玫瑰花的葬禮.png",145,42);while(1){if(kbhit())//判斷是否有輸入{mciSendString("close bkmusic", NULL, 0, NULL); input=getch();if(input=='e')break;switch(input){case 'a':mciSendString("open 3幻聽.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imga);break;case 'b':mciSendString("open 3素顏.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgb);break;case 'c':mciSendString("open 3灰色頭像.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgc);break;case 'd':mciSendString("open 3玫瑰花的葬禮.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgd);break;}}} } void menu_xusong() {char input;IMAGE mg;cleardevice();loadimage(&mg,"許嵩.png",400,500);putimage(0,0,&mg);settextcolor(GREEN);settextstyle(28,0,"宋體");outtextxy(135,20,"許嵩曲目");settextstyle(24,0,"宋體");outtextxy(122,90,"a. 幻聽 ");outtextxy(124,160,"b. 素顏");outtextxy(124,230,"c. 灰色頭像");outtextxy(124,300,"d. 玫瑰花的葬禮");outtextxy(124,370,"e. 返回主菜單");settextstyle(18,0,"宋體");outtextxy(6,440,"help:請輸入你想聽的歌曲所對應的字母"); } void qita()//混雜曲庫 {char input;menu_qita();IMAGE imga,imgb,imgc,imgd,imge,imgf,imgg,imgh;loadimage(&imga,"Love.png",145,42); loadimage(&imgb,"認真的老去.png",145,42);loadimage(&imgc,"星.png",145,42);loadimage(&imgd,"無名之輩.png",145,42);loadimage(&imge,"不知所措.png",145,42);loadimage(&imgf,"十年.png",145,42);loadimage(&imgg,"勛章.png",145,42);loadimage(&imgh,"夜航星.png",145,42);while(1){if(kbhit())//判斷是否有輸入{mciSendString("close bkmusic", NULL, 0, NULL); input=getch();if(input=='i')break;switch(input){case 'a':mciSendString("open Love.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imga);break;case 'b':mciSendString("open 認真的老去.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgb);break;case 'c':mciSendString("open 星.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgc);break;case 'd':mciSendString("open 無名之輩.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgd);break;case 'e':mciSendString("open 不知所措.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imge);break;case 'f':mciSendString("open 十年.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL);putimage(6,465,&imgf);break;case 'g':mciSendString("open 勛章.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgg);break;case 'h':mciSendString("open 夜航星.mp3 alias bkmusic", NULL, 0, NULL);mciSendString("play bkmusic repeat", NULL, 0, NULL); putimage(6,465,&imgh);break;}}} } void menu_qita() {char input;IMAGE mg;cleardevice();loadimage(&mg,"其他.png",400,500);putimage(0,0,&mg);settextcolor(RED);settextstyle(28,0,"宋體");outtextxy(135,20,"混雜曲庫");settextstyle(24,0,"宋體");outtextxy(20,90,"a.Love Story");outtextxy(220,90,"b.認真的老去 ");outtextxy(20,160,"c.夜空中最亮的星");outtextxy(220,160,"d.無名之輩");outtextxy(20,230,"e.不知所措");outtextxy(220,230,"f.十年");outtextxy(20,300,"g.勛章");outtextxy(220,300,"h.夜航星");outtextxy(100,370,"i.返回主菜單");settextstyle(18,0,"宋體");settextcolor(YELLOW);outtextxy(6,440,"help:請輸入你想聽的歌曲所對應的字母"); } void mi() {char input;IMAGE mg;cleardevice();loadimage(&mg,"作者.png",400,500);putimage(0,0,&mg);settextcolor(RED);settextstyle(28,0,"宋體");outtextxy(135,20,"作者簡介");settextstyle(16,0,"宋體");outtextxy(10,60,"作者輝小歌,");outtextxy(10,100,"是一個正在努力學習的菜鳥");outtextxy(10,140,"作者在這里謝謝大家的使用!");outtextxy(100,370,"a.返回主菜單");while(1){input=getch();if(input=='a')break;} } void menu() {char input;IMAGE mg;loadimage(&mg,"1.png",400,500);//加載圖片putimage(0,0,&mg);//從起點繪制圖片settextcolor(YELLOW);//設置字體顏色settextstyle(28,0,"consolas");//設置字體大小和格式setbkmode(TRANSPARENT);//去掉字體輸出的黑色背景outtextxy(114,15,"炫歌電臺為你服務");settextstyle(24,0,"宋體");outtextxy(124,90,"a. 周杰倫");outtextxy(124,150,"b. 林俊杰");outtextxy(124,210,"c. 許嵩");outtextxy(126,270,"d. 混雜曲庫");outtextxy(128,330,"e. 關于作者");outtextxy(130,390,"f. 退出");settextstyle(16,0,"consolas");outtextxy(10,440,"請輸入你想聽的歌手所對應的字母");outtextxy(10,460,"例: 聽周杰倫 請按 a(小寫)");input=_getch();switch(input){case 'a':zhoujielun();break;case 'b':linjunjie();break;case 'c':xusong();break;case 'd':qita();break;case 'e':mi();break;case 'f':i++;closegraph();break;} }int main(void) {initgraph(width,height);while(1){menu();if(i==1){return 0;break;}}return 0; }資源地址
鏈接:https://pan.baidu.com/s/1-T8SoWwpC5iX7xEte1dSkQ 提取碼:1234總結
以上是生活随笔為你收集整理的项目: 用C语言写一个精美图形化的音乐播放器【C++ / C】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 项目: 用C语言写一个图形化的音乐播放器
- 下一篇: 第七讲 贪心