wincc常用C脚本_第1页
wincc常用C脚本_第2页
wincc常用C脚本_第3页
wincc常用C脚本_第4页
wincc常用C脚本_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.用户注销:#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* lpszob

2、jectname, 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(ge

3、ttagword(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.点击事件弹出对话框,通过

4、点击弹出对话框的确定和取消按钮实现对变量的置位或取消: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)=

5、1 )settagbit(colse_display,0);settagbit(display_no,0); /return-type: boolsettagbit(display_comment,0);elsesettagbit(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,真的要启动制水吗?

6、,操作提示,mb_yesno|mb_iconquestion|mb_setforeground|mb_systemmodal) = 6) settagbit(30t制水启动,1);/return-type :boolelseif(messagebox(null,真的要停止制水吗?,操作提示,mb_yesno|mb_iconquestion|mb_setforeground|mb_systemmodal) = 6) settagbit(30t制水停止,1);9.将wincc运行画面最小化hwnd wincchwnd;wincchwnd=findwindow(null,wincc-runtime

7、- ); /如果运行语言为英文if (wincchwnd=0) wincchwnd=findwindow(null,wincc-运行系统 - ); /如果运行语言为中文closewindow(wincchwnd);10.显示或不显示(其中hiddvtext为内部的二进制变量)if(gettagbit(hiddvtext)=0) /return-type: boolsettagbit(hiddvtext,true); /return-type: bool/return-type: boolelsesettagbit(hiddvtext,false);10.打开编辑画面的脚本#pragma opt

8、ion(mbcs)#ifdef run_on_webnavigator#elsehwnd hexplorerwindow= null;hwnd hruntimewindow= null;hexplorerwindow= findwindow(winccexplorerframewndclass,null);hruntimewindow= findwindow(pdlrtisaliveandwaitsforyou,null);if(hexplorerwindow)showwindow(hexplorerwindow, sw_minimize); / this entry is only nece

9、ssary for windows 2000showwindow(hexplorerwindow, sw_shownormal);setforegroundwindow(hexplorerwindow);elseprintf(rn setforeground failed);#endif11.如何在wincc中制作一个保持型按钮方法1:if( gettagbit(m10) )settagbit(m10,0);elsesettagbit(m10,1);方法2:settagbit(m1.0,(short)!gettagbit(m1.0);求反指令,如果为1点击变为0,如果为0点击变为1方法3:或者

10、做两个按钮,按钮一:显示,直接连接m1.0,是-不显示,否-显示 。事件,直接连接,源,常数1,变量m1.0;按钮二:事件,直接连接,源,常数0,变量m1.0;用按钮一覆盖按钮二12变量每秒加1dword a;a=gettagdword(tank);a+=1;if(a100) (a=0);settagdword(tank,a);return 0; wincc动画脚本电机风扇旋转(几何-起始角度):#include apdefap.hlong _main(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)sta

11、tic dword f=20;if (gettagbit(di电机运行信号) f= f+30;if (f=360) (f=0);return f;电机风扇旋转(几何-结束角度):#include apdefap.hlong _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)(停车后,物料回到原点)*#includ

12、e apdefap.hlong _main(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)static int a=350;if (gettagbit(di电机运行信号) & (a=720) (a=350); if (!gettagbit(di电机运行信号) (a=350); return a;物料水平右移动(几何-位置x)(停车后,物料停在该点)#include apdefap.hlong _main(char* lpszpicturename, char* lpszobjectname, char*

13、lpszpropertyname)static int a=350;if (gettagbit(di电机运行信号) & (a=720) (a=350); return a;物料向上移动(几何-位置y)(停车后,物料停在该点)#include apdefap.hlong _main(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)static int b=450;if (gettagbit(di电机运行信号) & (b=290) b-=10;if (btm_year-100+2000,ptm-tm_mon+1

14、,ptm-tm_mday);return(p);时分秒(静态文本)#include apdefap.hchar* _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);登陆到指定的用户名

15、无须手动输入(按钮操作)#include apdefap.hvoid 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.hvoid onlbuttondown(char* lpszpictur

16、ename, 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.hvoid onlbuttondown(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname, uint nflags, int x, int y

17、) deactivatertproject ();单位递增按钮(到上限不提示出错)#include apdefap.hvoid onclick(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)dword value;value=gettagdword(ai标签); if (value90) (value=上限);else value=value+10;settagdword(ai标签,value); 单位递减按钮(到下限不提示出错)#include apdefap.hvoid onclick(char* l

18、pszpicturename, char* lpszobjectname, char* lpszpropertyname)dword value;value=gettagdword(ai标签); if (value10) (value=下限);else value=value-10;settagdword(ai标签,value); *单位递增按钮(到上限提示出错)*#include apdefap.hvoid onclick(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)dword value;hwnd

19、hwnd=null ; hwnd=findwindow(null,wincc-运行系统- ); value=gettagdword(ai标签); if (value0) (value=value-10);else messagebox(hwnd, 已到达下限值!, 错误,mb_ok|mb_iconwarning|mb_applmodal);settagdword(ai标签,value); *自动登陆到指定的用户(画面属性-其它授权)*#include apdefap.hlong _main(char* lpszpicturename, char* lpszobjectname, char* l

20、pszpropertyname)#pragma code(useadmin.dll)#include pwrt_api.h#pragma code()pwrtsilentlogin(用户名, 口令);return(0x0);*询问框(最好用于单机启动,组启也可,2个按钮,no不操作)*#include apdefap.hvoid onlbuttondown(char* lpszpicturename, char* lpszobjectname, char* lpszpropertyname, uint nflags, int x, int y)hwnd hwnd=null;int 上位启动信号

21、;hwnd=findwindow(null,wincc c-course);if (gettagbit(di备妥)上位启动信号=messagebox(hwnd,电源已备妥,您现在确定要启动吗?,启动!, mb_yesno|mb_iconquestion|mb_applmodal);printf(rnexample 3rn); if (上位启动信号=idno) (printf(user selected no button rn); else (settagbyte(上位启动信号,1);elsemessagebox(hwnd,电源未备妥,请查证后重试!,启动!, mb_ok|mb_iconhan

22、d|mb_applmodal);*询问框(最好用于单机启动,组启也可,3个按钮,no复位)*#include apdefap.hvoid 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, 电源已备妥,您现在确定要启动吗?,

23、启动!, mb_yesnocancel|mb_iconquestion|mb_applmodal); if (上位启动信号=idcancel) (printf(user selected no button rn); else if (上位启动信号=idyes) (settagbyte(上位启动信号,1); else (settagbyte(上位启动信号,0); elsemessagebox(hwnd, 电源未备妥,请查证后重试!,启动!, mb_ok|mb_iconhand|mb_applmodal);*搅拌器左侧扇页(几何宽度)*#include apdefap.hlong _main(c

24、har* lpszpicturename, char* lpszobjectname, char* lpszpropertyname)static int h=50;static int u=0;if (gettagbit(di电机运行信号)if (h0)&(h=0)&(u=75)&(h125)(h+=2);return h;if (u75)(u-=2);return u;u=125;h=75;return h;return u;if (!gettagbit(di电机运行信号)h=75;u=125;return h;return u;*显示层按钮*sub x6309x94ae2x0000x00

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论