GLG Toolkit, C / C++ API Library  Version 4.5
GlgMain.h File Reference
#include "GlgApi.h"

Functions

int GlgMain (int argc, char *argv[], GlgAppContext context)
 A prototype for the cross-platform program entry point that handles argc and argv parameters the same way on all platforms. More...
 

Function Documentation

◆ GlgMain()

int GlgMain ( int  argc,
char *  argv[],
GlgAppContext  context 
)

A prototype for the cross-platform program entry point that handles argc and argv parameters the same way on all platforms.

Parameters
argcNumber of command line parameters.
argvCommand line parameter list.
contextAn application context:
  • Windows: hInstance parameter of the WinMain entry point.
  • X11 and Gtk: (GlgAppContext)0
Returns
Exit code on Windows, GLG_EXIT_OK on X11 and in Gtk.

On Linux/Unix, GlgMain supplies the main entry point.

On Windows, GlgMain supplies the WinMain entry point and parses its lpCmdLine argument to extract cross-platform argc and argv arguments.

To use GlgMain, include the GlgMain.h file and use GlgMain in the program as shown in the example below.

Example

The following C code demonstrates an example of a GLG application code that uses GLG Generic API to display a GLG drawing in a cross-platform way. This code can compiled and used without any changes in either the X11, Gtk or Windows environment:

#include "GlgMain.h"
int GlgMain( int argc, char * argv[], GlgAppContext context )
{
// Initialize the Toolkit and let it process command-line arguments.
GlgInit( False, app_context, argc, argv );
// Load and display a drawing.
GlgObject viewport = GlgLoadWidgetFromFile( "drawing.g" );
GlgInitialDraw( viewport );
// Code to add an input callback and install a timer to update the drawing with data should be placed here.
...
// Process events.
int exit_code = GlgMainLoop();
return exit_code;
}
int GlgMain(int argc, char *argv[], GlgAppContext context)
A prototype for the cross-platform program entry point that handles argc and argv parameters the same...
#define False
A platform-independent boolean constant.
Definition: GlgApi.h:479
struct GlgObjectData * GlgObject
Opaque GlgObject type that represents all GLG objects in the GLG C API.
Definition: GlgApi.h:3376
void * GlgAppContext
Platform-independent application context.
Definition: GlgApi.h:3387
GlgAppContext GlgInit(GlgBoolean tk_initialized, GlgAppContext app_context, int argc, char **argv)
Initializes GLG Toolkit API.
GlgObject GlgLoadWidgetFromFile(char *filename)
Loads a GLG widget from a GLG drawing file or a URL.
void GlgInitialDraw(GlgObject object)
Draws a GLG viewport object for the first time after it has been created or loaded.
GlgLong GlgMainLoop(GlgAppContext context)
Implements an event polling loop in a platform independent way.

The following is the C++ version of the example that displays a GLG drawing in a cross-platform way:

#include "GlgMain.h"
int GlgMain( int argc, char * argv[], GlgAppContext init_context )
{
// Initialize the Toolkit and let it process command-line arguments.
GlgSessionC glg_session( False, init_context, argc, argv );
// Load and display a drawing.
GlgObjectC viewport;
viewport.LoadWidget( "drawing.g" );
viewport.InitialDraw();
// Process events.
int exit_code = glg_session.MainLoop( glg_session.app_context );
return exit_code;
}
The main class of the GLG C++ bindings.
Definition: GlgClass.h:606
Provides an interface for initializing the GLG Toolkit.
Definition: GlgClass.h:527
void InitialDraw(void)
Draws a GLG viewport object for the first time after it has been created or loaded.
GlgBoolean LoadWidget(char *filename)
Loads a GLG widget from a file or a URL.