📄 vc0905.cpp
字号:
// Example 9-5: 按钮类
#include <iostream.h>
#include <string.h>
class Button
{
protected:
int m_nX; //横坐标位置
int m_nY; //纵坐标位置
int m_nWidth; //按钮宽度
int m_nHeight; //按钮高度
char m_strType[10]; //按钮类型
char m_strColor[10]; //按钮颜色
char m_strText[20]; //按钮文字
public:
void Draw() { /* 绘制按钮 */ }
int GetX() { return m_nX; }
int GetY() { return m_nY; }
int GetWidth() { return m_nWidth; }
int GetHeight() { return m_nHeight;}
char* GetColor() { return m_strColor; }
char* GetType() { return m_strType; }
char* GetText() { return m_strText; }
void SetX(int x0) { m_nX=x0; }
void SetY(int y0) { m_nY=y0; }
void SetWidth(int w) { m_nWidth=w; }
void SetHeight(int h) { m_nHeight=h; }
void SetColor(char *color) { strcpy(m_strColor,color); }
void SetText(char *text) { strcpy(m_strText,text); }
void SetType(char *type) { strcpy(m_strType,type);}
virtual void BePressed()=0; //下压操作响应函数
};
class OK_Button : public Button
{
public:
OK_Button();
OK_Button(int,int,int,int,char*,char*,char*);
void BePressed();
};
OK_Button::OK_Button(int x0,int y0,int w,int h,char* type,char* color,char* text)
{
SetX(x0);
SetY(y0);
SetWidth(w);
SetHeight(h);
SetType(type);
SetColor(color);
SetText(text);
}
OK_Button::OK_Button()
{
SetX(10);
SetY(10);
SetWidth(20);
SetHeight(10);
SetType("立体");
SetColor("灰色");
SetText("按钮");
}
void OK_Button::BePressed()
{
cout<<endl<<" 执行相关操作"<<endl<<endl;
}
void main()
{
char ifg;
OK_Button b1;
cout<<" 横坐标: "<<b1.GetX()<<endl;
cout<<" 纵坐标: "<<b1.GetY()<<endl;
cout<<" 宽度 : "<<b1.GetWidth()<<endl;
cout<<" 高度 : "<<b1.GetHeight()<<endl;
cout<<" 颜色 : "<<b1.GetColor()<<endl;
cout<<" 类型 : "<<b1.GetType()<<endl;
cout<<" 文字 : "<<b1.GetText()<<endl<<endl;
cout<<" 按钮是否被触发(Y or N) ? : ";
cin>>ifg;
if(ifg=='Y'||ifg=='y') b1.BePressed();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -