Wincc常用C脚本及常用功能
打开用户管理器
ProgramExecute(""); 取消激活
#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_ICONWARNING|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_ICONWARNING|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:\\", "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);
}
读操作 fprintf作用
#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:\\","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是要显示的子画面。
在主画面中的画面窗口中切换显示子画面
SetPictureName("man.pdl","PicWindow_main","winder_basic_setting.pdl"); SetVisible("man.pdl","PicWindow_main",1);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。