以下是Demo程序退出画面的两个按钮的脚本,不太会C语言,看不明白,麻烦哪位大侠给注解一下,万分感谢!
按钮1:
#include "apdefap.h"
void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
int i, j, n;
char pic_name[256];
char obj_name[60];
n = strlen( lpszPictureName );
for ( i = n; i > 0; i-- )
if ( lpszPictureName[i] == '.' )
{
strncpy( pic_name, lpszPictureName, i );
strcpy( obj_name, &lpszPictureName[i+1] );
for ( j = 0; j < (n-i); j++)
if ( obj_name[j] == ':' )
{
obj_name[j] = '\0';
break;
}
SetVisible(pic_name,obj_name,FALSE);
break;
}
}
按钮2:
#include "apdefap.h"
void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
#define ApcRT_Start_Stop "RT_Start_Stop"
#define ApcRT_Stat "RT_Stat"
#pragma code ("kernel32.dll")
WINBASEAPI VOID WINAPI Sleep(DWORD dwMilliseconds);
#pragma code ()
SetTagBit(ApcRT_Stat ,1);
SetTagBit(ApcRT_Start_Stop,1-GetTagBit(ApcRT_Start_Stop));
Sleep(3000);
DeactivateRTProject ();
}
最佳答案
#include "apdefap.h"
void OnLButtonDown(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
int i, j, n; //定义整型变量
char pic_name[256]; //定义字符串,长度是256个字节
char obj_name[60]; //定义字符串,长度是60个字节
n = strlen( lpszPictureName ); //将lpszPictureName的长度付给n
for ( i = n; i > 0; i-- ) //for循环从n开始递减
if ( lpszPictureName[i] == '.' ) //如果lpszPictureName的第i的字符等于'.',则执行以下语句
{
strncpy( pic_name, lpszPictureName, i ); //将lpszPictureName的前i的字符拷贝给pic_name
strcpy( obj_name, &lpszPictureName[i+1] );
for ( j = 0; j < (n-i); j++)
if ( obj_name[j] == ':' )
{
obj_name[j] = '\0';
break;
}
SetVisible(pic_name,obj_name,FALSE); //设置对象属性为不可见
break;
}
}
提问者对于答案的评价:
谢谢!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc270773.html