依赖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;//没有检测到
}