C++ 图形界面学习效果及代码

cpp 复制代码
#include <stdio.h>
#include<conio.h>
#include <stdlib.h> 
#include<graphics.h>
#define WIDTH 800
#define HEIGHT 480
#define SIZE 20
int main() {
	const char* str = "人生就是由欲望不满足而痛苦和满足之后无趣这两者所构成";
	const char* str1 = "每个人都没有绝对的道德底线,只是诱惑不够";
	IMAGE img,da;
	loadimage(&img, "gui.png"); 
	loadimage(&da, "da.gif");

	initgraph(WIDTH, 480);


	int i = 0;
	while (1) {
		setbkcolor(i++ * 10 % 0xffffff);
		clearcliprgn();
		putimage(70, 70, &img);
		putimage(170, 170, &img);
		//putimage(170, 0, &da);
		for (int i = 0; i <= WIDTH / SIZE; i++) {
			for (int j = 0; j <= HEIGHT / SIZE; j++) {				
				rectangle(i * SIZE, j * SIZE, SIZE, SIZE);
			}
		}		
		settextstyle(24, 0, "宋体"); // 设置字体大小和样式
		settextcolor(YELLOW);
		outtextxy(20, 20, str); // 在指定位置输出汉字

		settextstyle(24, 0, "黑体"); // 设置字体大小和样式
		settextcolor(RED);
		outtextxy(20, 80, str1); // 在指定位置输出汉字
				
		rectangle(18, 18, 20 + strlen(str) * 12, 44); // 绘制长方形

		getch();
		clearcliprgn();
	}
	
	return 0;
}
相关推荐
苦瓜小生10 分钟前
【前端】|【js手撕】经典高频面试题:手写实现function.call、apply、bind
java·前端·javascript
mounter62537 分钟前
Linux 7.0 重磅更新:详解 nullfs 如何重塑根文件系统挂载与内核线程隔离
linux·运维·服务器·kernel
NGC_66111 小时前
Java 线程池:execute () 和 submit () 到底有什么区别?
java
cngm1101 小时前
解决麒麟v10下tomcat无法自动启动的问题
java·tomcat
色空大师1 小时前
【网站搭建实操(一)环境部署】
java·linux·数据库·mysql·网站搭建
客卿1231 小时前
牛客刷题--找数字-- 字符串检测-字符串 双指针
java·开发语言
烛之武1 小时前
SpringBoot基础
java·spring boot·后端
-Da-1 小时前
Unix哲学:一切皆文件与网络通信的统一抽象
服务器·unix
Amour恋空2 小时前
Java多线程
java·开发语言·python
小胖java2 小时前
高校培养方案制定系统
java·spring