纯c语言---大作业--实现音乐播放器

news/2024/11/30 2:26:41/

注意点

1,<graphics.h>需要自己下载

2,在使用vs2019时需要改一下设置

项目->属性->使用多字节字符集

实现过于匆忙,草率,代码略显粗糙,望读者海涵,毕竟我是萌新弱鸡。

#define _CRT_SECURE_NO_WARNINGS 
#include <windows.h>
#include<stdio.h>
#include<windows.h>
#include<mmsystem.h>//多媒体库
#include<conio.h>
#include<string>
#include<string.h>
#include<graphics.h>//图形库
#pragma comment(lib, "Winmm.lib")
typedef struct Button//建立我的按钮
{int x;int y;int xx;int yy;COLORREF color;char* buttonStr;
}BTN,*LPBTN;
LPBTN create_Button(int x, int y, int xx, int yy, COLORREF color, char* buttonStr)//定义button坐标结构体
{LPBTN button = (LPBTN)malloc(sizeof(BTN));//坐标信息button->x = x;button->y = y;button->xx = xx;button->yy = yy;button->color = color;button->buttonStr = (char*)malloc(strlen(buttonStr) + 1);strcpy(button->buttonStr, buttonStr);return button;
}
//void go_music();//播放音乐
void drawButton(LPBTN drybut);//画button
int  isinbutton(LPBTN isbut, MOUSEMSG m)//判断鼠标是否在这个isbut的上面
{if (isbut->x <= m.x && m.x <= isbut->xx && isbut->y <= m.y && isbut->yy >= m.y){return 1;}return 0;
}
void  play_Mouse(LPBTN play, MOUSEMSG m);//当鼠标移动到我们的button上面的时候,我们改变button的color
int clickButton(LPBTN but, MOUSEMSG m);//点击屏幕
void click(int flag, LPBTN play, LPBTN   pause, LPBTN resume, LPBTN close, MOUSEMSG m);
int main()
{//加载并添加图片initgraph(800, 600);int num = 1;IMAGE background;loadimage(&background, "3.jpg", 800, 600);putimage(0, 0, &background);//打开我的音乐mciSendString("open temp.mp3", 0, 0, 0);mciSendString("open 1.mp3", 0, 0, 0);mciSendString("open 2.mp3", 0, 0, 0);mciSendString("open 3.mp3", 0, 0, 0);mciSendString("open 4.mp3", 0, 0, 0);char ch;//定义我的按钮们LPBTN play = create_Button(10, 200, 160, 250,YELLOW,"播放音乐");LPBTN pause = create_Button(10, 260, 160, 310, YELLOW, "暂停音乐");LPBTN resume = create_Button(10, 320, 160, 370, YELLOW, "继续音乐");LPBTN next = create_Button(10, 380, 160, 430, YELLOW, "下一首");LPBTN close = create_Button(10, 440, 160, 490, YELLOW, "关闭音乐");int flag = 0;//通过flag来切换歌曲。while (1) //执行播放器{ //画出我们的buttonBeginBatchDraw();cleardevice();putimage(0, 0, &background);drawButton(play);drawButton(pause);drawButton(resume);drawButton(close);drawButton(next);//获得鼠标信息MOUSEMSG m = GetMouseMsg();play_Mouse(play, m);play_Mouse(pause, m);play_Mouse(resume, m);play_Mouse(close, m);play_Mouse(next, m);EndBatchDraw();if (clickButton(next, m))//切换音乐{if (flag == 0){mciSendString("close temp.mp3", 0, 0, 0);mciSendString("play 1.mp3", 0, 0, 0);}else if (flag == 1){mciSendString("close 1.mp3", 0, 0, 0);mciSendString("play 2.mp3", 0, 0, 0);}else if (flag == 2){mciSendString("close 2.mp3", 0, 0, 0);mciSendString("play 3.mp3", 0, 0, 0);}else if (flag == 3){mciSendString("close 3.mp3", 0, 0, 0);mciSendString("play 4.mp3", 0, 0, 0);}else if (flag == 4){mciSendString("close 4.mp3", 0, 0, 0);mciSendString("play temp.mp3", 0, 0, 0);}flag++;flag = flag % 5;}click(flag, play, pause, resume, close, m);}ch = getchar();///暂停,防止程序结束return 0;
}  void add_background()
{initgraph(800, 600);int num = 1;IMAGE background;loadimage(&background, "3.jpg", 800, 600);putimage(0, 0, &background);char ch;
}
void add_background1()
{initgraph(800, 600);int num = 1;IMAGE background;loadimage(&background, "3.jpg", 800, 600);putimage(0, 0, &background);char ch;
} 
void  play_Mouse(LPBTN play, MOUSEMSG m)
{if (isinbutton(play, m)){play->color = RED;}else play->color = GREEN;
}
int clickButton(LPBTN but, MOUSEMSG m)
{if (isinbutton(but, m)){//windows message left button dowmif (m.uMsg == WM_LBUTTONDOWN){return 1;}}return 0;
}
void click(int flag, LPBTN play, LPBTN   pause, LPBTN resume, LPBTN close, MOUSEMSG m)
{if (flag == 0){if (clickButton(play, m)){mciSendString("play temp.mp3", 0, 0, 0);}if (clickButton(pause, m)){mciSendString("pause temp.mp3", 0, 0, 0);}if (clickButton(resume, m)){mciSendString("resume temp.mp3", 0, 0, 0);}if (clickButton(close, m)){mciSendString("close temp.mp3", 0, 0, 0);}}else if (flag == 1){if (clickButton(play, m)){mciSendString("play 1.mp3", 0, 0, 0);}if (clickButton(pause, m)){mciSendString("pause 1.mp3", 0, 0, 0);}if (clickButton(resume, m)){mciSendString("resume 1.mp3", 0, 0, 0);}if (clickButton(close, m)){mciSendString("close 1.mp3", 0, 0, 0);}}else if (flag == 2){if (clickButton(play, m)){mciSendString("play 2.mp3", 0, 0, 0);}if (clickButton(pause, m)){mciSendString("pause 2.mp3", 0, 0, 0);}if (clickButton(resume, m)){mciSendString("resume 2.mp3", 0, 0, 0);}if (clickButton(close, m)){mciSendString("close 2.mp3", 0, 0, 0);}}else if (flag == 3){if (clickButton(play, m)){mciSendString("play 3.mp3", 0, 0, 0);}if (clickButton(pause, m)){mciSendString("pause 3.mp3", 0, 0, 0);}if (clickButton(resume, m)){mciSendString("resume 3.mp3", 0, 0, 0);}if (clickButton(close, m)){mciSendString("close 3.mp3", 0, 0, 0);}}else if (flag == 4){if (clickButton(play, m)){mciSendString("play 4.mp3", 0, 0, 0);}if (clickButton(pause, m)){mciSendString("pause 4.mp3", 0, 0, 0);}if (clickButton(resume, m)){mciSendString("resume 4.mp3", 0, 0, 0);}if (clickButton(close, m)){mciSendString("close 4.mp3", 0, 0, 0);}}
}
void drawButton(LPBTN drybut)
{setlinecolor(RED);setfillcolor(drybut->color);fillrectangle(drybut->x, drybut->y, drybut->xx, drybut->yy);setbkmode(TRANSPARENT);settextcolor(BLACK);settextstyle(30, 0, "楷体");outtextxy(drybut->x + 15, drybut->y + 10, drybut->buttonStr);
}

http://www.ppmy.cn/news/521413.html

相关文章

小米10青春版和小米10有什么区别 哪个好

小米10外观上&#xff0c;小米10采用了6.67"AMOLED小挖孔曲面屏&#xff0c;支持90Hz刷新率&#xff0c;180Hz触控采样率。包罗阳光屏3.0&#xff0c;峰值亮度1120nit亮度&#xff0c;5000000&#xff1a;1对比度。而且采用柔性屏COP工艺&#xff0c;3.32mm小下巴。搭载前…

小米10青春版刷鸿蒙,功能齐全也不行!小米10青春版现已跌至新低价,高刷已成趋势?...

今年的手机市场真的是各大厂商发力的一年&#xff0c;因为早在2019年&#xff0c;各大手机品牌制造商就陆续发布了5G旗舰机&#xff0c;但价格都相对偏高&#xff0c;然而到了2020年之后&#xff0c;手机厂商都在发布5G新机&#xff0c;结合市场中的行情&#xff0c;直接让5G手…

C语言课设-C语言期末大作业-购书系统(附源码下载链接)

C语言课设-C语言期末大作业-购书系统 介绍 C语言课设&#xff1a;购书系统 软件架构 主要架构&#xff1a; admin.txt 管理员信息存档book.txt 书籍信息存档user.txt 用户信息存档&#xff08;可以保存相关信息&#xff09;file.h 文件存储驱动main.c 主程序文件struct.h …

小米路由器青春版(R1CL)刷breed固件

文中所列方法仅为个人实践结果&#xff0c;请大家根据各自实际情况进行调整&#xff0c;谨慎操作。 小米路由器青春版 &#xff0c;采用 Micro USB 接口&#xff0c;和小米路由器的 USB A 接口不同。重置键位于路由器背部&#xff0c;镂空小孔阵列的右上角&#xff08;有 Reset…

小米8青春版刷入Ubuntu Touch教程

刷入前的准备&#xff1a;解bl锁&#xff0c;刷第三方rec 大致步骤&#xff1a;1、刷入魔趣9&#xff08;因为基于魔趣内核编译&#xff09; 2、刷内核 3、刷补丁 4、刷Ubuntu Touch GSI 第一步&#xff1a;1、刷入魔趣9底包 2、刷入魔趣9 第二部&#xff1a;刷入halium-boo…

c语言播放背景音乐

相信很多童鞋都在为大学课设而伤透头脑&#xff0c;而背景音乐的使用无疑会成为其中的一个亮点&#xff08;总比没有好吧(╯▽╰)&#xff09;&#xff0c;故接下来我将介绍一下如何用C播放音乐。 我用的编译器是CodeBlocks16.01 接下来新建一个C文件 建立完后是这样滴 然后添…

oppok7和小米10青春版 的区别 哪个好

外观上&#xff0c;oppok7采用了一块6.57英寸的水滴屏&#xff0c;机身背部摄像头采用的是普通竖排排列方式&#xff0c;有四种颜色设计&#xff0c;分别是海夜、秘境、流云和流焰。 小米10青春版更多使用感受和评价&#xff1a;https://www.xiaomi.cn/10 oppok7更多使用感受和…

C++(10):泛型算法

泛型算法&#xff1a;可用于不同类型的容器和不同类型的元素的通用算法。 概述 大多数算法都定义在头文件algorithm 中。标准库在头文件 numeric 中定义了一组数值泛型算法。 一般情况下&#xff0c;泛型算法不直接操作容器&#xff0c;而是遍历由两个迭代器指定的一个元素范…