int CALLBACK EnumObjectsProc(lpLogObject, lpData) | |||||
void FAR* lpLogObject; | /* address of object | */ | |||
LPARAM lpData; | /* address of application-defined data | */ |
The EnumObjectsProc function is an application-defined callback function that processes object data from the EnumObjects function.
lpLogObject
Points to a LOGPEN or LOGBRUSH structure that contains information about the attributes of the object.
The LOGPEN structure has the following form:
typedef struct tagLOGPEN { /* lgpn */
UINT lopnStyle;
POINT lopnWidth;
COLORREF lopnColor;
} LOGPEN;
The LOGBRUSH structure has the following form:
typedef struct tagLOGBRUSH { /* lb */
UINT lbStyle;
COLORREF lbColor;
int lbHatch;
} LOGBRUSH;
For a full description of these structures, see the Microsoft Windows Programmer's Reference, Volume 3.
lpData
Points to the application-defined data passed by the EnumObjects function.
This function must return a nonzero value to continue enumeration; to stop enumeration, it must return zero.
An application must register this callback function by passing its address to the EnumObjects function. The EnumObjectsProc function is a placeholder for the application-supplied function name. The actual name must be exported by including it in an EXPORTS statement in the application's module-definition (.DEF) file.
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;
}
EnumObjects, FreeProcInstance, GlobalAlloc, GlobalLock, MakeProcInstance