- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
LabWindows/CVI虚拟仪器设计技术场景与游戏设计之:时钟制作
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);
但是,这种设置方式重复工作量较大,代码大量冗余,容易出现错误,可以采用循环结构优化代码设计,即主函数中使用的代码:
for (i = 2; i < 14; i ++)
{
SetCtrlAttribute (panelHandle, i, ATTR_TEXT_BGCOLOR, VAL_TRANSPARENT);
}
采用此种代码方式,需要控制每个Text Message 控件的Tab Order 属性,使自动生成的"时钟制作.h"文件控件常量值遵从一定顺序,即:
#include <userint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define
PANEL
1
#define
PANEL_TEXTMSG_1
2
#define
PANEL_TEXTMSG_2
3
#define
PANEL_TEXTMSG_3
4
#define
PANEL_TEXTMSG_4
5
#define
PANEL_TEXTMSG_5
6
#define
PANEL_TEXTMSG_6
7
#define
PANEL_TEXTMSG_7
8
#define
PANEL_TEXTMSG_8
9
#define
PANEL_TEXTMSG_9
10
#define
PANEL_TEXTMSG_10
11
#define
PANEL_TEXTMSG_11
12
#define
PANEL_TEXTMSG_12
13
#define
PANEL_CANVAS
14
#define
PANEL_TIMER
15
#define
PANEL_DECORATION
16
int CVICALLBACK PanelCB(int panel, int event, void *callbackData, int eventData1, int eventData2);
int CVICALLBACK timer(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); #ifdef __cplusplus
}
#endif
上一篇:LabWindows/CVI虚拟仪器设计技术场景与游戏设计之:
下雪场景
下一篇:LabWindows/CVI虚拟仪器设计技术基本控件使用之:
Tab
控件