⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resdiag.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if( !error ) {
        error = ResPadDWord( handle );
    }
    */

    /* If the font was set, write the font information */
    if( !error && (head->Style & DS_SETFONT) ) {
        error = ResReadUint16( &tmp16, handle );
        head->PointSize = tmp16;
        if( !error ) {
            error = ResReadUint16( &(exhead->FontWeight), handle );
        }
        if( !error ) {
            error = ResReadUint8( &(exhead->FontItalic), handle );
        }
        if( !error ) {
            error = ResReadUint8( &(exhead->FontExtra), handle );
        }
        if( !error ) {
            head->FontName = ResRead32String( handle, NULL );
            error = (head->FontName == NULL);
        }
        if( !error ) {
            error = ResPadDWord( handle );
        }
    }

    return( error );
}

extern int ResWriteDialogBoxControl( DialogBoxControl * control,
                WResFileID handle )
/**************************************************************/
{
    int         error;
    int         numwrote;
    int         fixedbytes;
    uint_8      tmp8;

    /* write the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */
    fixedbytes = offsetof( DialogBoxControl, ClassID );
    numwrote = WRESWRITE( handle, control, fixedbytes );
    error = (numwrote != fixedbytes);
    if( error ) {
        WRES_ERROR( WRS_WRITE_FAILED );
    }

    /* if the ClassID is one of the predefined ones write it out as a byte */
    /* otherwise it is a string */
    if (!error) {
        if (control->ClassID->Class & 0x80) {
            error = ResWriteUint8( &(control->ClassID->Class), handle );
        } else {
            error = ResWriteString( control->ClassID->ClassName, FALSE, handle);
        }
    }

    if (!error) {
        error = ResWriteNameOrOrdinal( control->Text, FALSE, handle );
    }
    if (!error) {
        tmp8 = control->ExtraBytes;
        error = ResWriteUint8( &tmp8, handle );
    }

    return( error );
}

extern int ResWriteDialogBoxControl32( DialogBoxControl32 * control,
                WResFileID handle )
/******************************************************************/
{
    int     error;
    int     numwrote;
    int     fixedbytes;

    /* write the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */

    fixedbytes = offsetof( DialogBoxControl32, ClassID );
    numwrote = WRESWRITE( handle, control, fixedbytes );
    error = (numwrote != fixedbytes);
    if( error ) {
        WRES_ERROR( WRS_WRITE_FAILED );
    }
    if( !error ) {
        error = ResWriteDialogControlCommon32( control->ClassID,
                                control->Text, control->ExtraBytes, handle );
    }

    return( error );
}

extern int ResWriteDialogExControl32( DialogBoxExControl32 *control,
                                      WResFileID handle )
/**************************************************************************/
{
    int      error;
    int      numwrote;
    int      fixedbytes;

    /* write the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */

    fixedbytes = offsetof( DialogBoxExControl32, ClassID );
    numwrote = WRESWRITE( handle, control, fixedbytes );
    error = (numwrote != fixedbytes);
    if( error ) {
        WRES_ERROR( WRS_WRITE_FAILED );
    } else {
        error = ResWriteDialogControlCommon32( control->ClassID,
                                control->Text, control->ExtraBytes, handle );
    }

    return( error );
}

static int ResWriteDialogControlCommon32( ControlClass *class_id,
                        ResNameOrOrdinal *text, uint_16 extra_bytes,
                        WResFileID handle )
/**********************************************************************/
{
    int       error;
    uint_16   class_num;

    /* if the ClassID is one of the predefined ones write it out as a byte */
    /* otherwise it is a string */
    if( class_id->Class & 0x80) {
        /*the class number is prefixed by 0xFFFF to distinguish it
         * from a string */
        class_num = 0xFFFF;
        error = ResWriteUint16( &class_num, handle );
        if( !error ) {
            class_num =  class_id->Class;
            error = ResWriteUint16( &class_num, handle );
        }
    } else {
        error = ResWriteString( class_id->ClassName, TRUE, handle );
    }
    if(!error) {
        error = ResWriteNameOrOrdinal( text, TRUE, handle );
    }

    if(!error) {
        error = ResWriteUint16( &extra_bytes, handle );
    }

    return( error );
}

static ControlClass * ReadControlClass( WResFileID handle )
/*********************************************************/
{
    ControlClass *  newclass;
    uint_8          class;
    int             error;
    int             stringlen;
    char *          restofstring;

    restofstring = NULL;

    /* read in the first byte */
    error = ResReadUint8( &(class), handle );
    if (!error) {
        if (class & 0x80 || class == '\0') {
            stringlen = 0;
        } else {
            restofstring = ResReadString( handle, &stringlen );
            stringlen++;    /* for the '\0' */
            error = (restofstring == NULL);
        }
    }

    /* allocate memory for the new class */
    if (error) {
        newclass = NULL;
    } else {
        newclass = WRESALLOC( sizeof(ControlClass) + stringlen );
        if( newclass == NULL ) {
            error = TRUE;
            WRES_ERROR( WRS_MALLOC_FAILED );
        }
    }

    /* copy the class or string into the correct place */
    if (!error) {
        newclass->Class = class;
        if (stringlen > 0) {
            memcpy( &(newclass->ClassName[1]), restofstring, stringlen );
        }
    }

    if (restofstring != NULL) {
        WRESFREE( restofstring );
    }

    return( newclass );
}

