多线程

#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include <thread>
#include<graphics.h>
#include<conio.h>
#include <fstream>
#include <string>
#pragma comment(lib,"Winmm.lib")
using namespace std;

#define BG_SIZE_WIDTH 1024
#define BG_SIZE_HEIGTH 768
#define START_X 150
#define START_Y 80
#define X_OFFSET 31
#define Y_OFFSET 31
#define PIC_SIZE_WIDTH 1536/2
#define PIC_SIZE_HEIGHT 2048/2
#define TYPEFACE_SIZE 24

void painButton(int leftX,int leftY,int righgtX,int rightY,int textX,int textY,const char str[]) {

//setlinecolor(YELLOW);
setfillcolor(GREEN);        // 填充为蓝色
setcolor(WHITE);
fillrectangle(leftX, leftY, righgtX, rightY);

outtextxy(textX, textY, str); //textX 文本X坐标  textY 文本Y坐标

}

void button() {
string str=“播放”;

painButton(806,140,841+12,158+10,807,141,str.c_str());

}
void button2() {
string str = “暂停”;
painButton(875, 140, 910+12, 158+10, 876, 141, str.c_str());
}

void printSTR() {

	IMAGE bgimg;
	initgraph(BG_SIZE_WIDTH, BG_SIZE_HEIGTH);
	setcolor(BLACK);
	settextstyle(TYPEFACE_SIZE, 0, "楷体");
	loadimage(&bgimg, _T("shaomo.jpg"), PIC_SIZE_WIDTH, PIC_SIZE_HEIGHT,FALSE);
	putimage(0, 0, &bgimg);
	setbkmode(TRANSPARENT);

char str[] = "给自己的一封信!那天过后,我们已经形同陌路";
char str2[] = ",在我的心中,早已没有了你的存在!";
 outtextxy(START_X, START_Y,str);
 outtextxy(START_X, START_Y+ Y_OFFSET, str2);
 button();
 button2();
 

	//int len = strlen(str);
	//char tmp[3] = { 0 };
	//for (int i = 0; i < len; ) {
	//	memset(tmp, 0, 3);
	//	if (str[i] >= 0x80) {
	//		strncpy(tmp, &(str[i]), 2);
	//		i += 2;
	//	}

	//	else {
	//		strncpy(tmp, &(str[i]), 1);
	//		i += 1;

	//	}
	//	//printf("%s", tmp);
	//	int w = 0, h = 0;
	//
	//	for (int i = 0; i < 400;i++) {
	//	
	//		outtextxy(w, h, tmp);
	//		w += 10;
	//	
	//	}
		

	_getch();
	closegraph();

}
void consolePrintLyric() {
ifstream infile;
string line;
infile.open(“data.txt”);
if (infile.fail()) {

	printf("文件打开失败!");
	return;
}
while (!infile.eof()) {
	getline(infile, line);
	char str[256];
	strcpy(str, line.c_str());
	int len = strlen(str);



	char tmp[3] = { 0 };
	for (int i = 0; i < len; ) {
		memset(tmp, 0, 3);
		if (str[i] >= 0x80) {
			strncpy(tmp, &(str[i]), 2);
			i += 2;
		}

		else {
			strncpy(tmp, &(str[i]), 1);
			i += 1;

		}
		printf("%s", tmp);
		Sleep(100);
	}
	printf("\n");

}

}

void playmusic() {
while (1) {
PlaySound(TEXT(“陈慧娴 - 月半小夜曲(Live)【有间音乐】.wav”), NULL, SND_FILENAME);

}

}
void musicLyric() {

initgraph(BG_SIZE_WIDTH/3, BG_SIZE_HEIGTH);
setbkcolor(GREEN);
cleardevice();

outtextxy(100, 100, "歌词线程");
_getch();

closegraph();

}
int main(void){

//thread mytread(printSTR);
thread myconsole(consolePrintLyric);
thread mymusic(playmusic);
//thread mymusicLyric(musicLyric);

//mytread.join();
myconsole.join();
mymusic.join();
//mymusicLyric.join();

return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值