用easyx建立一个按钮

#include<stdio.h>
#include<easyx.h>

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 t[] = "button";
strcpy_s(t, text);
int tx = x + (w - textwidth(t)) / 2;
int ty = y + (h - textheight(t)) / 2;

outtextxy(tx, ty, t);
}


int main()
{

initgraph(640, 480,EW_SHOWCONSOLE);//初始化窗口

button(50, 50, 150, 50, "按钮");
ExMessage msg;
while (1) {
if (peekmessage(&msg, EM_MOUSE))
{
switch (msg.message)
{
case WM_LBUTTONDOWN:
if (msg.x >= 50 && msg.x <= 200 && msg.y >= 50 && msg.y <= 100) {
printf("click\n");
}
break;
deault:
break;
}
}
}
getchar();

return 0;
}

posted @ 2022-08-04 22:40  是你华哥  阅读(820)  评论(0)    收藏  举报