Sorry, wie komme ich auf "Pushbutton"?
So sollte es eigentlich funktionieren:
Code: Alles auswählen
oBmp := XbpPushButton():New(wDlg,, {20,20},{60,60}):Create()
xResource := LoadResource(123,,"GIF")
If empty( xResource ) )
oBmp:setBuffer( xResource, XBPBMP_FORMAT_GIF, 0 )
ELSE
MSGBOX( "Resource not found!" )
ENDIF
....
oBmp:show()
Oder etwas universeller:
Code: Alles auswählen
oBmp := XbpPushButton():New(wDlg,, {20,20},{60,60}):Create()
SetxbbImage( @oBmp, 123, "GIF" ) // GIF
SetxbbImage( @oBmp, 201 ) // BMP
Code: Alles auswählen
Func SetxbpImage(oBmp, xResourceId, cResType , xDLL )
Local nFormat
Local lOk := .F.
cResType := IFF( cResType == NIL, "", cResType)
IF Valtype( xResourceId ) == "C" // Datei auf Festplatte
IF !File( xResourceId)
Msgbox("Error: Imagedatei nicht gefunden:" + xResourceId )
Return ( NIL )
ENDIF
If oBmp:Loadfile( xResourceId )
DO CASE
CASE At( ".BMP", xResourceId ) > 0
nFormat := XBPBMP_FORMAT_WIN3X
CASE At( ".PNG", xResourceId ) > 0
nFormat := XBPBMP_FORMAT_PNG
CASE At( ".JPG", xResourceId ) > 0
nFormat := XBPBMP_FORMAT_JPG
CASE At( ".GIF", xResourceId ) > 0
nFormat := XBPBMP_FORMAT_GIF
otherwise
Msgbox("Error: nicht unterstützes Imageformat:" + xResourceId )
Return ( NIL )
endcase
else
Msgbox("Error: Imagedatei lonnte nicht geladen werden.")
Return ( NIL )
endif
lOk := TRUE
ELSE
IF empty( cResType )
// Standard: BMP-Format
lOK := oBmp:load( xDll, xResourceId )
nFormat := XBPBMP_FORMAT_WIN3X
ELSE
// PNG, GIF, JPG/JPG
xResource := LoadResource( xResourceId, xDll, cResType )
IF ( lOK := ! empty( xResource ) ) // tries Imagetype from imagedata Signature
DO CASE
CASE substr( xResource, 1, 3 ) == "GIF"
nFormat := XBPBMP_FORMAT_GIF
CASE substr( xResource, 2, 3 ) == "PNG"
nFormat := XBPBMP_FORMAT_PNG
CASE substr( xResource, 7, 4 ) == "JFIF" .or. ;
( chr(0xFF) + chr(0xE0) + chr(0) + chr(0x10) + "JFIF" + chr(0)) $ left( xResource, 100 )
nFormat := XBPBMP_FORMAT_JPG
OTHERWISE
// this is an other imagetyp
MsgBox(" falscher Bitmap-Typ?!")
lOK := FALSE
ENDCASE
IF lOK
oBmp:setBuffer( xResource, nFormat, 0 ) // no Compression
ENDIF
else
Msgbox("Kann Resource nicht laden")
ENDIF
ENDIF
ENDIF
IF lOK
oBmp:Cargo := nFormat // store imagetyp-format to ::cargo
// afterwards the type cannot be determined.
IF ( nFormat == XBPBMP_FORMAT_PNG ) .OR. ( nFormat == XBPBMP_FORMAT_GIF ) // set Transparence-color
oBmp:transparentClr := oBmp:getDefaultBGColor()
ENDIF
ENDIF
RETURN ( NIL )