您现在的位置是:主页 > news > 模板网站跟仿站的区别/百度竞价关键词怎么优化
模板网站跟仿站的区别/百度竞价关键词怎么优化
admin2025/5/25 4:02:28【news】
简介模板网站跟仿站的区别,百度竞价关键词怎么优化,智能网站建设软件有哪些方面,可以做动态图表的网站熟悉EasyX的用户应该都知道EasyX虽然有丰富的画图函数,但是也有很多好用的组件是不具备的,比如按钮,这对于我们进行游戏开发来说是个非常重要的交互组件,这篇文章就用c语法写一个简易的按钮组件方便大家用C在开发游戏和学习中使用…
模板网站跟仿站的区别,百度竞价关键词怎么优化,智能网站建设软件有哪些方面,可以做动态图表的网站熟悉EasyX的用户应该都知道EasyX虽然有丰富的画图函数,但是也有很多好用的组件是不具备的,比如按钮,这对于我们进行游戏开发来说是个非常重要的交互组件,这篇文章就用c语法写一个简易的按钮组件方便大家用C在开发游戏和学习中使用…
熟悉EasyX的用户应该都知道EasyX虽然有丰富的画图函数,但是也有很多好用的组件是不具备的,比如按钮,这对于我们进行游戏开发来说是个非常重要的交互组件,这篇文章就用c++语法写一个简易的按钮组件方便大家用C++在开发游戏和学习中使用。
涉及C++知识点:函数、数组、结构体。
1、绘制按钮边框
#include<graphics.h>
#include<conio.h>struct Button
{int x1;int x2;int y1;int y2;
};void setVertexAndShowButton(Button btn,int x1,int x2,int y1,int y2)
{//设置顶点坐标btn.x1 = x1;btn.x2 = x2;btn.y1 = y1;btn.y2 = y2;//绘制按钮边框rectangle(btn.x1, btn.y1, btn.x2, btn.y2);}int main()
{Button btns[3]; //初始化按钮结构体数组initgraph(640, 480);//初始化界面setVertexAndShowButton(btns[0], 280, 360, 220, 260);setVertexAndShowButton(btns[1], 280, 360, 270, 310);setVertexAndShowButton(btns[2], 280, 360, 320, 360);_getch();//等待用户输入return 0;
}
输出:
2、设置按钮文字
#include<graphics.h>
#include<conio.h>
#include<string>
#include<Windows.h>
#include<iostream>
using namespace std;struct Button
{int x1;int x2;int y1;int y2;
};void setVertexAndShowButton(Button btn,int x1,int x2,int y1,int y2, TCHAR text[1000],int tlength,int twidth,int tsetoff,string color)
{//设置顶点坐标btn.x1 = x1;btn.x2 = x2;btn.y1 = y1;btn.y2 = y2;//绘制按钮边框rectangle(btn.x1, btn.y1, btn.x2, btn.y2);//设置按钮文字setbkmode(TRANSPARENT);//设置透明字体if(color=="red"|| color == "RED")settextcolor(RED);//设置字体颜色为红色else if(color == "green"|| color == "GREEN")settextcolor(GREEN);//设置字体颜色为红色else if(color == "blue"|| color == "BLUE")settextcolor(BLUE);//设置字体颜色为红色else if(color == "yellow"|| color == "YELLOW")settextcolor(YELLOW);//设置字体颜色为黄色else if (color == "black" || color == "BLACK")settextcolor(BLACK);//设置字体颜色为黑色else if (color == "white" || color == "WHITE")settextcolor(WHITE);//设置字体颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查字体颜色是否设置正确,目前字体颜色包含:red、green、blue、yellow、black、white。"), TEXT("字体颜色设置错误"), 1);cout << x;}//settextcolor(BLUE);//设置字体颜色settextstyle(tlength, twidth, _T("宋体"));//设置字体格式outtextxy(x1 + tsetoff, y1 + tsetoff,text);//设置显示位置}int main()
{Button btns[3]; //初始化按钮结构体数组initgraph(640, 480);//初始化界面TCHAR tex1[1000] = _T("按钮1");TCHAR tex2[1000] = _T("按钮2");TCHAR tex3[1000] = _T("按钮3");setVertexAndShowButton(btns[0], 280, 360, 220, 260, tex1,20,10,5,"red1");setVertexAndShowButton(btns[1], 280, 360, 270, 310, tex2, 20,10,5,"white");setVertexAndShowButton(btns[2], 280, 360, 320, 360, tex3, 20,10,5,"YELLOW");_getch();//等待用户输入return 0;
}
函数参数说明:
TCHAR text[1000]:按钮提示文字。
使用时需要在主函数手动设置变量再引入参数:
TCHAR tex1[1000] = _T("按钮1");TCHAR tex2[1000] = _T("按钮2");TCHAR tex3[1000] = _T("按钮3");
int tlength:字体的长度
int twidth:字体的宽度
int tsetoff:字体距离按钮边框左上角的偏移量
string color:字体颜色
输出:
3、设置按钮颜色
根据文字颜色的设置方法我们将按钮的边框和底色也自定义颜色:
void setVertexAndShowButton(Button btn,int x1,int x2,int y1,int y2, TCHAR text[1000],int tlength,int twidth,int tsetoff,string tcolor,string lcolor,string fcolor)
{//设置顶点坐标btn.x1 = x1;btn.x2 = x2;btn.y1 = y1;btn.y2 = y2;//设置边框颜色if (lcolor == "red" || lcolor == "RED")setlinecolor(RED);//设置边框颜色为红色else if (lcolor == "green" || lcolor == "GREEN")setlinecolor(GREEN);//设置边框颜色为红色else if (lcolor == "blue" || lcolor == "BLUE")setlinecolor(BLUE);//设置边框颜色为红色else if (lcolor == "yellow" || lcolor == "YELLOW")setlinecolor(YELLOW);//设置边框颜色为黄色else if (lcolor == "black" || lcolor == "BLACK")setlinecolor(BLACK);//设置边框颜色为黑色else if (lcolor == "white" || lcolor == "WHITE")setlinecolor(WHITE);//设置边框颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查按钮边框颜色是否设置正确,目前字体颜色包含:red、green、blue、yellow、black、white。"), TEXT("按钮边框颜色设置错误"), 1);cout << x;}//绘制按钮边框rectangle(btn.x1, btn.y1, btn.x2, btn.y2);//设置填充颜色if (fcolor == "red" || fcolor == "RED")setfillcolor(RED);//设置填充颜色为红色else if (fcolor == "green" || fcolor == "GREEN")setfillcolor(GREEN);//设置填充颜色为红色else if (fcolor == "blue" || fcolor == "BLUE")setfillcolor(BLUE);//设置填充颜色为红色else if (fcolor == "yellow" || fcolor == "YELLOW")setfillcolor(YELLOW);//设置填充颜色为黄色else if (fcolor == "black" || fcolor == "BLACK")setfillcolor(BLACK);//设置填充颜色为黑色else if (fcolor == "white" || fcolor == "WHITE")setfillcolor(WHITE);//设置填充颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查按钮填充颜色是否设置正确,目前填充颜色包含:red、green、blue、yellow、black、white。"), TEXT("按钮填充颜色设置错误"), 1);cout << x;}fillrectangle(btn.x1, btn.y1, btn.x2, btn.y2);//设置按钮文字setbkmode(TRANSPARENT);//设置透明字体if(tcolor=="red"|| tcolor == "RED")settextcolor(RED);//设置字体颜色为红色else if(tcolor == "green"|| tcolor == "GREEN")settextcolor(GREEN);//设置字体颜色为红色else if(tcolor == "blue"|| tcolor == "BLUE")settextcolor(BLUE);//设置字体颜色为红色else if(tcolor == "yellow"|| tcolor == "YELLOW")settextcolor(YELLOW);//设置字体颜色为黄色else if (tcolor == "black" || tcolor == "BLACK")settextcolor(BLACK);//设置字体颜色为黑色else if (tcolor == "white" || tcolor == "WHITE")settextcolor(WHITE);//设置字体颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查字体颜色是否设置正确,目前字体颜色包含:red、green、blue、yellow、black、white。"), TEXT("字体颜色设置错误"), 1);cout << x;}//settextcolor(BLUE);//设置字体颜色settextstyle(tlength, twidth, _T("宋体"));//设置字体格式outtextxy(x1 + tsetoff, y1 + tsetoff,text);//设置显示位置//恢复画线和填充颜色setlinecolor(WHITE);setfillcolor(WHITE);
}
输出:
4、设置按钮响应动画
按钮响应可以是颜色、大小、声音等多方面的变化,接下来我们将实现鼠标进入按钮会发生的变化。
#include<graphics.h>
#include<conio.h>
#include<string>
#include<Windows.h>
#include<iostream>
using namespace std;struct Button
{int x1;int x2;int y1;int y2;
};void setVertexAndShowButton(Button btn,int x1,int x2,int y1,int y2, TCHAR text[1000],int tlength,int twidth,int tsetoff,string tcolor,string lcolor,string fcolor)
{BeginBatchDraw();//暂停绘画//设置顶点坐标btn.x1 = x1;btn.x2 = x2;btn.y1 = y1;btn.y2 = y2;//设置边框颜色if (lcolor == "red" || lcolor == "RED")setlinecolor(RED);//设置边框颜色为红色else if (lcolor == "green" || lcolor == "GREEN")setlinecolor(GREEN);//设置边框颜色为红色else if (lcolor == "blue" || lcolor == "BLUE")setlinecolor(BLUE);//设置边框颜色为红色else if (lcolor == "yellow" || lcolor == "YELLOW")setlinecolor(YELLOW);//设置边框颜色为黄色else if (lcolor == "black" || lcolor == "BLACK")setlinecolor(BLACK);//设置边框颜色为黑色else if (lcolor == "white" || lcolor == "WHITE")setlinecolor(WHITE);//设置边框颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查按钮边框颜色是否设置正确,目前字体颜色包含:red、green、blue、yellow、black、white。"), TEXT("按钮边框颜色设置错误"), 1);cout << x;}//绘制按钮边框rectangle(btn.x1, btn.y1, btn.x2, btn.y2);//设置填充颜色if (fcolor == "red" || fcolor == "RED")setfillcolor(RED);//设置填充颜色为红色else if (fcolor == "green" || fcolor == "GREEN")setfillcolor(GREEN);//设置填充颜色为红色else if (fcolor == "blue" || fcolor == "BLUE")setfillcolor(BLUE);//设置填充颜色为红色else if (fcolor == "yellow" || fcolor == "YELLOW")setfillcolor(YELLOW);//设置填充颜色为黄色else if (fcolor == "black" || fcolor == "BLACK")setfillcolor(BLACK);//设置填充颜色为黑色else if (fcolor == "white" || fcolor == "WHITE")setfillcolor(WHITE);//设置填充颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查按钮填充颜色是否设置正确,目前填充颜色包含:red、green、blue、yellow、black、white。"), TEXT("按钮填充颜色设置错误"), 1);cout << x;}fillrectangle(btn.x1, btn.y1, btn.x2, btn.y2);//设置按钮文字setbkmode(TRANSPARENT);//设置透明字体if(tcolor=="red"|| tcolor == "RED")settextcolor(RED);//设置字体颜色为红色else if(tcolor == "green"|| tcolor == "GREEN")settextcolor(GREEN);//设置字体颜色为红色else if(tcolor == "blue"|| tcolor == "BLUE")settextcolor(BLUE);//设置字体颜色为红色else if(tcolor == "yellow"|| tcolor == "YELLOW")settextcolor(YELLOW);//设置字体颜色为黄色else if (tcolor == "black" || tcolor == "BLACK")settextcolor(BLACK);//设置字体颜色为黑色else if (tcolor == "white" || tcolor == "WHITE")settextcolor(WHITE);//设置字体颜色为白色else {int x;x = MessageBox(GetForegroundWindow(), TEXT("请检查字体颜色是否设置正确,目前字体颜色包含:red、green、blue、yellow、black、white。"), TEXT("字体颜色设置错误"), 1);cout << x;}//settextcolor(BLUE);//设置字体颜色settextstyle(tlength, twidth, _T("宋体"));//设置字体格式outtextxy(x1 + tsetoff, y1 + tsetoff,text);//设置显示位置//设置按钮交互响应//MOUSEMSG m;// 定义鼠标消息int change=10;ExMessage m;//定义一个消息变量m = getmessage(EM_MOUSE);//获取鼠标消息switch (m.message){case WM_MOUSEMOVE:// 鼠标移动按钮时按钮变大if (m.x >= btn.x1 && m.x <= btn.x2) {if (m.y >= btn.y1 && m.y <= btn.y2){rectangle(btn.x1- change, btn.y1- change, btn.x2+ change, btn.y2+ change);}else{FlushBatchDraw();//批量绘制//cleardevice();}}else{FlushBatchDraw();//批量绘制//cleardevice();}break;case WM_LBUTTONDOWN:// 鼠标点击按钮会变绿色if (m.x >= btn.x1 && m.x <= btn.x2){if (m.y >= btn.y1 && m.y <= btn.y2){setfillcolor(GREEN);fillrectangle(btn.x1, btn.y1, btn.x2, btn.y2);FlushBatchDraw();//批量绘制}else{FlushBatchDraw();//批量绘制//cleardevice();}}break;}//恢复画线和填充颜色setlinecolor(WHITE);setfillcolor(WHITE);
}int main()
{Button btns[3]; //初始化按钮结构体数组initgraph(640, 480);//初始化界面TCHAR tex1[1000] = _T("按钮1");TCHAR tex2[1000] = _T("按钮2");TCHAR tex3[1000] = _T("按钮3");while (1){setVertexAndShowButton(btns[0], 280, 360, 220, 260, tex1, 20, 10, 5, "green", "green", "red");setVertexAndShowButton(btns[1], 280, 360, 270, 310, tex2, 20, 10, 5, "white", "green", "red");setVertexAndShowButton(btns[2], 280, 360, 320, 360, tex3, 20, 10, 5, "YELLOW", "green", "red");}_getch();//等待用户输入return 0;
}