| HOWTO: How to Decipher EMR_SELECTOBJECT Records in Enhanced Meta FileID: Q142319 
 | 
The EMR_SELECTOBJECT record in an enhanced metafile can indicate that the object to be selected is a stock object. It does so by setting the high order bit in the handle. This article shows how to decipher those records to get a handle to the stock object.
If an EMR_SELECTOBJECT record is encountered while enumerating the records
in an enhanced metafile, the dParm member of the ENHMETARECORD parameter is
normally an index into the handle table of the object to be selected.
However, if the high order bit of dParm[0] is set, the remaining bits
indicate the index that can be used with GetStockObject() to obtain a handle to the object of interest.
For example, consider the following enumeration callback function:
   int CALLBACK EnumEnhMetafileProc( HDC hDC,
                                  HANDLETABLE *lpHTable,
                                  ENHMETARECORD *lpEMFR,
                                  int nObj, LPARAM lpData )
   {
    DWORD    dwIndex;
    HGDIOBJ  hObj;
    // Which record type is this record?
    switch( lpEMFR->iType )
    {
        case EMR_SELECTOBJECT: // It's a SelectObject() record
            // Is the high order bit set?
            if( lpEMFR->dParm[0] & 0x80000000 )
            {
                // High order bit is set - its a stock object
                // Strip the high bit to get the index
                dwIndex = lpEMFR->dParm[0] & 0x7fffffff;
                // Pass the index to GetStockObject()
                hObj = GetStockObject( dwIndex );
                // Select the object into the DC
                SelectObject( hDC, hObj );
            }
            else
            {
                // High order bit wasn't set - not a stock object
                SelectObject( hDC,
                          lpHTable->objectHandle[lpEMFR->dParm[0]] );
            }
        break;
        default:
            // Process other records
            PlayEnhMetaFileRecord( hDC, lpHTable, lpEMFR, nObj );
        break;
    }
    // Return non-zero to continue enumeration
    return 1;
} Additional query words: Windows 95 4.00 3.50 Enumerate EnumEnhMetaFile EnhMetaFileProc missing EMR_CREATEBRUSHINDIRECT
Keywords          : kbSDKWin32 
Version           : WINDOWS:
Platform          : WINDOWS 
Issue type        : kbhowto Last Reviewed: June 24, 1999