C++:按键控制头文件Button.h

这篇博客主要介绍了C++中用于按键控制的头文件Button.h,包括相关代码和函数SHOW()的使用。
摘要由CSDN通过智能技术生成


°★.☆° .★·°∴°★.°·∴°☆ ·°∴° ☆..·
☆°★°∴°°∴ ☆°.·★°∴°.
   ◢◣。        ◢◣。     ☆圣★
  ◢★◣。     ◢★◣。     ★诞☆
 ◢■■◣。   ◢■■◣。     ☆节★
◢■■■◣。 ◢■■■◣。      ★快☆
︸︸||︸︸ !!︸︸||︸︸         ☆乐★
祝你圣诞节快乐 ^_^!!☆°★°∴°°∴ ☆°.·★°∴°.
°★.☆° .★·°∴°★.°·∴°☆ ·°∴° ☆..·.

还记得C++鼠标点击吗?

。。。。。。

我费尽心思,整理了一份按键控制头文件,代码如下:

代码</>:

名字就叫Button.h

#ifndef BUTTON_H
#include <bits/stdc++.h>    
#include <conio.h>          
#include <windows.h>       
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1 : 0)
using namespace std;
void SHOW()
{
	printf("Hello!欢迎使用Button使用向导!");
	Sleep(700);
	printf("\n下面我就简单介绍一下Button头文件。");
	Sleep(700);
	printf("\n1、GetPos没有实际作用。");
	Sleep(700);
	printf("\n2、GOTOXY可以移动光标至(x, y)。");
	Sleep(700);
	printf("\n3、__color可以更改颜色。");
	Sleep(700);
	printf("\n4、Button结构体用来创建按钮,");
	Sleep(700);
	printf("\n结构是:Button 按钮名称 = NewButton(按钮x坐标, 按钮y坐标, 按钮颜色, 按钮内容)。");
	Sleep(700);
	printf("\n5、Preserve用来判断,");
	Sleep(700);
	printf("\n结构是:if (Preserve(按钮名称) == ture) { 执行语句 }。");
	_getch();
}
void GetPos(POINT &pt)
{
	HWND hwnd = GetForegroundWindow();
	GetCursorPos(&pt);
	ScreenToClient(hwnd, &pt);
	pt.y = pt.y / 16, pt.x = pt.x / 8;
	swap(pt.x, pt.y);
}
void GOTOXY(int x, int y)
{
	COORD pos; pos.X = y; pos.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void __color(int a)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}
struct Button
{
	int x, y, color;
	const char *name;
	int len;
};
Button NewButton(int x, int y, int color, const char *name)
{
	Button t;
	t.x = x, t.y = y, t.name = name;
	t.color = color;
	t.len = strlen(name);
	return t;
}
bool Preserve(Button A)
{
	GOTOXY(A.x, A.y), __color(A.color), printf("%s", A.name);
	POINT pt;
	GetPos(pt);
	if (pt.x == A.x && (pt.y >= A.y&&pt.y <= A.y + A.len))
	{
		__color(112), GOTOXY(A.x, A.y), printf("%s", A.name);
		if (KEY_DOWN(MOUSE_MOVED)) return 1;
	}
	return 0;
}
#endif

函数㏒㏑ :

详见函数SHOW()。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

快乐星空Maker

你的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值