Jump to content

WinOpenWindowDC

From EDM2
Revision as of 18:47, 14 May 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Opens a device context for a window

Syntax

WinOpenWindowDC(hwnd)

Parameters

hwnd (HWND)
Handle of the window

Returns

hdc (HDC) - returns
Device-context handle.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.

Remarks

hdc is used to associate a presentation space with the window.

Note
The window device context is automatically closed when its associated window is destroyed. It must not be closed with the DevCloseDC call.

The visible region of the device context is updated automatically as windows are rearranged.

Example Code

Declaration:

#define INCL_WINWINDOWMGR /* Or use INCL_WIN, INCL_PM, Also in COMMON section */
#include <os2.h>

HWND    hwnd;  /*  Window handle. */
HDC     hdc;   /*  Device-context handle. */

hdc = WinOpenWindowDC(hwnd);

This example calls WinOpenWindowDC to open a device context for a window, the handle to which is then used to associate a presentation space with the window.

#define INCL_WINWINDOWMGR       /* Window Manager Functions     */
#define INCL_GPICONTROL         /* Gpi Control Functions        */
#include <os2.h>

HWND  hwnd;             /* window handle                        */
HPS    hps;             /* presentation-space handle            */
SIZEL pagesize={0L,0L}; /* Presentation page size               */
HAB   hab;              /* Anchor-block handle                  */
HDC   hdc;              /* device-context handle                */

case WM_CREATE:                    /* Window just created       */

   hdc = WinOpenWindowDC(hwnd);   /* Open window device context */

   hps = GpiCreatePS(hab,               /* Create GPI PS and */
                     hdc,               /* associate with DC */
                     &pagesize,         /* default size */
                     PU_PELS |          /* pixel units */
                     GPIF_LONG |        /* 4-byte coordinates */
                     GPIA_ASSOC);       /* associate with device */

Related Functions