使用easyx制作一个绘画程序

#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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值