CreateDC

 

Description

 

The CreateDC function creates a device context (DC) for a device using the specified name.

 

C++ Syntax

 

HDC CreateDC(

__in LPCTSTR lpszDriver,

__in LPCTSTR lpszDevice,

__in LPCTSTR lpszOutput,

__in const DEVMODE* lpInitData

);

 

PowerBASIC Syntax

 

FUNCTION CreateDC ( _

BYREF lpszDriver AS ASCIIZ, _

BYREF lpszDevice AS ASCIIZ, _

BYREF lpszOutput AS ASCIIZ, _

BYREF lpInitData AS DEVMODE _

);

 

Unicode version:

 

FUNCTION CreateDCW ( _

BYVAL lpszDriver AS DWORD, _

BYVAL lpszDevice AS DWORD, _

BYVAL lpszOutput AS DWORD, _

BYREF lpInitData AS DEVMODEW _

);

 

Parameters

 

lpszDriver

 

Windows 95/98/Me: The lpszDriver parameter can be NULL, WINSPL16 (a print provider), or (to obtain a display DC) it can be either the null-terminated string DISPLAY or the device name of a specific display device. If lpszDevice specifies a particular device, you must use NULL for lpszDriver.

 

Windows NT 4.0: Pointer to a null-terminated character string that specifies either DISPLAY or the name of a print provider, which is usually WINSPOOL.

 

Windows 2000/XP: Pointer to a null-terminated character string that specifies either DISPLAY or the name of a specific display device or the name of a print provider, which is usually WINSPOOL.

 

lpszDevice

 

[in] Pointer to a null-terminated character string that specifies the name of the specific output device being used, as shown by the Print Manager (for example, Epson FX-80). It is not the printer model name. The lpszDevice parameter must be used.

 

To obtain valid names for displays, call EnumDisplayDevices.

 

If lpszDriver is DISPLAY or the device name of a specific display device, then lpszDevice must be NULL or that same device name. If lpszDevice is NULL, then a DC is created for the primary display device.

 

Windows NT 3.51 and Windows NT 4.0: There is only one (thus the primary) display device. Set lpszDevice to NULL.

 

Windows 2000 and later: If there are multiple monitors on the system, calling CreateDC("DISPLAY", BYVAL %NULL, BYVAL %NULL, BYVAL %NULL) will create a DC covering all the monitors.

 

lpszOutput

 

This parameter is ignored and should be set to NULL. It is provided only for compatibility with 16-bit Windows.

 

lpInitData

 

[in] Pointer to a DEVMODE structure containing device-specific initialization data for the device driver. The DocumentProperties function retrieves this structure filled in for a specified device. The lpInitData parameter must be NULL if the device driver is to use the default initialization (if any) specified by the user.

 

If lpszDriver is DISPLAY, then lpInitData must be NULL. The display device's current DEVMODE is used.

 

Return Value

 

If the function succeeds, the return value is the handle to a DC for the specified device.

 

If the function fails, the return value is NULL. The function will return NULL for a DEVMODE structure other than the current DEVMODE.

 

Windows NT/2000/XP: To get extended error information, call GetLastError.

 

Remarks

 

Note that the handle to the DC can only be used by a single thread at any one time.

 

For parameters lpszDriver and lpszDevice, call EnumDisplayDevices to obtain valid names for displays.

 

When you no longer need the DC, call the DeleteDC function.

 

Windows 2000/XP: If lpszDriver or lpszDevice is DISPLAY, the thread that calls CreateDC owns the HDC that is created. When this thread is destroyed, the HDC is no longer valid. Thus, if you create the HDC and pass it to another thread, then exit the first thread, the second thread will not be able to use the HDC.

 

ICM: To enable ICM, set the dmICMMethod member of the DEVMODE structure (pointed to by the pInitData parameter) to the appropriate value.

 

Windows 95/98/Me: CreateDCW is supported by the Microsoft Layer for Unicode.

 

Valid XHTML 1.0 Transitional