全局脚本编程(按钮连续增减)
说明:1、建立全局脚本函数
2、建立全局动作C脚本
3、在启动画面的打开画面中调用全局脚本函数
4、在计算机的启动选项中选中全局脚本
全局脚本函数InitAction ()
extern char tagname[30] = " ";
extern SHORT count = 0;
extern FLOA T low = 0;
extern FLOA T high = 0;
extern FLOA T step = 0;
void InitAction()
按钮左键按下连续增加
extern char tagname[30];
extern SHORT count;
extern FLOA T low;
extern FLOA T high;
extern FLOA T step;
strcpy(tagname,"S32i_varia_but_04");
count = 1;
low = 0;
high =1400;
step =0.5;
按钮左键按下连续减少
extern char tagname[30];
extern SHORT count;
extern FLOA T low;
extern FLOA T high;
extern FLOA T step;
strcpy(tagname,"S32i_varia_but_04");
count = 2;
low = 0;
high =1400;
step =0.5;
按钮左键松开停止增减
extern SHORT count;
count=0; 全局动作C脚本(counter.pas)
#include "apdefap.h"
int gscAction( void )
{
extern char tagname[30];
extern SHORT count;
extern FLOA T low;
extern FLOA T high;
extern FLOA T step;
FLOA T value;
if ((count==1)||(count==2)) {
//get current value
value = GetTagFloat (tagname);
if (count==1){ //inc
value = value+step;
if (value>high) (value=high); //high limit
}//if
if (count==2){ //dec value = value-step;
if (value }//if SetTagFloat (tagname,value); }//if return(0); } 全局脚本函数(InitAction)文件: C脚本(counter.pas)文件: 按钮左键连续增加文件: 按钮左键松开文件: C脚本编程(按钮按击增减) 1、直接调用C动作方式实现: #include "apdefap.h" void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y) { FLOA T value; value=GetTagFloat("S32i_varia_but_00"); //get tag value if (value>1300) (value=1400); //check limit else value=value+100; //inc value SetTagFloat("S32i_varia_but_00",value); //set new value 2、调用函数方式实现(incdecvalue): FLOA T value; value=GetTagFloat ("S32i_varia_but_04"); IncDecV alue(&value,0,1400,100,1); SetTagFloat ("S32i_varia_but_04",value); 项目函数(incdecvalue) void IncDecV alue(FLOA T *value,FLOA T low,FLOA T high,FLOA T step,DWORD a) { FLOA T v; v=*value; //get current value switch (a){ case 0: { if (v else v=v-step; //decrement } //case 0 break; case 1:{ if (v>(high-step)) (v=high); //high limit else v=v+step; //increment }//case 1 break; }//switch *value=v; //return } 项目函数(incdecvalue)文件: C脚本编程(按钮切换开关): #include "apdefap.h" void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y) { BOOL state; //flip tag state = !GetTagBit("BINi_varia_but_16"), SetTagBit("BINi_varia_but_16",(SHORT)state); } 按钮切换开关文件: