int EnumObjects(hdc, fnObjectType, goenmprc, lParam) | |||||
HDC hdc; | /* handle of device context | */ | |||
int fnObjectType; | /* type of object, */ | ||||
GOBJENUMPROC goenmprc; | /* address of callback function | */ | |||
LPARAM lParam; | /* application-defined data | */ |
The EnumObjects function enumerates the pens and brushes available in the given device context. For each object of a given type, the callback function is called with the information for that object. EnumObjects continues until there are no more objects or the callback function returns zero.
hdc
Identifies the device context.
fnObjectType
Specifies the object type. This parameter can be one of the following values:
Value | Meaning |
OBJ_BRUSH | Specifies a brush. |
OBJ_PEN | Specifies a pen. |
goenmprc
Specifies the procedure-instance address of the application-supplied callback function. The address must be created by the MakeProcInstance function. For more information about the callback function, see the description of the EnumObjectsProc callback function.
lParam
Specifies a 32-bit application-defined value that is passed to the callback function.
The return value specifies the last value returned by the callback function and is defined by the user.
The following example retrieves the number of horizontally hatched brushes and fills LOGBRUSH structures with information about each of them:
#define MAXBRUSHES 50
GOBJENUMPROC lpProcCallback;
HGLOBAL hglbl;
LPBYTE lpbCountBrush;
lpProcCallback = (GOBJENUMPROC) MakeProcInstance(
(FARPROC) Callback, hinst);
hglbl = GlobalAlloc(GMEM_FIXED, sizeof(LOGBRUSH)
* MAXBRUSHES);
lpbCountBrush = (LPBYTE) GlobalLock(hglbl);
*lpbCountBrush = 0;
EnumObjects(hdc, OBJ_BRUSH, lpProcCallback,
(LPARAM) lpbCountBrush);
FreeProcInstance((FARPROC) lpProcCallback);
int FAR PASCAL Callback(LPLOGBRUSH lpLogBrush, LPBYTE pbData)
{
/*
* The pbData parameter contains the number of horizontally
* hatched brushes; the lpDest parameter is set to follow the
* byte reserved for pbData and the LOGBRUSH structures that
* have been filled with brush information.
*/
LPLOGBRUSH lpDest =
(LPLOGBRUSH) (pbData + 1 + (*pbData * sizeof(LOGBRUSH)));
if (lpLogBrush->lbStyle ==
BS_HATCHED && /* if horiz hatch */
lpLogBrush->lbHatch == HS_HORIZONTAL) {
*lpDest++ = *lpLogBrush; /* fills structure with brush info */
(*pbData) ++; /* increments brush count */
if (*pbData >= MAXBRUSHES)
return 0;
}
return 1;
}
EnumObjectsProc, FreeProcInstance, GlobalAlloc, GlobalLock, MakeProcInstance