栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C/C++简易版音乐播放器图形库制作

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C/C++简易版音乐播放器图形库制作

使用时将项目属性字符集改成“使用多字节字符集”,符合模式改为“否”。

代码中部分文件来源于本地文件,使用时需自行更换(代码中有注释)。

#define _CRT_SECURE_NO_WARNINGS 

#include 
#include 
#include 
#include 
#include 
#include 

#pragma comment(lib,"winmm.lib") 



typedef struct Button {
	int x;
	int y;
	int	xx;
	int yy;
	COLORREF color;
	char* buttonStr;
}BTN, * LPBTN;



//做按钮:
//1、确定按钮的属性----》创建按钮的过程
LPBTN createButton(int x, int y, int xx, int yy, COLORREF color, char* buttonStr) {
	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 drawButton(LPBTN pButton) {
	setlinecolor(BLACK);
	setfillcolor(pButton->color);
	fillrectangle(pButton->x, pButton->y, pButton->xx, pButton->yy);
	setbkmode(TRANSPARENT);
	settextcolor(BLACK);
	settextstyle(30, 0, "楷体");
	outtextxy(pButton->x + 15, pButton->y + 10, pButton->buttonStr);
}

//判断鼠标位置
int IsinButton(LPBTN pButton,MOUSEMSG m) {
	if (pButton->x <= m.x && m.x <= pButton->xx && pButton->y <= m.y && pButton->yy >= m.y) {
		return 1;
	}
	return 0;
}

//按钮颜色效果
void Color(LPBTN pButton, MOUSEMSG m) {
	if (IsinButton(pButton, m)) {
		pButton->color = RGB(142, 210, 138);
	}
	else {
		pButton->color = YELLOW;
	}
}

//鼠标点击功能
int clickButton(LPBTN pButton, MOUSEMSG m) {
	if (IsinButton(pButton, m)) {

		if (m.uMsg == WM_LBUTTONDOWN) {
			return 1;
		}
	}
	return 0;
}


int main() {


	//打开音乐文件
	mciSendString("open be.mp3    ", 0, 0, 0);
	//按钮的使用
	LPBTN play = createButton(300,200,450,250,YELLOW,"播放音乐");
	LPBTN pause = createButton(300,260,450,310,YELLOW,"暂停音乐");
	LPBTN resume = createButton(300,320,450,370,YELLOW,"继续音乐");
	LPBTN close = createButton(300,380,450,430,YELLOW,"关闭音乐");

	//创建窗口
	initgraph(800, 600);
	

	//识别鼠标动作
	MOUSEMSG m;
	//图片类型定义===IMAGE
	IMAGE bk;
	//加载图片
	loadimage(&bk, "背景.png    ", 800, 600);

	while (1) {
		BeginBatchDraw();
		cleardevice();
		putimage(0, 0, &bk);        //放置背景图片
		drawButton(play);
		drawButton(pause);
		drawButton(resume);
		drawButton(close);
		MOUSEMSG m = GetMouseMsg();			//获取鼠标消息
		Color(play,m);
		Color(pause,m);
		Color(resume,m);
		Color(close,m);
		if (clickButton(play, m)) {
			//音乐加载指令
			//播放音乐文件
			mciSendString("play be.mp3    ", 0, 0, 0);
		}
		if (clickButton(pause, m)) {
			//暂停音乐
			mciSendString("pause be.mp3    ", 0, 0, 0);
		}
		if (clickButton(resume, m)) {
			//继续音乐
			mciSendString("resume be.mp3    ", 0, 0, 0);
		}
		if (clickButton(close, m)) {
			//关闭音乐
			mciSendString("close be.mp3    ", 0, 0, 0);
			exit(0);
		}

		EndBatchDraw();
	}
	
	
	_getch();
	closegraph();
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/297192.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号