GLG Toolkit, C / C++ API Library  Version 4.5
GLG Custom Control

Windows only: A Win32 control that may be used to integrate GLG drawings in a Windows program. More...

Detailed Description

Windows only: A Win32 control that may be used to integrate GLG drawings in a Windows program.

GLG Custom Control is a Windows wrapper designed for embedding GLG drawings in the programs using a Win32 API. It allows embedding GLG drawings into the Windows interface hierarchy as a custom window control (a window with a custom window type).

The control's class name is "GlgControl". The GLG library registers it when the library is initialized with GlgInit.

Creating GLG Custom Control

The control is created by passing "GlgControl" as the class name parameter of CreateWindow. The viewport object containing the control's drawing is assigned to the control via GlgSetDefaultViewport:

GlgObject viewport = GlgLoadWidgetFromFile( "drawing.g" ); /* Load the drawing from a file. */
if( !viewport )
return FALSE;
GlgSetDefaultViewport( viewport ); /* Set the drawing to be displayed in the custom control. */
/* Create a GLG control to display graphics. */
HWND GlgControl = CreateWindow( "GlgControl", "GlgControl", WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, 600, 400, parent_hWnd, NULL, hInstance, NULL );
GlgDropObject( viewport ); /* Drop: viewport was referenced by the control. */
GlgInitialDraw( viewport ); /* Display the drawing inside the control. */
struct GlgObjectData * GlgObject
Opaque GlgObject type that represents all GLG objects in the GLG C API.
Definition: GlgApi.h:3376
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.
void GlgSetDefaultViewport(GlgObject viewport)
Windows only: Sets a drawing to be used by the GLG Custom Control.
void GlgDropObject(GlgObject object)
Decrements an object's reference count.

Alternatively, GlgSetWindowViewport may be used to assign the control's drawing after the control has been created instead of using GlgSetDefaultViewport before a call to CreateWindow.

The examples_c_cpp\animation\GlgAnimationW.c file in the GLG installation directory on Windows provides an example of using the control in a Windows application.

Include file: GlgApi.h

Functions

GlgLong CALLBACK GlgControlWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 Windows only: Passes messages to the GLG Custom Control. More...
 
GlgObject GlgGetWindowViewport (HWND window)
 Windows only: Returns a viewport object used by the GLG Custom Control. More...
 
void GlgSetDefaultViewport (GlgObject viewport)
 Windows only: Sets a drawing to be used by the GLG Custom Control. More...
 
void GlgSetWindowViewport (HWND window, GlgObject viewport)
 Windows only: Sets or replaces the viewport of the GLG Custom Control after its window has been created. More...
 

Function Documentation

◆ GlgControlWindowProc()

GlgLong CALLBACK GlgControlWindowProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Windows only: Passes messages to the GLG Custom Control.

This function is used by the window procedure of the control's parent window to pass messages to the control.

The examples_c_cpp\animation\GlgAnimationW.c file in the GLG installation directory on Windows provides an example of using this function.

Parameters
hwndThe window ID of the GLG Control.
msgThe message to be passed.
wParamThe message parameter.
lParamThe message parameter.
Returns
The result of the message processing, depends on the message sent, see Win32 API WINPROC.

◆ GlgGetWindowViewport()

GlgObject GlgGetWindowViewport ( HWND  window)

Windows only: Returns a viewport object used by the GLG Custom Control.

Parameters
windowA window handle of the GLG Custom Control.
Returns
The viewport object used by the GLG Custom Control, or NULL if a window other than the GLG Custom Control is passed as the window parameter.

◆ GlgSetDefaultViewport()

void GlgSetDefaultViewport ( GlgObject  viewport)

Windows only: Sets a drawing to be used by the GLG Custom Control.

Parameters
viewportSpecifies a viewport object containing a drawing to be displayed in the GLG Custom Control.

The function is used to pass the viewport to the CreateWindow function that creates the custom control. The viewport will be assigned to the custom control created by the next call to CreateWindow after GlgSetDefaultViewport is invoked.

Alternatively, GlgSetWindowViewport may be used to assign the control's drawing after the control has been created instead of using GlgSetDefaultViewport before a call to CreateWindow.

Since every custom control needs its own copy of the viewport, a viewport instance may be used to create only one GLG Custom Control. To create several custom controls with the same drawing, load a new instance of the drawing for each control or use GlgCopyObject to create copies of the viewport, then select them using GlgSetDefaultViewport before creating each control or widget. This function references the viewport object using GlgReferenceObject.

The examples_c_cpp\animation\GlgAnimationW.c file in the GLG installation directory on Windows provides an example of using this function.

◆ GlgSetWindowViewport()

void GlgSetWindowViewport ( HWND  window,
GlgObject  viewport 
)

Windows only: Sets or replaces the viewport of the GLG Custom Control after its window has been created.

Parameters
windowThe window handle of the GLG Custom Control.
viewportThe viewport to be used as the control's drawing.

Each custom control has to have its own instance of the viewport. To display the same drawing in several custom controls, load a new instance of the drawing for each control or use GlgCopyObject to create copies of the viewport. This function references the viewport object using GlgReferenceObject.