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


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

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

C++:按键控制头文件Button.h_第1张图片

。。。。。。

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

代码:

名字就叫Button.h

#ifndef BUTTON_H
#include     
#include           
#include        
#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()。

你可能感兴趣的:(C++打包头文件,c++,开发语言)