* 30/may/2008 pdv * The images with a transparent color (of type JPG, GIF or PNG) are not * well displayed by buttons. Their transparent color is not transparent. * The solution is to first attach them to an image control. The image * control handles them correctly. Due to VFP's way of handling images in * memory, it will use the correct image as found in memory. * There's no need to refer to the image.picture. The picture property of * the button can still refer to the picture file. * * The functions hereunder are based on the code from Chad Bourque. * See on the UT: Message #1138011 * However, I don't see how his UnloadImages() function adds functionality. * According to me, the image collection will automatically be removed from * memory when the last memory variable that refers to the collection is * released. * Usage: * Call this function in the main program. The call returns a reference to a * created collection of images. Ensure that this collection exists during the * entire session by assigning the returned object reference to a variable. The * collection will be automatically removed when that variable is released. * Example code: #if .f. local loImageCollection loImageCollection = LoadImageCollection() #endif local lcImageTxtFile lcImageTxtFile = 'Images.txt' UpdateTxtFile( m.lcImageTxtFile ) RETURN LoadImages( m.lcImageTxtFile ) FUNCTION loadImages() as Collection lparameter tcImageTxtFile LOCAL ARRAY laImages[1] LOCAL llTalk as Boolean, ; lnX as Integer, ; loImages as Collection *JCJB* 10/06/2005 - Save the current Talk setting and turn Talk off. llTalk = (SET('Talk') == 'ON') SET TALK OFF *JCJB* 09/14/2005 - Initialize the variable to null. loImages = null *JCJB* 09/14/2005 - See if a file containing the names of the images exists. IF FILE( m.tcImageTxtFile ) *JCJB* 09/14/2005 - Clear Resources to free any cached images. CLEAR RESOURCES *JCJB* 09/14/2005 - Create a collection to hold images. loImages = NEWOBJECT('Collection') *JCJB* 09/14/2005 - Iterate the file names in the textfile *JCJB* 09/14/2005 - For each file, add an Image object to the collection. FOR lnX = 1 TO ALINES(laImages, FILETOSTR( m.tcImageTxtFile ), 1) loImages.Add(NEWOBJECT('Image')) loImages[loImages.Count].Picture = laImages[lnX] ENDFOR ENDIF *JCJB* 10/06/2005 - Restore the previous Talk setting. IF llTalk SET TALK ON ENDIF *JCJB* 09/14/2005 - Return the Image collection. RETURN loImages ENDFUNC FUNCTION UpdateTxtFile lparameter tcImageTxtFile IF VERSION(2) > 0 && AND llDevelopment *JCJB* 09/14/2005 - In Development, (re)create the textfile. LOCAL lcFile as String, ; lnX as Integer, ; llSafety as Boolean *JCJB* 09/14/2005 - If this errors (most likely due to the project not *JCJB* 09/14/2005 - being opened), it's no big deal. Ignore the error. TRY lcFile = '' *JCJB* 09/14/2005 - Gather the names of all of the wanted images in the project. * 30/may/2008 pdv Transparency applies to png, jpg and gif. FOR lnX = 1 TO _VFP.ActiveProject.Files.Count IF inlist( LOWER(RIGHT(_VFP.ActiveProject.Files(lnX).Name, 4)), '.png', '.jpg', '.gif' ) lcFile = lcFile + _VFP.ActiveProject.Files(lnX).Name + CHR(13) ENDIF ENDFOR *JCJB* 09/14/2005 - Save the current state of Safety. llSafety = (SET('Safety') == 'ON') *JCJB* 09/14/2005 - Turn Safety off and overwrite the PNGs file. SET SAFETY OFF STRTOFILE(lcFile, m.tcImageTxtFile ) *JCJB* 09/14/2005 - Turn Safety back on if it was on. IF llSafety SET SAFETY ON ENDIF *JCJB* 09/14/2005 - Add the textfile to the project. _VFP.ActiveProject.Files.Add( m.tcImageTxtFile ) CATCH ENDTRY ENDIF RETURN ENDFUNC