IF VERSION(2) > 0 && AND llDevelopment *JCJB* 09/14/2005 - In Development, (re)create the PNGs.txt file. 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 PNGs in the project. FOR lnX = 1 TO _VFP.ActiveProject.Files.Count IF LOWER(RIGHT(_VFP.ActiveProject.Files(lnX).Name, 4)) == '.png' 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, 'PNGs.txt') *JCJB* 09/14/2005 - Turn Safety back on if it was on. IF llSafety SET SAFETY ON ENDIF *JCJB* 09/14/2005 - Add the PNGs file to the project. _VFP.ActiveProject.Files.Add('PNGs.txt') CATCH ENDTRY ENDIFHere are the load/unload functions:
FUNCTION loadImages() as Collection 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 PNGs exists. IF FILE('PNGs.txt') *JCJB* 09/14/2005 - Clear Resources to free any cached PNG images. CLEAR RESOURCES *JCJB* 09/14/2005 - Create a collection to hold PNG images. loImages = NEWOBJECT('Collection') *JCJB* 09/14/2005 - Iterate the file names in PNGs.txt *JCJB* 09/14/2005 - For each file, add an Image object to the collection. FOR lnX = 1 TO ALINES(laImages, FILETOSTR('PNGs.txt'), 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 unloadImages(toImages as Collection) *JCJB* 09/14/2005 - See if an Image Collection was passed. IF VARTYPE(toImages) == 'O' AND LOWER(toImages.BaseClass) == 'collection' *JCJB* 09/14/2005 - Release all of the Image objects. DO WHILE toImages.Count > 0 toImages.Remove(1) ENDDO ENDIF ENDFUNCAnd here is how it's called:
*JCJB* 09/14/2005 - Create a collection containing the project's PNG files. loImages = loadImages() * Here is where your application loop goes. *JCJB* 09/14/2005 - Release the collection since the app is done. unloadImages(loImages)HTH,
>>* Fix Image Transparency >>* VFP/GDI+ has a bug where image transparency is not respected on buttons >>* The solution is to load the picture in an image control first >>* This program clears the image from cache and reloads it in an image control >>Lparameters loControl as CommandButton >>Local lcPicture, loImage as Image >> >>* Only applies to formats that support transparency >>lcPicture = loControl.Picture >>If Empty(lcPicture) or !InList(Upper(JustExt(lcPicture)),"JPG","PNG","GIF") >> Return >>EndIf >> >>* Clear image from cache >>loControl.Picture = "" >>Clear Resources (lcPicture) >> >>* Reload picture in Image control >>loImage = CreateObject("Image") >>loImage.Picture = lcPicture >> >>* Reset Picture on control >>loControl.Picture = lcPicture >>>>