微波EDA网,见证研发工程师的成长!
首页 > 测试测量 > 测试测量技术文库 > LabWindows/CVI虚拟仪器设计技术场景与游戏设计之:时钟制作

LabWindows/CVI虚拟仪器设计技术场景与游戏设计之:时钟制作

时间:11-13 来源:3721RD 点击:

{
case EVENT_CLOSE:
QuitUserInterface (0);
break;
}
return 0;
}
//定时器
int CVICALLBACK timer (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char *timestr;
char CurTime[50];
int Seconds;
int Minutes;
int Hours;
int sdeg;
int mdeg;
int hdeg;
double srad;
double mrad;
double hrad;
//记录表盘指针状态
static int sx2,sy2,soldx2,soldy2;
static int mx2,my2,moldx2,moldy2;
static int hx2,hy2,holdx2,holdy2;
switch (event)
{
case EVENT_TIMER_TICK:
// 获得系统时间
GetSystemTime (&Hours, &Minutes, &Seconds);
// 转换为角度
sdeg = Seconds * 6;
mdeg = Minutes * 6;
hdeg = Hours * 30 + (0.5 * Minutes);
// 设置秒针参数
// 设置Canvas 控件绘图笔宽度
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_WIDTH, 2);
soldx2 = sx2;
soldy2 = sy2;
// 转换为弧度
srad = (3.14 / 180) * sdeg;
// 擦除上一次绘制图形
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_BLACK);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (soldx2,
soldy2));

// 计算指针末端位置
sx2 = 150 + 100 * sin(srad);
sy2 = 150 – 100 * cos(srad);
// 绘制新图形
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_RED);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (sx2,sy2));
// 设置分针参数
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_WIDTH, 4);
moldx2 = mx2;
moldy2 = my2;
mrad = (3.14 / 180) * mdeg;
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_BLACK);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (moldx2,
moldy2));
mx2 = 150 + 80 * sin(mrad);
my2 = 150 – 80 * cos(mrad);
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_BLUE);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (mx2,my2));
// 设置时针参数
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_WIDTH, 6);
holdx2 = hx2;
holdy2 = hy2;
hrad = (3.14 / 180) * hdeg;
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_BLACK);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (holdx2,
holdy2));
hx2 = 150 + 65 * sin(hrad);
hy2 = 150 – 65 * cos(hrad);
SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_WHITE);
CanvasDrawLine (panelHandle, PANEL_CANVAS, MakePoint (150,150), MakePoint (hx2,hy2));
// 获得当前时间字符串
timestr = TimeStr ();
CurTime[0] = '\0';
strcat (CurTime, " 当前时间:");
strcat (CurTime, timestr);
// 标题栏显示当前时间
SetPanelAttribute (panelHandle, ATTR_TITLE, CurTime);
break;
}
return 0;
}

3:程序注释

①设置透明背景在程序中,采用了SetCtrlAttribute 函数的VAL_TRANSPARENT 属性将Text Message 控件的背景设置为透明。对于12 个数字标签,需要重复设置VAL_TRANSPARENT ,其代码为:

SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_1, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_2, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_3, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_4, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_5, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_6, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_7, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_8, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_9, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_10, ATTR_TEXT_BGCOLOR,VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_11, ATTR_TEXT_BGCOLOR,VAL_TRANSPARENT);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_12, ATTR_TEXT_BGCOLOR,VAL_TRANSPARENT);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top