static ControlClass * Read32ControlClass( WResFileID handle )
/***********************************************************/
{
    ControlClass *  newclass;
    uint_16         flags;
    uint_16         class;
    int             error;
    int             stringlen;
    char *          restofstring;

    restofstring = NULL;

    /* read in the first word */
    error = ResReadUint16( &flags, handle );
    if( !error ) {
        if( flags == 0xffff ) {
            stringlen = 0;
            error = ResReadUint16( &class, handle );
        } else {
            restofstring = ResRead32String( handle, &stringlen );
            stringlen++;    /* for the '\0' */
            error = (restofstring == NULL);
        }
    }

    /* allocate memory for the new class */
    if( error ) {
        newclass = NULL;
    } else {
        newclass = WRESALLOC( sizeof(ControlClass) + stringlen );
        if( newclass == NULL ) {
            error = TRUE;
            WRES_ERROR( WRS_MALLOC_FAILED );
        }
    }

    /* copy the class or string into the correct place */
    if( !error ) {
        if( flags == 0xffff ) {
            newclass->Class = class;
        } else {
            newclass->ClassName[0] = (char)( flags & 0x00ff );
            memcpy( &(newclass->ClassName[1]), restofstring, stringlen );
        }
    }

    if (restofstring != NULL) {
        WRESFREE( restofstring );
    }

    return( newclass );
}

extern int ResReadDialogBoxControl( DialogBoxControl * control,
                WResFileID handle )
/**************************************************************/
{
    int         error;
    int         numread;
    int         fixedbytes;
    uint_8      tmp8;

    /* read the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */
    fixedbytes = offsetof( DialogBoxControl, ClassID );
    numread = WRESREAD( handle, control, fixedbytes );
    error = (numread != fixedbytes);
    if( error ) {
        WRES_ERROR( numread == -1 ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
    }

    if (!error) {
        control->ClassID = ReadControlClass( handle );
        error = (control->ClassID == NULL);
    }

    if (!error) {
        control->Text = ResReadNameOrOrdinal( handle );
    }
    if (!error) {
        error = ResReadUint8( &tmp8, handle );
        control->ExtraBytes = tmp8;
    }

    return( error );
}

extern int ResReadDialogBoxControl32( DialogBoxControl32 * control,
                WResFileID handle )
/**************************************************************/
{
    int         error;
    int         numread;
    int         fixedbytes;
    uint_16     tmp16;

    error = ResPadDWord( handle );

    /* read the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */
    if( !error ) {
        fixedbytes = offsetof( DialogBoxControl32, ClassID );
        numread = WRESREAD( handle, control, fixedbytes );
        error = (numread != fixedbytes);
        if( error ) {
            WRES_ERROR( numread == -1 ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
        }
    }

    if (!error) {
        control->ClassID = Read32ControlClass( handle );
        error = (control->ClassID == NULL);
    }

    if (!error) {
        control->Text = ResRead32NameOrOrdinal( handle );
    }
    if (!error) {
        error = ResReadUint16( &tmp16, handle );
        control->ExtraBytes = tmp16;
    }

    return( error );
}

extern int ResReadDialogExControl32( DialogBoxExControl32 * control,
                WResFileID handle )
/**************************************************************/
{
    int     error;
    int     numread;
    int     fixedbytes;

    error = ResPadDWord( handle );

    /* read the fixed part of the structure */
    /* the structure is fixed up to, but not including, ClassID */
    if( !error ) {
        fixedbytes = offsetof( DialogBoxExControl32, ClassID );
        numread = WRESREAD( handle, control, fixedbytes );
        error = (numread != fixedbytes);
        if( error ) {
            WRES_ERROR( numread == -1 ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
        }
    }

    if (!error) {
        control->ClassID = Read32ControlClass( handle );
        error = (control->ClassID == NULL);
    }

    if (!error) {
        control->Text = ResRead32NameOrOrdinal( handle );
    }
    if (!error) {
        error = ResReadUint16( &(control->ExtraBytes), handle );
    }

    return( error );
}

extern ControlClass * ResNameOrOrdToControlClass( const ResNameOrOrdinal * name)
/******************************************************************************/
{
    int             stringlen;
    ControlClass *  class;

    if (name->ord.fFlag == 0xff) {
        class = ResNumToControlClass( name->ord.wOrdinalID );
    } else {
        if (stricmp( name->name, "button" ) == 0) {
            class = ResNumToControlClass( CLASS_BUTTON );
        } else if (stricmp( name->name, "edit" ) == 0) {
            class = ResNumToControlClass( CLASS_EDIT );
        } else if (stricmp( name->name, "static" ) == 0) {
            class = ResNumToControlClass( CLASS_STATIC );
        } else if (stricmp( name->name, "listbox" ) == 0) {
            class = ResNumToControlClass( CLASS_LISTBOX );
        } else if (stricmp( name->name, "scrollbar" ) == 0) {
            class = ResNumToControlClass( CLASS_SCROLLBAR );
        } else if (stricmp( name->name, "combobox" ) == 0) {
            class = ResNumToControlClass( CLASS_COMBOBOX );
        } else {
            /* space for the '\0' is reserve in the ControlClass structure */
            stringlen = strlen( name->name );
            class = WRESALLOC( sizeof(ControlClass) + stringlen );
            if( class == NULL ) {
                WRES_ERROR( WRS_MALLOC_FAILED );
            } else {
                /* +1 to copy the '\0' */
                memcpy( &(class->ClassName), name->name, stringlen + 1 );
            }
        }
    }
    return( class );
}

extern ControlClass * ResNumToControlClass( uint_16 classnum )
/************************************************************/
{
    ControlClass *  class;

    if (classnum & 0x80) {
        class = WRESALLOC( sizeof(ControlClass) );
        if( class == NULL ) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            class->Class = classnum;
        }
    } else {
        class = WRESALLOC( sizeof(ControlClass) + 1 );
        if( class == NULL ) {
            WRES_ERROR( WRS_MALLOC_FAILED );
        } else {
            class->ClassName[0] = classnum;
            class->ClassName[1] = '\0';
        }
    }
    return( class );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -