VS导入easyx图形库

初学C/C++的人应该都会一个疑惑,为什么C/C++不能进行图形编程?
虽然C/C++没有自带的图形库,但我们可以自己导入其他图形库,想graphcis.h之类的。
下面,我将介绍如何在VS中导入easyx图形库。

下载easyx图形库

easyx图形库可以到官网下载。这里我下载的是2018春分版,下面也将以这个为例进行介绍。
下载完成之后,虽然是一个应用程序,但我们可以右键进行解压(如果右键没有这一选项,就去下载一个解压软件,如WinRAR),解压后的文件如图所示。
在这里插入图片描述

导入easyx图形库

解压之后,将include中的两个文件放到VS相应include目录中,lib中的文件一样。
如图所示。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
将文件都拷贝到VS的目录下面之后,就成功导入easyx图形库了。可以写一个代码检测一下:

#include "pch.h"
#include <iostream>
#include<stdlib.h>
#include <graphics.h>
#include<math.h>
#include <windows.h>  

DWORD WINAPI drawCircle(LPVOID lpParam) {
	
	double pi = 3.1415926;

	for (int i = 0; i < 800; i++) {
		int x = 200 + 100*cos(i*pi/400);
		int y = 200 + 100*sin(i*pi/400);
		putpixel(x, y, RED);
		Sleep(10);
	}
	return 0;
}

DWORD WINAPI drawRectangle(LPVOID lpParam) {
	int x, y;
	for (int i = 0; i < 800; i++) {
		if (i < 200) {
			x = 500 + i;
			y = 100;
		}
		else if (i < 400) {
			x = 700;
			y = 100 + (i-200);
		}
		else if (i < 600) {
			x = 700 - (i - 400);
			y = 300;
		}
		else {
			x = 500;
			y = 300 - (i - 600);
		}
		putpixel(x, y, RED);
		Sleep(10);
	}
	return 0;
}

int main(){
	initgraph(800, 400);
	setbkcolor(YELLOW);
	HANDLE hThread[2];
	hThread[0] = CreateThread(NULL, 0, drawCircle, NULL, 0, NULL);
	hThread[1] = CreateThread(NULL, 0, drawRectangle, NULL, 0, NULL);
	WaitForMultipleObjects(2, hThread, TRUE, INFINITE); 	//等待子线程运行 
	system("pause");
	closegraph();          // 关闭绘图窗口
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章