From EDM2
Jump to: navigation, search

This function associates a graphics presentation space with, or dissociates it from, a device context.


GpiAssociate(hps, hdc)


hps (HPS) - input
Presentation-space handle.
hdc (HDC) - input
Device-context handle.
rc (BOOL) - returns
Success indicator.


rc (BOOL) - returns
Success indicator.
  • TRUE - Successful completion
  • FALSE - Error occurred.


Possible returns from WinGetLastError

An invalid presentation-space handle was specified.
An attempt was made to access the presentation space from more than one thread simultaneously.
An attempt was made to destroy a presentation or associate a presentation space that is still associated with a device context.
An attempt was made to associate a presentation space with a device context that was already associated or to destroy a device context that was associated.
An attempt was made to issue a function that is invalid in a micro presentation space.
An invalid device-context handle or (micro presentation space) presentation-space handle was specified.
An attempt was made to create a realizable logical color table on a device driver that does not support this function.
An attempt was made to open or close a segment either directly or during segment drawing, or to issue GpiAssociate while there is an open path bracket.
One of the following has occurred:
  • A segment has been opened, closed, or drawn.
  • GpiAssociate was issued while an area bracket was open.
  • A drawn segment has opened an area bracket and ended without closing it.


Any type of device context may be used.

Subsequent drawing functions direct output to the associated device context.

If a null handle is supplied for the device context, the presentation space is dissociated from its currently-associated device context. An associated presentation space cannot be associated with another device context, and an associated device context cannot be associated with another presentation space.

An error occurs if you try to draw to a presentation space associated with a memory device context that has no bit map selected into it (see GpiSetBitmap).

The processing described for GRES_ATTRS (see GpiResetPS) is performed on the presentation space. Also, bounds data is destroyed, the page viewport is reset to its default value (see GpiCreatePS), and any clip region and path definition are lost. The save/restore presentation-space stack (see GpiSavePS) is purged.

Any palette selected into the presentation space remains selected.

Any dynamic segments left drawn on the device are not subsequently removed by GpiRemoveDynamics.

Example Code

This example releases the current device context and associates a new device context with the presentation space.

#define INCL_GPICONTROL         /* GPI control Functions */
#include <os2.h>

HPS hps;                /* presentation space handle     */
HDC hdcPrinter;         /* device context handle         */

/* release the current device context */
GpiAssociate(hps, NULLHANDLE);
/* associate a printer device context */
GpiAssociate(hps, hdcPrinter);

Related Functions

  • GpiCreatePS
  • GpiDestroyPS
  • GpiQueryDevice
  • GpiQueryPS
  • GpiResetPS
  • GpiRestorePS
  • GpiSavePS
  • GpiSetMarkerSet
  • GpiSetPatternSet
  • GpiSetPS