This script illustrates how to run an external program or a program that was compiled inside your publication. For instance, you would like to launch a program that you ship with your publication.
We use the internal HEScript function named RunAProgram to execute a program. We only need to know the path to the program file we want to launch. Fortunately HTML Executable has a global variable named HEPublicationPath pointing to the path of the folder that contains the publication’s exe file.
procedure RunTutor; var EbookPath, MyProgram: String; begin EbookPath := GetGlobalVar("HEPublicationPath", ""); MyProgram := EbookPath + "hehvdemo.exe"; RunAProgram(MyProgram, "", EbookPath, false, SW_SHOWNORMAL); end;
First we get the path to our publication stored into the EbookPath variable. Then we add the filename of our executable program and we pass the result to the RunAProgram function.
You can include the program file directly into your publication .exe. In that case you need to extract the program file before running it: use the _heopenit target or the following code:
procedure RunACompiledProgram; var MyProgram: String; begin MyProgram := UnpackTemporaryResource("programfilename.exe"); RunAProgram(MyProgram, "", ExtractFilePath(MyProgram), false, SW_SHOWNORMAL); end;
This code uses the UnpackTemporaryResource internal function that extracts a compiled file from the publication to a temporary location. Then you just need to execute the file.
Copyright G.D.G. Software 2016. All rights reserved