当前位置:文档之家› WINCC的API编程

WINCC的API编程

WINCC的API编程
WINCC的API编程

如何将其它程序的窗口置于最前面?

可以通过使用Windows API 函数FindWindow找到一个窗口的句柄。

假设您希望将一个Microsoft Access 窗口置于最前面:

HWND Handle= ZERO;

Handle= FindWindow("OMAIN",ZERO);

if(Handle)

{

ShowWindow(Handle, SW_MINIMIZE); //

ShowWindow ( Handle, SW_SHOWNORMAL );

SetForegroundWindow(Handle);

}

else

ProgramExecute("C:\\MSOffice.97\\Office\\ACCESS.EXE");

如果没有发现该窗口,随后Microsoft Access 将重新启动。

FindWindow 函数的注意事项:

第一个参数是窗口的类。

可以使用编译器(比如:用Visual C++ 中的Spy 命令)找到类。

第二个参数是窗口的标题(标题栏)。可以指定两个参数中的任何一个,或者两个都指定。在本

运行时通过按下一个按钮来启动一个程序,打印一个文本文件或者打开一个显示订货号

22560470

WinHelp (Windows Help) via API

显示订货号

QUESTION:

Can a user-specific Help be called in a WinCC project?

ANSWER:

Yes, in WinCC you can call use an API call to call a user-specific Help. With "fuCommand" you can branch to a specific topic. For this you create a new project function with the following code:

#pragma code("user32.dll")

BOOL WinHelpA(hwnd, lpszHelpFile, fuCommand, dwData); #pragma code()

#define HELP_CONTENTS 0x0003L

void WinHelpApi() {

HWND hwnd; /* handle of window requesting help */ char HelpFile[255];

UINT fuCommand; /* type of help */

DWORD dwData; /* additional data */

BOOL bRetVal;

LPCTSTR lpszHelp;

lpszHelp = HelpFile;

strcpy(HelpFile, "c:\\Win.95\\Help\\Calc.hlp");

hwnd = FindWindow("PDLRTisAliveAndWaitsForYou","WinCC Runtime - ");

fuCommand = HELP_CONTENTS;

dwData = 0L;

bRetVal=WinHelpA((DWORD) hwnd,(DWORD) lpszHelp, fuCommand, dwData);

printf("hwnd: %d \r\n",hwnd);

printf("HelpFile: %s \r\n",HelpFile);

printf("bRetVal: %d \r\n",bRetVal);

}

In this example the "Help for Windows Pocket Computers" is opened. If you want to open a different Help file, replace the "HelpFile" string with the path of a different file. If the return value "bRetVal" is equal to 0, an error has occurred. You can now call this project function, for example, by clicking a button

Here, we are talking about calling a Windows function. Detailed descriptions are given for instance in the documentation for Visual C++. This example is solely to demonstrate how to

incorporate the call in WinCC.

Print out ASCII file via Action

显示订货号

QUESTION:.

How can I print out an ASCII file via Action?

ANSWER:

If you want to print out an ASCII file via Action (for example for production data acquisition), then you need to make a function call as follows:

system("copy c:\\autoexec.bat \\\\nbgm312a\\ps1cs1");

? You must enter the path and filename in the first part of the call.

?

A network printer is in the second part whose address is given under Printer Properties.

Creating a new directory via C scripts

显示订货号

QUESTION:

How can I create a new directory in WinCC with script functions?

ANSWER:

Use the following program code if you want to create a new directory in WinCC:

#pragma code("kernel32.dll");

BOOL CreateDirectoryA( LPCTSTR ,LPSECURITY_ATTRIBUTES ); #pragma code()'

CreateDirectoryA("c:\\test",NULL);

使用C 函数“Sleep”

显示订货号

问题:

如何在WinCC 中编程“Sleep”等待功能?

解答:

为此,可以使用Windows API 功能“Sleep()”。下面的样例程序演示了如何使用“Sleep”功能。

#pragma code("Kernel32.dll") void Sleep(int Milliseconds); #pragma code()

Sleep(1000); //time in milliseconds

警告:

“Sleep”函数对动作处理性能有很大的负面影响。因此,如果想用此函数的话,请注意以下几点:

? 使用Sleep()时,C 脚本的处理在特定的一段时间内被中断。在此期间内,任何对于被中断功能的请求将不被处理。

? 而且,使用相同触发器的所有动作将不再被处理。使用相同的触发器意味着用同一个循环触发器所有动作或变量触发器的所有动作将不再被处理。如果同步地调用动作,这种调用通过一个变量触发器或事件被周期性地或非周期性地启动,而且所有这些功能使用了Sleep()函数,那么所有的动作会被终止。最坏情况下是;由于启动这四个动作将终止对所有动作的处理。

? 如果说,在一个带10-秒延迟触发器的动作中使用了Sleep()函数。那么所有被循环调用的动作将被中断。结果是,如:用1-秒触发器的动作操作中断, 除此以外,所有后继的动作也不被执行。这就是说,不仅当前的动作不被处理,其它还没有启动的动作也不会被处理。

? 作业不被处理是因为中断仍储存在队列中。一旦中断结束,所有在队列中的动作将开始被处理。但是,中断结束后,在队列中的动作不会在他们原来指定的循环中被处理。因此,如同前面所述的那样,那么队列中剩下的动作将被一个接一个的处理而不再由触发器启动。并且这些动作只是尽可能快的被处理掉。 (理论上同步)。

关键字:

性能提高,功能调用

如何打开一个应用程序并保持其始终在前台显示?

显示订货号

显示订货号

T1_C.zip

显示订货号

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName) {

// 打印机框的调用

ProgramExecute("C:\\WIN.95\\control.exe printers"); }

当在WinCC 脚本中结合一个DLL 时,使用的内存空间增加了

显示订货号

问题:

如果使用Visual C++创建的一个DLL 文件时,发现PC 上使用的内存增加了。对于这种情况,应该怎么办? 解答:

检查是否用正式发行的版本创建了DLL 。所提供WinCC 是正式发行的版本。这意味着WinCC 也可以使用Microsoft DLL MFC42.DLL 的发行版本。

如果在测试版本中有DLL 文件,那么全局脚本中必须另外加载MFC42.DLL 的 测试版本。另外,这会增加对内存的用量。

在WinCC 中始终使用DLL 文件的发行版本。

相关主题
文本预览
相关文档 最新文档