一个自己写的头文件包装-button.h-1.0

本文详细介绍了一种使用C++和Windows API进行简易按钮创建的方法。通过定义Button结构体并实现SetButton和Preserve函数,可以创建并维护按钮状态,包括响应鼠标事件如点击、双击和滚动。此教程适合初学者理解和实践C++窗口编程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

依赖windowset.h 文章链接 https://blog.youkuaiyun.com/yuanwow/article/details/94206600
不想说什么,上代码

//c++简单按钮创建头文件
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<windows.h>
#include<algorithm>
#include"windowset.h"
using namespace std;
struct Button {
	int x,y,color;//位置x,y颜色color
	//----------------------other
	char *label;//label
	int llen;//label的长度
};
void SetButton(int x,int y,int color,Button &t,char* label) {//设置按钮,返回它
	t.x=x,t.y=y;
	t.color=color;
	t.label=label;
	t.llen=strlen(label);
}

int Preserve(Button A) {//维护一个按钮
	POINT pt;
	GetPos(pt);
	gto(A.x,A.y),color(A.color),printf("%s",A.label);
	if(pt.y==A.x&&(pt.x>=A.y&&pt.x<A.y+A.llen)) {
		color(A.color+16),gto(A.x,A.y),printf("%s",A.label);
		if(KEY_DOWN(MOUSE_MOVED)) return 1;//检测到左键
		if(KEY_DOWN(DOUBLE_CLICK)) return 2;//检测到右键
		if(KEY_DOWN(MOUSE_WHEELED))	return 3;//检测到滚轮
	}
	return 0;//没有检测到
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值