⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button.cpp

📁 金融pos机前台源码
💻 CPP
字号:
/*******************************************************************************
	模  块:	按钮模块.
	功  能:	能完成接受按键,并返回按钮事件.
	程序员:	雷中南.
	版  本:	v1.1
	时  间:	1999-05-05
*******************************************************************************/

#include <string.h>
#include <graphics.h>
#include <conio.h>
#include "button.h"
#include "han.h"

//构造函数.
Button::Button(struct RECT R, char *caption, int ID) : Object(R)
{
	Caption = new char[strlen(caption)+2];//按钮标题.
	strcpy(Caption, caption);
	HighLight = L_ERROR;
	ButtonID = ID;//按钮识别号.
	SetBkColor(7);//设置背景颜色.
}

//析构函数.
Button::~Button()
{
	delete []Caption;
}

//接受RUN函数的调用.
void
Button::DoIt()
{
	for(;;)
	{
		//将背景设为高亮,显示它.
		HighLight = L_OK;
		Object::Show();
		HighLight = L_ERROR;
		//读取一个键.
		switch ( GetKey() )
		{
			case KEY_RETURN:
			case KEY_SPACE:
				//选定按钮.
				PutEvent(ButtonID);
				Show();
				return;
			case KEY_ESC:
				//退出.
				PutEvent(EV_QUIT);
				Show();
				return;
			case KEY_LEFT:
			case KEY_UP:
				//上一个控件.
				PutEvent(EV_PREV);
				Show();
				return;
			case KEY_RIGHT:
			case KEY_DOWN:
				//下一个控件.
				PutEvent(EV_NEXT);
				Show();
				return;
			case KEY_TAB:
				//TAB键
				PutEvent(EV_NEXT);
				Show();
				return;
		}
	}
}

//重画函数.
void
Button::Draw()
{
	//先画对象.
	Object::Draw();
	//如果在被选中时画,应为高亮.
	if(HighLight == L_OK)
	{
		//高亮显示.
		setfillstyle(SOLID_FILL,1);
		bar(2,2,Rect.Width-2,Rect.Height-2);
		//写按钮标题.
		int temp=han.Color;
		han.Color = 15;
		han.Out((Rect.Width-8*strlen(Caption))/2,(Rect.Height-16)/2,Caption);
		han.Color = temp;
	}
	else
	{
		//正常背景显示.
		//...
		//写按钮标题.
		int temp=han.Color;
		han.Color = 0;
		han.Out((Rect.Width-8*strlen(Caption))/2,(Rect.Height-16)/2,Caption);
		han.Color = temp;
	}
	//画3D边框.
	setcolor(15);
	line(0, 0, Rect.Width, 0);
	line(0, 0, 0, Rect.Height);
	setcolor(8);
	line(0, Rect.Height, Rect.Width, Rect.Height);
	line(Rect.Width, 0, Rect.Width, Rect.Height);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -