EasyX之鼠标消息函数

#include <graphics.h>  
#include <stdio.h>  
#include <easyx.h>  
  
// 声明button函数  
void button(int x, int y, int w, int h, const char* text);  
  
int main()  
{  
    initgraph(640, 832, EW_SHOWCONSOLE); // 初始化图形窗口  
  
    // 如果你想要加载和显示图像,可以在这里添加代码  
    // 但由于问题中没有具体要求,这部分我注释掉了  
     IMAGE img;  
     loadimage(&img, "./hello.jpg");  
     putimage(0, 0, &img);  
  
    // 调用button函数  
    button(50, 50, 150, 50, "按钮"); 
	ExMessage msg;
	while(true)
	{
		if(peekmessage(&msg,EM_MOUSE))
		{

			switch(msg.message)
			{
			case WM_LBUTTONDOWN:
				if(msg.x>=50 && msg.x<=50+150 && msg.y>=50&&msg.y<=50+50)
				{
				    printf("我是按钮,我被点击了\n");
				}
			    break;
			default:
				break;

			}
		
		}

	
	}
  
    // 等待用户输入后关闭图形窗口  
    getchar();  
    closegraph();  
  
    return 0;  
}  
  
// button函数的定义  
void button(int x, int y, int w, int h, const char* text)  
{  
    setbkmode(TRANSPARENT);  
    setfillcolor(BROWN);  
    fillroundrect(x, y, x + w, y + h, 10, 10);  
    settextstyle(30, 0, "黑体");  
    char text_[50] = "button"; // 这里其实不需要初始化,因为后面会覆盖  
    strcpy(text_, text);  
    int tx = x + (w - textwidth(text_)) / 2;  
    int ty = y + (h - textheight(text_)) / 2;  
    outtextxy(tx, ty, text_);  
}

 

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值