#include<iostream>
#include<easyx.h>
#include<conio.h>
#include<graphics.h>//包含windows.h
#include<mmsystem.h>//使用_getch()
#pragma comment(lib,"winmm.lib")
using namespace std;
void change()
{
//获取窗口句柄
HWND hnd = GetHWnd();
//设置窗口标题
SetWindowText(hnd, "small pink pig");
}
int main()
{
initgraph(800, 600, EX_SHOWCONSOLE);
setbkcolor(WHITE);//设置背景颜色
cleardevice();//用设置的背景颜色填充
setbkmode(TRANSPARENT);
change();//窗口文字
// 设置默认颜色和笔刷大小
COLORREF currentColor = RED;
static int size = 5;
int flag = 0;
int freams = 4;
int ys = (flag + freams) % freams;
while (true)
{
// 处理鼠标事件
if (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
// 绘制印记
BeginBatchDraw();
if (msg.mkLButton)
{
setfillcolor(currentColor);
solidcircle(msg.x, msg.y, size);
FlushBatchDraw();
printf("%d, %d\n", msg.x, msg.y);
}
EndBatchDraw();
}
// 处理键盘事件
if (_kbhit())
{
int key = _getch();
if (key == 'A')
{
flag--;
printf("A\n");
}
else if (key == 'D')
{
flag++;
printf("D\n");
}
else if (key == 'Q')
{
size = max(1, size - 5);
printf("Q\n");
}
else if (key == 'E')
{
size = min(25, size + 5);
printf("E\n");
}
}
if (flag < 0) flag = 3;
ys = (flag + freams) % freams;
switch (ys)
{
case 0:
currentColor = RED;
break;
case 1:
currentColor = RGB(255, 174, 201);
break;
case 2:
currentColor = BLACK;
break;
case 3:
currentColor = WHITE;
break;
}
}
_getch();//按任意键退出
closegraph();
return 0;
}
使用easyx制作一个绘画程序
最新推荐文章于 2024-09-16 11:29:33 发布