DemoGL::Reference::Functions::DEMOGL_AppRun

DEMOGL_AppRun

DEMOGL_AppRun starts the DemoGL powered part of your application. This part can be a normal execution of the Timeline events scripted in the application script as a normal win32 program, as a screensaver or as a screensaver preview. It can also start the configuration part of your application when that application is a screensaver.

int
DEMOGL_AppRun(
	const HINSTANCE hInstance,
	const SStartupDat *psdStartupDat,
	const char *pszWindowTitle,
	const bool bUseCrypting, 
	const byte byKey1, 
	const byte byKey2, 
	const int iRunType
);
	
Parameters.
hInstance
The instance of the application. This value is passed to WinMain() by windows. This value is needed to let DemoGL access resources stored in your application, for example an icon or a bitmap that should show up on the startup dialog. See Definitions and Defaults for more details.
psdStartupDat
Pointer to a SStartupDat structure, which contains all the data DemoGL needs to startup and run your application succesfully. Can be NULL, which results in the usage of the values stored in the registry, if present, or if not present the default build in values. When you pass a SStartupDat structure to DEMOGL_AppRun, you should set every value of the structure.
pszWindowTitle
Pointer to a zero-terminated string which will result in the title of the application's window, when applicable. This title is displayed in the dragbar/titlebar of the window, when the application runs in windowed mode.
bUseCrypting
Specifies whether to enable or disable decryption. If this parameter is true, decryption is enabled and DemoGL will decrypt all the data loaded before it's passed back to the caller. As decryption keys are used the values specified in byKey1 and byKey2. If this parameter is false, these variables are ignored.
byKey1
Specifies the first decryption key for the decryption process. Only valid when bUseCrypting is true. You crypt your data with Cryde.
byKey2
Specifies the second decryption key for the decryption process. Only valid when bUseCrypting is true. You crypt your data with Cryde.
iRunType
Specifies how your application should run. iRunType can be one of the following values:

RunType Description
RUNTYPE_NORMAL The default. Your application will run like a normal win32 application. DemoGL will open a startup dialog so the user can select runtime specific options, and when the user selects to start the application, the execution will continue by opening a window and run the application script. The values specified in psdStartupDat  are used to preset options in the startup dialog, but are overruled by the eventually stored values in the registry. When the user selected this, the options selected are stored in the registry when the application is actually started, when the user clicks the start button. DEMOGL_AppRun will exit when the script is terminating the application or the user terminates the application. DemoGL will recover from errors during the startup of the application if the user selected runtime specific options that are not valid (for example a resolution that is not supported by the video adapter)
RUNTYPE_NODIALOG As RUNTYPE_NORMAL, but no startup dialog is shown and DemoGL will use the values specified in psdStartupDat as specific runtime options. The user is not able to select an option how to run the application. No options are stored nor read from the registry. DEMOGL_AppRun will exit when the script is terminating the application or the user terminates the application. Any error during the startup of the application will result in application termination. DemoGL can't recover from errors caused by options set in psdStartupDat/i>, which are not valid during runtime.
RUNTYPE_SAVER_CONFIG DemoGL will open the startup dialog of RUNTYPE_NORMAL, but now the user is able to set runtime specific options for the application when it's ran as a screensaver. DEMOGL_AppRun will exit as soon as the user clicks Save or Cancel. When the user set runtime specific options using this RunType, these options are used to run the application as a screensaver at every run.
RUNTYPE_SAVER_NORMAL As RUNTYPE_NODIALOG, but DemoGL will now read the settings set by the user when the application was ran in RUNTYPE_SAVER_CONFIG, plus the application is ran as a screensaver, thus called by windows. Windows will call your application as a normal screensaver when you select your application as the windows screensaver and press Preview on the Screensaver tab in display properties, or when the time-out occurs set with the screensaver properties in display properties. DEMOGL_AppRun exits when the user moves the mouse or presses a key or when the script terminates DemoGL.
RUNTYPE_SAVER_PREVIEW As RUNTYPE_SAVER_NORMAL, but now the application runs inside the small area on the screensaver tab. Windows will block all keyboard messages to the application, but mouse messages are still sent. Runtime specific settings are used, but not for windowsize, as the application runs inside an area specified by windows.
RUNTYPE_SAVER_PASSWORD Not implemented. DemoGL will exit immediately. All successors of windows95 will do their own password unlocking when it comes to screensavers, as also WinNT/Windows2000, only windows95 does not but relies on the unlocking code inside the screensaver, controlled with this RunType, but it's not implemented inside DemoGL.
RUNTYPE_UNKNOWN Used when the RunType could not be determined, it will result in a clean exit of DEMOGL_AppRun.

