最新WINCC脚本整理
wincc-全套脚本总结
)
}
-------------------------------------
——————7、对话框调用——————
BOOL A;
BOOL B;
}
// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END
return 0;
}
=====================================================
int value;
value=GetTagBit("IM_in");//"IM_in"为触发的变量。
if(value==1)
{
SetVisible("lianxi.pdl","按钮8",TRUE);//lianxi.pdl为控制对象所在画etVisible("lianxi.pdl","按钮8",FALSE);//lianxi.pdl
SetPropWord(lpszPictureName,"qushi","ValueAxisEndValue",Hi);
————————————————————————
——————4、获取位号————————
SetTagChar("TrendTagName1","ProcessValueArchive\\PT111");//Return-Type: BOOL
VB操作wincc脚本心得
V B操作w i n c c脚本心得集团标准化工作小组 #Q8QGGQT-GX8G08Q8-GNQGJ8-MHHGN#Vbs 操作wincc画面脚本总结一:不使用变量单纯的操作界面1.操作某个画面中控件的属性如(总窗体)下的画面窗口2(画面窗口)Sub OnClick(ByVal Item) Dim objCircleDim screennameDim pwnameSet objCircle= ScreenItems("圆1" )= 60Set screenname=("Home1") creenItems("画面窗口2")Set value=2.更改画面窗口的对象Sub OnClick(Byval Item)Dim opObjectSet opObject= ("Home1").ScreenItems("画面窗口2")=""End Sub3.设置文本Set titleTxt= ("Home1").ScreenItems("静态文本2")=+"EF" Dim objTagDim ATextSet objTag = ("a") vb 中Switch语句的变体Dim objTagDim ATextSet objTag = ("a") 你要求是有是和否两个按钮那么MyVar = MsgBox ("HelloWorld!", 65, "MsgBox Example")中的65改成4就可以了!vbs脚本中:if msgbox("确实要启动设备吗",4,"警告")=6 then("tag1").write 1end if。
wincc-全套脚本总结
—————-1、wincc全局脚本动作-——-—-—隐藏控件——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit(”IM_in”);//"IM_in”为触发的变量.if(value==1){SetVisible("lianxi.pdl”,”按钮8",TRUE);//lianxi。
pdl为控制对象所在画面名,“按钮8”为对象名称}else{SetVisible(”lianxi.pdl","按钮8",FALSE);//lianxi.pdl}// WINCC:PICNAME_SECTION_START// syntax:#define PicNameInAction "PictureName”// next PicID : 1// WINCC:PICNAME_SECTION_ENDreturn 0;}=====================================================说明:在触发器里选择变量IM_in-—————2、wincc全局脚本动作-——-提示框————--#include "apdefap.h”int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName”// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit(”IM_in”);if(value==1){MessageBox(NULL,”请确认三厅相关门是否关好,或者请解锁。
WinCC_V6全局脚本
04.04 目目目目1函数和动作的创建 (1)1.1项目函数 - 特征 (3)1.2标准函数 - 特征 (4)1.3内部函数 - 特征 (5)1.4局部动作 - 特征 (6)1.5全局动作 - 特征 (7)1.6如何将全局脚本运行系统添加到项目的启动列表中 (8)1.7全局C变量 - 应用 (9)1.8在函数和动作中使用DLL (10)2全局脚本编辑器 (11)2.1在编辑窗口中使用 (13)2.1.1编辑器功能 - 键盘 (14)2.1.2使用鼠标完成编辑功能 (15)2.2使用工具栏 (16)2.3如何设置不同的视图 (18)2.4如何设置字体样式 (19)2.5如何使用“另存为...”.. (20)2.6如何删除动作或项目与标准函数 (21)2.7如何再次生成头文件 (22)2.8如何编译所有函数 (23)2.9如何在文件中搜索 (24)2.10打印函数和动作 (25)2.10.1如何设置打印参数 (26)2.10.2如何打开页面视图 (27)2.10.3如何打印项目文档 (27)3创建和编辑函数 (29)3.1如何创建新的函数 (31)3.2如何编写函数代码 (32)3.3如何使用内部函数 (33)3.4如何使用标准函数和项目函数 (34)3.5插入附加的与函数有关的信息 (35)3.6如何保护函数,避免未经授权的人员对其进行修改或查看 (36)3.7如何编译和保存函数 (38)3.8如何重新命名函数 (39)3.9如何使用其它来源的函数 (40)目目04.04 4创建和编辑动作 (41)4.1WinCC - 编码规则 (43)4.2如何创建新的动作 (44)4.3如何编辑动作 (45)4.4添加与动作相关的信息 (46)4.5如何防止动作被未经授权的人员修改或查看 (47)4.6编译和保存动作 (49)4.7触发器 (50)4.7.1如何添加新的“定时器”(类型)触发器 (52)4.7.2如何添加新的“变量”(类型)触发器 (54)4.7.3如何改变触发器 (56)4.7.4如何删除触发器 (58)4.8如何分配授权 (59)4.9如何导出动作 (60)4.10如何导入动作 (61)4.11如何重新命名动作 (62)4.12如何使用其它来源的动作 (63)5动作的运行行为 (65)5.1GSC运行系统 (65)5.1.1如何将GSC运行系统放置到过程画面中 (68)5.1.2GSC运行系统的属性 (69)5.1.3如何编辑动作 (70)5.2GSC诊断 (70)5.2.1如何将GSC诊断放置到过程画面中 (71)5.2.2GSC诊断 - 属性 (72)5.2.3GSC诊断 - 工具栏 (72)04.04 函数和动作的创建1 函数和动作的创建引言WinCC可以通过使用函数和动作动态化WinCC项目中的过程。
WINCC动画脚本
WINCC动画脚本电机风扇旋转(几何---起始角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static DWORD f=20;if (GetTagBit("DI电机运行信号")) {f= f+30;if (f==360) (f=0);}return f;}电机风扇旋转(几何---结束角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static DWORD i=80;if (GetTagBit("DI电机运行信号")) {i = i+30;if (i==360) (i=0);}return i;**物料水平右移动(几何---位置X)(停车后,物料回到原点)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}if (!GetTagBit("DI电机运行信号")) (a=350);return a;}物料水平右移动(几何---位置X)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}return a;物料向上移动(几何---位置Y)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int b=450;if (GetTagBit("DI电机运行信号") && (b>=290)) {b-=10;if (b<=280) (b=450);}return b;}年月日(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%04d/%02d/%02d",ptm->tm_year-100+2000,ptm->tm_mon+1,ptm->tm_mda y);return(p);}时分秒(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%02d:%02d:%02d",ptm->tm_hour,ptm->tm_min,ptm->tm_sec);return(p);}登陆到指定的用户名无须手动输入(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");}**显示登陆对话框无须热键(按钮操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code( )PWRTLogin('c');}退出WINCC运行(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){{DeactivateRTProject ();}}单位递增按钮(到上限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value>90) (value=上限);else value=value+10;SetTagDWord("AI标签",value);}单位递减按钮(到下限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value<10) (value=下限);else value=value-10;SetTagDWord("AI标签",value);}**单位递增按钮(到上限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value<=90) (value=value+10);else MessageBox(hWnd,"已到达上限值!","错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**单位递减按钮(到下限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value>0) (value=value-10);else MessageBox(hWnd," 已到达下限值!"," 错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**自动登陆到指定的用户(画面属性--其它—授权)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");return(0X0);}**询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int 上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗?","启动!",MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);printf("\r\nExample 3\r\n");if (上位启动信号==IDNO) (printf("User selected NO button \r\n"));else (SetTagByte("上位启动信号",1));}MessageBox(hWnd,"电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);}**询问框(最好用于单机启动,组启也可,3个按钮,NO复位)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd," 电源已备妥,您现在确定要启动吗?","启动!",MB_YESNOCANCEL|MB_ICONQUEST ION|MB_APPLMODAL);if (上位启动信号==IDCANCEL) (printf("User selected NO button\r\n"));else{if (上位启动信号==IDYES) (SetTagByte("上位启动信号",1));else (SetTagByte("上位启动信号",0));}}MessageBox(hWnd," 电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);}**搅拌器左侧扇页(几何—宽度)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int h=50;static int u=0;if (GetTagBit("DI电机运行信号")){if ((h>0)&&(h<=50)){(h-=2);return h;}if ((u>=0)&&(u<50)){(u+=2);return u;}u=0;h=50;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=50;u=0;return h;return u;}}**搅拌器左侧扇页(几何—位置X,右侧扇页没有位置变化)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int h=75;static int u=125;if (GetTagBit("DI电机运行信号")){if ((h>=75)&&(h<125)){(h+=2);return h;}if ((u<=125)&&(u>75)){(u-=2);return u;}u=125;h=75;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=75;u=125;return h;return u;}}**显示层按钮**SubX6309X94AE2X0000X0000_X6309X94AE2X0000X60C5_X6309X94AE2X0000X653E_OnLButtonDown (ByVal Item, ByVal Flags, ByVal x, ByVal y)Dim objScreenDim CountLayerSet objScreen = HMIRuntime.Screens("layer")For CountLayer=1 To 32 Step 1yers(CountLayer).Visible = vbFalseNextyers(n).Visible = vbTrueEnd Subn=层数+1初始画面程序(画面空地--属性--事件--其它--打开画面--动作)**打印按钮**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){WinExec("PRTSCR.EXE -hardcopy",SW_SHOWNORMAL);}**一个圈代表电机两种状态**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){char* opentag="DI1电机运行信号";char* closetag="DI2电机运行信号";BOOL open,close;open = GetTagBit(opentag);close = GetTagBit(closetag);if (open)return CO_GREEN;if (close)return CO_BLUE;}。
wincc 全套脚本总结
} -------------------------------------
——————6、时间同步——————
void SetCpuTime() { #pragma code("kernel32.dll"); void GetLocalTime(SYSTEMTIME *lpst); #pragma code(); SYSTEMTIME time BOOL ret; //printf("Start function SetCpuTime\r\n"); GetLocalTime(&time); ret= SetTagMultiWait("%d%d%d%d%d%d%d",
"data_FLAG",1
) }
-------------------------------------
——————7、对话框调用——————
BOOL A; BOOL B; HWND hwnd=NULL; int RetMsg; A=GetTagBit("TJ_ANNIU"); //Return-Type: BOOL hwnd=FindWindow(NULL,"WinCC-运行系统 - "); if (A==0)
MB_OK|MB_SYSTEMMODAL|MB_SETFOREGROUND); SetTagBit("TJ_ANNIU",0);
} else B=0; } else { } ------------------------------------------
——————8、声音报警——————
#pragma code("Winmm.dll") VOID WINAPI PlaySoundA(char* pszSound,char* hmode,DWORD dwflag); #pragma code()
Wincc常用C脚本及常用功能
打开用户管理器ProgramExecute("Passcs.exe");取消激活#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统- "); //获得句柄iRet=MessageBox(hwnd,"是否取消激活?","Deactivate",MB_OKCANCEL|MB_ICONW ARNING|MB_APPLMODAL);if(iRet==1)DeactivateRTProject (); //Return-Type: BOOL}关闭计算机#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)HWND hwnd=NULL;int iRet;hwnd=FindWindow(NULL,"WinCC-运行系统- ");iRet=MessageBox(hwnd,"是否关闭计算机?","ShutDown",MB_OKCANCEL|MB_ICONW ARNING|MB_APPLMODAL);if(iRet==1)DMExitWinCCEx(DM_SDMODE_SYSTEM);}====================================================================== 登陆代码:#pragma code(“useadmin.dll”)#include <pwrt_api.h>#pragma code()PWRTLogin (‘e’);====================================取消激活(Deactivate)DeactivateRTProject();======================================Wincc变量操作GetTagDWord(“变量名称”); 获取Wincc变量值SetTagDWord(“变量“,设定值);设置Wincc变量对文本读写操作写操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)FILE* lpFile;char *shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"};char* lpszStr;int i,j;lpszStr=SysMalloc(60); //Return-Type: void*lpFile = fopen("D:\\test.txt", "w+");for(i=0;i<6;i++){lpszStr=GetTagChar(shuzhu[i]);strcat(lpszStr,"\r\n");if(lpFile == NULL){ printf("can not open file\r\n"); return;}fprintf(lpFile, lpszStr);}SysFree(lpszStr);fclose(lpFile);}读操作#include "apdefap.h"void OnLButtonUp(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma option(mbcs)char* shuzhu[6]={"tag_1","tag_2","tag_3","tag_4","tag_5","tag_6"};char tmp[255];int i=0;int ChrNumLine=38;FILE *fp;fp=fopen("D:\\test.txt","r");if (fp==NULL){return;}else{rewind(fp);while(!feof(fp)){fgets(tmp,ChrNumLine,fp);SetTagChar(shuzhu[i],tmp);i++;}}fclose(fp);}画面窗口显示界面切换SetPictureName(lpszPictureName,"PicWindow_button","produce_manage_button.pdl"); SetVisible(lpszPictureName,"PicWindow_button",1);注:PicWindow_button是画面窗口名称;produce_manage_button.pdl是要显示的子画面。
西门子 HMI WinCC V7.2 WinCC:脚本编辑(VBS、ANSI-C、VBA)系统手册说
2
VBA for Automated Configuration
3
Print of the Online Help
02/2013
A5E32315920-AA
Legal information
Warning notice system This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are graded according to the degree of danger.
Table of contents
1 VBS for Creating Procedures and Actions..................................................................................................11
Proper use of Siemens products Note the following:
WARNING Siemens products may only be used for the applications described in the catalog and in the relevant technical documentation. If products and components from other manufacturers are used, these must be recommended or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and maintenance are required to ensure that the products operate safely and without any problems. The permissible ambient conditions must be complied with. The information in the relevant documentation must be observed.
wincc脚本全集
——————1、wincc全局脚本动作-------隐藏控件——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");//"IM_in"为触发的变量。
if(value==1){SetVisible("lianxi.pdl","按钮8",TRUE);//lianxi.pdl为控制对象所在画面名,“按钮8”为对象名称}else{SetVisible("lianxi.pdl","按钮8",FALSE);//lianxi.pdl}// WINCC:PICNAME_SECTION_START// syntax: #define PicNameInAction "PictureName"// next PicID : 1// WINCC:PICNAME_SECTION_ENDreturn 0;}=====================================================说明:在触发器里选择变量IM_in——————2、wincc全局脚本动作----提示框——————#include "apdefap.h"int gscAction( void ){// WINCC:TAGNAME_SECTION_START// syntax: #define TagNameInAction "DMTagName"// next TagID : 1// WINCC:TAGNAME_SECTION_ENDint value;value=GetTagBit("IM_in");if(value==1){MessageBox(NULL,"请确认三厅相关门是否关好,或者请解锁。
WINCC动画脚本集萃
WINCC动画脚本集萃WINCC电机风扇旋转(几何---起始角度):#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static DWORD f=20;if (GetTagBit("DI电机运行信号")) {f= f+30;if (f==360) (f=0);}return f;}电机风扇旋转(几何---结束角度):#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static DWORD i=80;if (GetTagBit("DI电机运行信号")) {i = i+30;if (i==360) (i=0);}return i;}**物料水平右移动(几何---位置X)(停车后,物料回到原点)** #include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}if (!GetTagBit("DI电机运行信号")) (a=350);return a;}物料水平右移动(几何---位置X)(停车后,物料停在该点)#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}return a;}物料向上移动(几何---位置Y)(停车后,物料停在该点)#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int b=450;if (GetTagBit("DI电机运行信号") && (b>=290)) {b-=10;if (b<=280) (b=450);}return b;}年月日(静态文本)#include ""char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%04d/%02d/%02d",ptm->tm_year-100+2000,ptm->tm_mon+1,p tm->tm_mday);return(p);}时分秒(静态文本)#include ""char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%02d:%02d:%02d",ptm->tm_hour,ptm->tm_min, ptm->tm_sec) ;return(p);}登陆到指定的用户名无须手动输入(按钮操作)#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code("")#include ""#pragma code()PWRTSilentLogin("用户名", "口令");}**显示登陆对话框无须热键(按钮操作)**#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code ("")#include ""#pragma code( )PWRTLogin('c');}退出WINCC运行(按钮操作)#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){{DeactivateRTProject ();}}单位递增按钮(到上限不提示出错)#include ""void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value>90) (value=上限);else value=value+10;SetTagDWord("AI标签",value);}单位递减按钮(到下限不提示出错)#include ""void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value<10) (value=下限);else value=value-10;SetTagDWord("AI标签",value);}**单位递增按钮(到上限提示出错)**#include ""void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value<=90) (value=value+10);else MessageBox(hWnd,"已到达上限值!","错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**单位递减按钮(到下限提示出错)**#include ""void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value>0) (value=value-10);else MessageBox(hWnd," 已到达下限值!"," 错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**自动登陆到指定的用户(画面属性--其它—授权)**#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){#pragma code("")#include ""#pragma code()PWRTSilentLogin("用户名", "口令");return(0X0);}**询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)** #include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int 上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗","启动!",MB_YESNO|MB_ICONQUESTION|MB_APPLM ODAL);printf("\\Example 3\\");if (上位启动信号==IDNO) (printf("User selected NO button \\"));else (SetTagByte("上位启动信号",1));}elseMessageBox(hWnd,"电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);}**询问框(最好用于单机启动,组启也可,3个按钮,NO复位)**#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd," 电源已备妥,您现在确定要启动吗","启动!",MB_YESNOCANCEL|MB _ICONQUESTION|MB_APPLMODAL);if (上位启动信号==IDCANCEL) (printf("User selected NO button \\"));else{if (上位启动信号==IDYES) (SetTagByte("上位启动信号",1));else (SetTagByte("上位启动信号",0));}}elseMessageBox(hWnd," 电源未备妥,请查证后重试!","启动!", MB_OK|MB_ICONHAND|MB_APPLMODAL);}**搅拌器左侧扇页(几何—宽度)**#include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int h=50;static int u=0;if (GetTagBit("DI电机运行信号")){if ((h>0)&&(h<=50)){(h-=2);return h;}if ((u>=0)&&(u<50)){(u+=2);return u;}u=0;h=50;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=50;u=0;return h;return u;}}**搅拌器左侧扇页(几何—位置X,右侧扇页没有位置变化)** #include ""long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){static int h=75;static int u=125;if (GetTagBit("DI电机运行信号")) {if ((h>=75)&&(h<125)){(h+=2);return h;}if ((u<=125)&&(u>75)){(u-=2);return u;}u=125;h=75;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=75;u=125;return h;return u;}}**显示层按钮**SubX6309X94AE2X0000X0000_X6309X94AE2X0000X60C5_X630 9X94AE2X0000X653E_On LButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)Dim objScreenDim CountLayerSet objScreen = ("layer")For CountLayer=1 To 32 Step 1(CountLayer).Visible = vbFalseNext(n).Visible = vbTrueEnd Subn=层数+1初始画面程序(画面空地--属性--事件--其它--打开画面--动作)**打印按钮**#include ""void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){WinExec(" -hardcopy",SW_SHOWNORMAL);}**一个圈代表电机两种状态**#include ""void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){char* opentag="DI1电机运行信号";char* closetag="DI2电机运行信号";BOOL open,close;open = GetTagBit(opentag); close = GetTagBit(closetag); if (open)return CO_GREEN;if (close)return CO_BLUE;。
WINCC动画脚本集锦
WINCC动画脚本电机风扇旋转(几何---起始角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static DWORD f=20;if (GetTagBit("DI电机运行信号")) {f= f+30;if (f==360) (f=0);}return f;}电机风扇旋转(几何---结束角度):#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static DWORD i=80;if (GetTagBit("DI电机运行信号")) {i = i+30;if (i==360) (i=0);}return i;}**物料水平右移动(几何---位置X)(停车后,物料回到原点)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}if (!GetTagBit("DI电机运行信号")) (a=350);return a;}物料水平右移动(几何---位置X)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static int a=350;if (GetTagBit("DI电机运行信号") && (a<=730)) {a+=20;if (a>=720) (a=350);}return a;}物料向上移动(几何---位置Y)(停车后,物料停在该点)#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static int b=450;if (GetTagBit("DI电机运行信号") && (b>=290)) {b-=10;if (b<=280) (b=450);}return b;}年月日(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%04d/%02d/%02d",ptm->tm_year-100+2000,ptm->tm_mon+1,ptm->tm_mday);return(p);}时分秒(静态文本)#include "apdefap.h"char* _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){time_t timer ;struct tm *ptm;char *p;time(&timer);ptm =localtime(&timer);p =SysMalloc(9);sprintf(p,"%02d:%02d:%02d",ptm->tm_hour,ptm->tm_min,ptm->tm_sec);return(p);}登陆到指定的用户名无须手动输入(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");}**显示登陆对话框无须热键(按钮操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code( )PWRTLogin('c');}退出WINCC运行(按钮操作)#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){DeactivateRTProject ();}}单位递增按钮(到上限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value>90) (value=上限);else value=value+10;SetTagDWord("AI标签",value);}单位递减按钮(到下限不提示出错)#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){DWORD value;value=GetTagDWord("AI标签");if (value<10) (value=下限);else value=value-10;SetTagDWord("AI标签",value);}**单位递增按钮(到上限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName)DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value<=90) (value=value+10);else MessageBox(hWnd,"已到达上限值!","错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**单位递减按钮(到下限提示出错)**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){DWORD value;HWND hWnd=NULL ;hWnd=FindWindow(NULL,"Wincc-运行系统- ");value=GetTagDWord("AI标签");if (value>0) (value=value-10);else MessageBox(hWnd," 已到达下限值!"," 错误",MB_OK|MB_ICONWARNING|MB_APPLMODAL);SetTagDWord("AI标签",value);}**自动登陆到指定的用户(画面属性--其它—授权)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){#pragma code("useadmin.dll")#include "PWRT_API.H"#pragma code()PWRTSilentLogin("用户名", "口令");return(0X0);}**询问框(最好用于单机启动,组启也可,2个按钮,NO不操作)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){HWND hWnd=NULL;int 上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd,"电源已备妥,您现在确定要启动吗?","启动!",MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);printf("\r\nExample 3\r\n");if (上位启动信号==IDNO) (printf("User selected NO button \r\n"));else (SetTagByte("上位启动信号",1));}elseMessageBox(hWnd,"电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);}**询问框(最好用于单机启动,组启也可,3个按钮,NO复位)**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)HWND hWnd=NULL;int上位启动信号;hWnd=FindWindow(NULL,"WinCC C-Course");if (GetTagBit("DI备妥")){上位启动信号=MessageBox(hWnd," 电源已备妥,您现在确定要启动吗?","启动!",MB_YESNOCANCEL|MB_ICONQUESTION|MB_APPLMODAL);if (上位启动信号==IDCANCEL) (printf("User selected NO button\r\n"));else{if (上位启动信号==IDYES) (SetTagByte("上位启动信号",1));else (SetTagByte("上位启动信号",0));}}elseMessageBox(hWnd," 电源未备妥,请查证后重试!","启动!",MB_OK|MB_ICONHAND|MB_APPLMODAL);}**搅拌器左侧扇页(几何—宽度)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){static int h=50;static int u=0;if (GetTagBit("DI电机运行信号"))if ((h>0)&&(h<=50)){(h-=2);return h;}if ((u>=0)&&(u<50)){(u+=2);return u;}u=0;h=50;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=50;u=0;return h;return u;}}**搅拌器左侧扇页(几何—位置X,右侧扇页没有位置变化)**#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName)static int h=75;static int u=125;if (GetTagBit("DI电机运行信号")){if ((h>=75)&&(h<125)){(h+=2);return h;}if ((u<=125)&&(u>75)){(u-=2);return u;}u=125;h=75;return h;return u;}if (!GetTagBit("DI电机运行信号")){h=75;u=125;return h;return u;}}**显示层按钮**SubX6309X94AE2X0000X0000_X6309X94AE2X0000X60C5_X6309X94AE2X00 00X653E_OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByValy)Dim objScreenDim CountLayerSet objScreen = HMIRuntime.Screens("layer")For CountLayer=1 To 32 Step 1yers(CountLayer).Visible = vbFalseNextyers(n).Visible = vbTrueEnd Subn=层数+1初始画面程序(画面空地--属性--事件--其它--打开画面--动作)**打印按钮**#include "apdefap.h"void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y){WinExec("PRTSCR.EXE -hardcopy",SW_SHOWNORMAL);}**一个圈代表电机两种状态**#include "apdefap.h"void OnClick(char* lpszPictureName, char* lpszObjectName, char*lpszPropertyName){char* opentag="DI1电机运行信号";char* closetag="DI2电机运行信号";BOOL open,close; open = GetTagBit(opentag); close = GetTagBit(closetag);if (open)return CO_GREEN;if (close)return CO_BLUE;。
wincc 脚本,实践可用
1风机风叶c动作全局脚本触发器时间0.5s#include"apdefap.h"int gscAction( void ){#pragma option(mbcs)int a,b,c;b=GetTagWord("fdf");//风机风叶状态显示a=GetTagBit("i12");//风机运行反馈的I1.2if (a==1){b=b*2;if (b>4||b<1) b=1;}elseb=0;SetTagWord("fdf",b);return 0;}2 火焰状态全局vb 触发器时间0.5sOption ExplicitFunction actionDim a,b,c,d,ea=HMIRuntime.tags("huoyan2").Read 'plc变量火焰状态 0 1 2 3 b=HMIRuntime.tags("wc1").Read '火焰状态显示是内部变量16位无符号Select Case aCase 0HMIRuntime.tags("wc1").write 0Case 1b=b+1If b>2 Then b=1HMIRuntime.tags("wc1").write b'statementblock_1Case 2If b<4 Then b=4b=b*2If b>20 Then b=4HMIRuntime.tags("wc1").write b'statementblock_2Case 3If b<40 Then b=32b=b*2If b>128 Then b=32HMIRuntime.tags("wc1").write bCase ElseHMIRuntime.tags("wc1").write 0'statementblock_nEnd SelectEnd Function3 仓泵气阀开关状态显示这个在图形编辑器,圆属性的颜色属性c脚本触发时间0.25s#include"apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)int a,b,c,d;a=GetTagWord("DB22_DW62");//plc 开关状态1 2 3 4SetTagBit("prec2",!GetTagBit("prec2")); //Return-Type: BOOLb=GetTagBit("prec2");//plc内部辅助变量这个运行的定义变量无法保存,所以要借用内部变量。
wincc常用C脚本
wincc常用C脚本第一篇:wincc常用C脚本.用户注销:#pragma code(“useadmin.dll”)#include “PWRT_api.h” #pragma code()PWRTLogout();2.用户登录:#pragma code(“useadmin.dll”)#include “PWRT_api.h” #pragma code()PWRTLogin('c');3.关闭项目并退出wincc:ExitWinCC();4.退出运行到wincc资源管理器:DeactivateRTProject();按钮变三种颜色#include “apdefap.h” long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){ #pragma option(mbcs)if(GetTagWord(“TX/ZSH001”)==1)return0x0000ff00;else if(GetTagWord(“TX/ZSL001”)==1)return 0x000000ff;else return 0x00c0c0c0;} 一个调用按钮变色#include “apdefap.h” long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName){ #pragma option(mbcs)if(GetTagWord(“NewTag”)==0)return0x0000ff00;else return 0x00ffffff;}5.结束监控并关闭计算机(会弹出确认对话框)HWND hWnd = NULL;//Author:Smartsys int iRet;hWnd = FindWindow(NULL,“WinCC-运行系统”);//如果运行语言为英文if(WinCCHwnd==0)WinCCHwnd=FindWindow(NULL,“Win CC-运行系统-”);//如果运行语言为中文CloseWindow(WinCCHwnd);10.显示或不显示(其中hiddVtext 为内部的二进制变量)if(GetTagBit(“hiddVtext”)==0)//Return-Type: BOOL { SetTagBit(“hiddVtext”,TRUE);//Return-Type: BOOL //Return-Type: BOOL } else {SetTagBit(“hiddVtext”,FALSE);} 10.打开编辑画面的脚本#pragma option(mbcs)#ifdef RUN_ON_WEBNAVIGATOR #elseHWND hExplorerWindow= NULL;HWND hRuntimeWindow= NULL;hExplorerWindow=FindWindow(“WinCCExplorerFrameWndClass”,NULL);hRuntim eWindow=FindWindow(“PDLRTisAliveAndWaitsForYou”,NULL);if(hExplor erWindow){ ShowWindow(hExplorerWindow, SW_MINIMIZE);// This entry is only necessary for Windows 2000 ShowWindow(hExplorerWindow,SW_SHOWNORMAL);SetForegroundWindow(hExplorerWindow) ;} else printf(“rn SetForeground failed”);#endif 11.如何在WINCC中制作一个保持型按钮方法1:if(GetTagBit(“M10”))SetTagBit(“M10”,0);elseSetTagBit(“M10”,1);方法2:SetTagBit(“M1.0”,(SHORT)!GetTagBit(“M1.0”));求反指令,如果为1点击变为0,如果为0点击变为1 方法3:或者做两个按钮,按钮一:显示,直接连接m1.0,是--不显示,否--显示。
Get格雅wincc常用C脚本..
wincc常用C脚本...用户注销:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();2.用户登录:#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');3.关闭工程并退出wincc:ExitWinCC ();4.退出运行到wincc资源管理器:DeactivateRTProject ();按钮变三种颜色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("TX/ZSH001")==1)return 0x0000ff00;elseif(GetTagWord("TX/ZSL001")==1)return 0x000000ff;elsereturn 0x00c0c0c0;}一个调用按钮变色#include "apdefap.h"long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {#pragma option(mbcs)if(GetTagWord("NewTag")==0)return 0x0000ff00;elsereturn 0x00ffffff;}5.结束监控并关闭计算机〔会弹出确认对话框〕HWND hWnd = NULL;//Author:Smartsysint iRet;hWnd = FindWindow(NULL,"WinCC-运行系统 - ");iRet=MessageBox(hWnd,"结束监控并关闭计算机","关闭操作站",MB_YESNO|MB_ICONWARNING|MB_APPLMODAL); if(iRet==IDYES)DMExitWinCCEx (DM_SDMODE_POWEROFF);6.点击事件弹出对话框,通过点击弹出对话框确实定和取消按钮实现对变量的置位或取消:int r;r=MessageBox(NULL, "YES为开,NO为关", "确定开命令:", MB_YESNO |MB_SYSTEMMODAL); if (r==IDYES)SetTagBit("TAGNAME",TRUE);elseSetTagBit("TAGNAME",FALSE);7.开显示关显示:〔要在内部变量中建立三个二进制变量COLSE_DISPLAY、DISPLAY_NO和DISPLAY_COMMENT〕// Funktion: Bit in Doppelwort setzen;if (GetTagBitWait("COLSE_DISPLAY")==1 ) {SetTagBit("COLSE_DISPLAY",0);SetTagBit("DISPLAY_NO",0); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}else{SetTagBit("COLSE_DISPLAY",1);SetTagBit("DISPLAY_NO",1); //Return-Type: BOOLSetTagBit("DISPLAY_COMMENT",0);}8.开阀确认:BOOL a;a=GetTagBit("30T制水启动");//Return-Type :short intif (a==0){if(MessageBox(NULL,"真的要启动制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROU ND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水启动",1);//Return-Type :BOOL}}else{if(MessageBox(NULL,"真的要停止制水吗?","操作提示",MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROU ND|MB_SYSTEMMODAL) == 6){ SetTagBit("30T制水停止",1);}}HWND WinCCHwnd;WinCCHwnd=FindWindow(NULL,"WinCC-Runtime - "); //如果运行语言为英文if (WinCCHwnd==0)WinCCHwnd=FindWindow(NULL,"WinCC-运行系统- "); //如果运行语言为中文CloseWindow(WinCCHwnd);10.显示或不显示〔其中hiddVtext为内部的二进制变量〕if(GetTagBit("hiddVtext")==0)//Return-Type: BOOL{SetTagBit("hiddVtext",TRUE);//Return-Type: BOOL//Return-Type: BOOL}else{SetTagBit("hiddVtext",FALSE);}#pragma option(mbcs)#ifdef RUN_ON_WEBNAVIGATOR#elseHWND hExplorerWindow= NULL;HWND hRuntimeWindow= NULL;hExplorerWindow=FindWindow("WinCCExplorerFrameWndClass",N ULL);hRuntimeWindow=FindWindow("PDLRTisAliveAndWaitsForYou",N ULL);if(hExplorerWindow){ShowWindow(hExplorerWindow, SW_MINIMIZE); // This entry is only necessary for Windows 2000ShowWindow(hExplorerWindow, SW_SHOWNORMAL);SetForegroundWindow(hExplorer Window);}elseprintf("rn SetForeground failed");#endif方法1:if( GetTagBit("M10") )SetTagBit("M10",0);elseSetTagBit("M10",1);方法2:SetTagBit("M1.0",(SHORT)!GetTagBit("M1.0"));求反指令,如果为1点击变为0,如果为0点击变为1方法3:或者做两个按钮,按钮一:显示,直接连接m1.0,是--不显示,否--显示。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
切换按钮001 SetTagBit("TE_BOOL",!GetTagBit("TE_BOOL"));002 BOOL AA=GetTagBit("TE_BOOL");if(A) SetTagBit("TE_BOOL",0);Else SetTagBit("TE_BOOL",1);003 SetTagBit("TE_BOOL ",1-GetTagBit("TE_BOOL "));I O 域处的格式化输入输出在I/O域的输出值事件处的动作Float F_TAG;F_TAG =GetTagFloat("TE_FLOAT");return(F_TAG /100);WINCC运行画面最小化HWND WinCCHwnd;WinCCHwnd=FindWindow("PDLRTisAliveAndWaitsForYou",NULL);CloseWindow(WinCCHwnd);WINDOWS中提供的标准对话框{ BOOL bool1;HWND Hwnd;int iRet;Hwnd = FindWindow(NULL,"WinCC-运行系统- ");if (!Hwnd) Hwnd = FindWindow(NULL,"WinCC-运行系统- ");if (!Hwnd) printf("\r\nGetWinCC Handle Failed!");iRet=MessageBox(Hwnd,"确认合闸","确认对话框",MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_SYSTEMMODAL);switch (iRet){case IDYES: printf("user do YES\r\n");SetTagBit("TE_QUEST",1);break;case IDNO: printf("user do NO\r\n");SetTagBit("TE_QUEST",0);break;case IDCANCEL: printf("user do CANCEL\r\n");break;}}本画框的功能是点击按钮的时候弹出windows询问对话框其中“确认合闸”为对话内容,对话框的名称为“确认对话框”用户不同显示不同的按钮你可以在用户管理器给每个用户不同的权限,使他们对按钮有不同的操作权,这是最简便的。
但是如果一定要根据用户不同显示不同的按钮就要用C脚本了下面这段代码可以加在有两个按钮的画面的对象属性--事件--画面对象--其他--打开画面,三个用户名是user1,user2,user3,按钮名称是按钮1 ,按钮2,你可以自行修改,这里假设已经进行过用户登录的操作,当打开有这两个按钮的画面时执行下列脚本判断用户并显示相应的按钮if (strcmp(GetTagChar("@CurrentUser"),"user1") ){}else{SetVisible(lpszPictureName,"按钮1",TRUE);SetVisible(lpszPictureName,"按纽2",FALSE);}if(strcmp(GetTagChar("@CurrentUser"),"user2") ){}else{SetVisible(lpszPictureName,"按钮1",FALSE);SetVisible(lpszPictureName,"按钮2",TRUE);}if (strcmp(GetTagChar("@CurrentUser"),"user3") ){}else{SetVisible(lpszPictureName,"按钮1",TRUE);SetVisible(lpszPictureName,"按钮2",TRUE);}strcmp是比较字符串的语句,比较文本变量只能用它,帮助里没有的,用它比较读取到的用户名GetTagChar("@CurrentUser")和三个用户名"userX",你把这段语句加到一个按钮的鼠标动作里,看点击按钮会不会两个按钮现实和隐藏。
登录登出对话框#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogin('c');PWRTLogin 参数必须是 CHAR 字符。
它指定了显示对话框的监视器。
如果只使用一个监视器,那么保留默认参数“c”或者指定“1”。
#pragma code ("useadmin.dll")#include "PWRT_api.h"#pragma code()PWRTLogout();PWRTLogin 参数必须是 CHAR 字符。
它指定了显示对话框的监视器。
如果只使用一个监视器,那么保留默认参数“c”或者指定“1”。
WinCC如何实现鼠标OnMouseOVer事件用WINDOWAPI函数GetCusorPos获取当前鼠标位置,用GetWindowRect函数获取窗口位置,两值相减得鼠标在WINCC frame上的相对位置。
用全局脚本(设定为1s定时刷新),然后获取要OnMouseOver事件的物体的位置,并与鼠标位置相比较,如一致则触发自己定义的动作。
#i nclude "apdefap.h"int gscAction( void ){#pragma code("user32.dll");BOOL GetCusorPos(POINT lpPoint); //获取鼠标的位置(绝对位置-对应屏幕分辨率)BOOL GetWindowRect(HWND hwnd,LPRECT lpRect); //获取窗体位置#pragma code();POINT pPos;RECT rRec;HWND hwnd;BOOL bRet,bRet2;long lLeft,lTop,lWidth,lHeight;long lX,lY;char szStr[100];hwnd=FindWindow(NULL,"WinCC-Runtime - "); //如语言为中文应为"WinCC 运行系统-"if (hwnd==0) {printf("\r\nError! WinCc Handle is %d",hwnd);goto over;}bRet=GetCursorPos(&pPos);if (bRet==0) goto over;bRet2=GetWindowRect(hwnd,&rRec);if (bRet2==0) goto over;lX=pPos.x-rRec.left; //鼠标对{置lY=pPos.y-rRec.top; //鼠标位置//如果为非全屏模式,需将上述数值中的高height判断减去标题栏的宽度//printf("The Current Cusor Pos is x:%d,y:%d\r\n",pPos.x,pPos.y);//printf("The Cusor Pos in Window is x:%d,y:%d\r\n",pPos.x-lLeft2,pPos.y-lTop2);lLeft=GetLeft("NewPdl0.Pdl","Text1"); //Return - Type :long intlTop=GetTop("NewPdl0.Pdl","Text1"); //Return - Type :long intlWidth=GetWidth("NewPdl0.Pdl","Text1"); //Return - Type :long intlHeight=GetHeight("NewPdl0.Pdl","Text1"); //Return - Type :long intif ((lX>=lLeft)&&(lY>=lTop)&&(lX<=lLeft+lWidth)&&(lY<=lTop+lHeight)) {sprintf(szStr,"%d,%d",lX,lY);SetText("NewPdl0.Pdl","Text1",szStr); //Return - Type :char*}//printf("The Text1 Pos is x:%d,y:%d\r\n",lLeft2,lTop-lTop2);over:return 0;}退出WINCC监控时选择退出方式DMExitWinCCEx (DM_SDMODE_SYSTEM);或者使用动态向导通过给变量ExitSystem赋不同的数值实现不同的方式int a;a=GetTagWord("ExitSystem"); //返回类型:WORDswitch(a){case 1 : MExitWinCCEx (DM_SDMODE_REBOOT); break;case 2 : DMExitWinCCEx (DM_SDMODE_SYSTEM); break;case 4 : ExitWinCC();break; ////DMExitWinCCEx (DM_SDMODE_WINCC); break; case 8 : DMExitWinCCEx (DM_SDMODE_LOGOFF); break;}如何实现用户登陆日志wincc中用c脚本实现?#pragma code("kernel32.dll")VOID GetLocalTime(LPSYSTEMTIME lpSystemTime);#pragma code()char* username;char buf[128];static char preuser[128];unsigned a,b,c,d,e,f;FILE* fp;SYSTEMTIME sysTime;//读取系统时间,并且复制给变量a,b,c,d,e,fGetLocalTime(&sysTime); a=sysTime.wHour; b=sysTime.wMinute; c=sysTime.wSecond; f=sysTime.wYear; e=sysTime.wMonth; d=sysTime.wDay;username = GetTagChar("@CurrentUser"); //得到当前用户名称fp= fopen("c:\\wincclog.txt", "a+"); //创建文件if(strcmp(username, preuser)!=0) //如果当前用户名称和前一个用户名不同{ if((strcmp(username, "") != 0)&&(strcmp(preuser, "") == 0))//如果当前用户名称不空同时前一个用户名为空{ sprintf(buf, "用户:%s\t登陆时间是:\t %d-%d-%d,%d-%d-%d\n", username,a,b,c,d,e,f);fputs(buf, fp); }else{ if((strcmp(username, "") == 0)&&(strcmp(preuser, "") != 0)) //如果当前用户名称为空同时前一个用户名不空{ sprintf(buf, "用户:%s\t退出时间是:\t %d-%d-%d,%d-%d-%d\n", preuser,a,b,c,d,e,f);fputs(buf, fp);}else{sprintf(buf, "用户:%s\t退出时间是:\t %d-%d-%d,%d-%d-%d\n", preuser,a,b,c,d,e,f);fputs(buf, fp);sprintf(buf, "用户:%s\t登陆时间是:\t %d-%d-%d,%d-%d-%d\n", username,a,b,c,d,e,f);fputs(buf, fp);}}}strcpy(preuser, username);fclose(fp);return 0;用户登陆日志:(包括用户的登陆退出信息,以便查询在什么时间段是哪个用户在使用这个监控软件)设置语言英语SetLanguage(0x409);法语SetLanguage(0x407);德语SetLanguage(0x40C);调用计算器如果在C脚本中仅仅有一句ProgramExecute("CALC.exe")此时不关计算器就切换画面,则计算器都在后台运行。