The Labeled Set

Assume that you have a BYTE field that could be a distinct set of values; for example, Application_Error can have the values of 0=No Error, 1=System Error, 2=Application Error, 3=User Error, and 5=Critical Error. (Note that there is no 4.) You can use a Labeled Set to describe this field.

First, define the SET for the property:

// APPLICATION_ERROR  labeled set
LABELED_BYTE APPLICATIONError[] =
{  
    0x00,  "No Error",    
    0x01,  "System Error",    
    0x02,  "Application Error",    
    0x03,  "User Error",    
    0x05,  "Critical Error",    
};

SET APPLICATIONErrorSet = {sizeof(APPLICATIONError)/sizeof(LABELED_BYTE),  
                   APPLICATIONError};
 

The SET type is defined in BHTYPES.H.

Next, define the property: (Note that this is a piece of a larger property table.)

PROPERTYINFO property_table[] =
{
...
// PROP_APPLICATIONERROR
    {      0,0,            // handle, label
    "Error",            // property name
    "Specifies the type of APPLICATION Error",    //  status bar message    
    PROP_TYPE_BYTE,        // prop type
    PROP_QUAL_LABELED_SET,    // qualifier
    &ApplicationErrorSet,        //  address of set structure
    64,                //  max string size of display text
    FormatPropertyInstance },        //  instance data
...
};
 

The instance data is being used by this parser to store the address of the formatting routine. At FormatProperties time, this parser simply jumps to the address stored in the instance data.

Next, at attach time, the property instance is added:

// Application Error
    AttachPropertyInstance( hFrame,  // handle to frame
        PropertyTable[PROP_APPLICATIONERROR].hProperty,  // handle of property
        sizeof(MyApplicationStruct->Error),  // size of data instance
        &MyApplicationStruct->Error,  // pointer to instance in frame
        ApplicationFrame,    // Help ID
        3,        // level
        0);        // Error
 

Many formatting routines are already provided to the parser writer in a library. Look at PARSER.H and OLDPLIB.H in the \MSSDK\INCLUDE subdirectory of the Platform SDK CD-ROM for the names and functions of the formatting routines.