Return values.
If the function succeeds, it returns SYS_OK.
If the function fails, it returns SYS_NOK.

Remarks.
After you've registered your effectobjects with DEMOGL_EffectRegister, you can start the application by calling DEMOGL_AppRun, specifying startup properties and the RunType DemoGL should use. For normal win32 application runtimes, like RUNTYPE_NORMAL and RUNTYPE_NODIALOG, you know what runtype to run your application in. This is not the case when it comes to a screensaver application, powered by DemoGL. Windows will specify on the command line how the screensaver should behave: as a preview window, as a normal screensaver, as a configuration window or as a password unlock instance (not implemented in DemoGL, see RUNTYPE_SAVER_PASSWORD). To determine which RunType you should specify when your screensaver application is ran, call DEMOGL_ParseScreenSaverCL and pass the commandline received by WinMain() to the function. DEMOGL_ParseScreenSaverCL will then fill a SScreenSaverCLParams structure for you which contains the type of screensaver runtype you should use. Your application can now determine if it first should open it's own configuration dialog, or for example if it should start the screensaver normally. You can first program your screensaver as a normal application using RUNTYPE_NORMAL or RUNTYPE_NODIALOG, and when the application runs as planned you can include the commandline parsing logic to actually run the application as a screensaver. After you've done that you should rename the executable to a name with the extension .scr and the screensaver is finished. See the example below.

The values specified in psdStartupDat  are always overruled by the values eventually stored in the registry, except when you specify RUNTYPE_NODIALOG as RunType. psdStartupDat  values are used as hints to set options in the startup dialog or the config dialog and as execution specific values when a startup dialog or config dialog is not applicable. The values set in the startup dialog and the config dialog are stored in different places in the registry. For RUNTYPE_NORMAL applications, the values are stored in the registry key HKCU/Software/DemoGL/Application/Application title/AppData. For RUNTYPE_SAVER_* applications, the values are stored in the registry key HKCU/Software/DemoGL/Screensaver/Application title/AppData, by using the RUNTYPE_SAVER_CONFIG RunType. It's recommended you should store custom application parameters inside these registry keys, depending on the RunType.

When you call DEMOGL_AppRun DemoGL will take over control of your application. The only code in your application that is called is the code inside the registered effectobjects. You should call DEMOGL_AppEnd after DEMOGL_AppRun returns, no matter what returnvalue it will return.

Example.
Below you'll find an example which shows how to determine the RunType of the current instance of the application and how to use it succesfully. It also shows where you should place your own config dialog startcode when you've written a screensaver using DemoGL which relies on settable parameters. You can add a button to that config dialog that calls DEMOGL_AppRun with the RunType RUNTYPE_SAVER_CONFIG to let the user set runtime specific settings like screendepth, resolution, sound etc.

// Declare a pointer to the screensaver command line parameter structure
SScreenSaverCLParams	*pSSCLParams;
	
// Parse commandline for screensaver exectype
pSSCLParams=DEMOGL_ParseScreenSaverCL(lpCmdLine);

iRunType=RUNTYPE_NORMAL;

// start as a screensaver
switch(pSSCLParams->iSaverExecType)
{
	case DGL_SSAVERET_CONFIG:
	{
		/////////////////////////
		// Insert your own configwindow initialisation and start up code HERE
		// If you do you shouldn't enter DEMOGL_AppRun() below but include it
		// in your dialog with a button.
		/////////////////////////
		iRunType=RUNTYPE_SAVER_CONFIG;
	}; break;
	case DGL_SSAVERET_NORMAL:
	{
		iRunType=RUNTYPE_SAVER_NORMAL;
	}; break;
	case DGL_SSAVERET_PREVIEW:
	{
		iRunType=RUNTYPE_SAVER_PREVIEW;
	}; break;
	default:
	{
		// should not run, unknown or unsupported screensaver type.
		iRunType=RUNTYPE_UNKNOWN;	// will return immediately
	}; break;
}
// Start the application. We won't return until the demo ends (by userinteraction or by script) or 
// when a fatal error occurs.
DEMOGL_AppRun(hInstance, &sdStartupDatValues, "My title", false,0,0,iRunType);

// End it. Call this routine to signal DemoGL it's all over and it should release
// claimed resources.
DEMOGL_AppEnd();
	

Requirements.
DemoGL v1.3 (build 0112 or higher)

See also.
DEMOGL_AppEnd, DEMOGL_EffectRegister, DEMOGL_ParseScreenSaverCL, SStartupDat, SScreenSaverCLParams, Definitions and Defaults

Last changed on 16-feb-2001

©1999-2001 Solutions Design