Various ways to display multiple photographs: on a Fox form


My prior 2 posts show how to display multiple photos on a VB.Net form, first using the PictureBox control, the second drawing to the form directly. Below is some code to display multiple photos on a Fox form using an array of Fox Image controls. These controls are windowless: you can use Spy++ to verify.


It gives each image a name in the form of “imxxyy”, like “im0101” and “im0912”.


 


For another sample of an array of controls, see the Fox version of the Minesweeper game (Tools->Task Pane->MineSweeper). The source code can be found in Tools\xsource\xsource.zip, VFPSource\TaskPane\PaneCache\Microsoft.minesweeper\mines.prg


 


#define CWIDTH 2


PUBLIC ox


ox=CREATEOBJECT(“MyForm”)


ox.Show()


 


DEFINE CLASS MyForm AS Form


          Allowoutput=.f.


          xPix=12


          yPix=9


          picwidth=160  && default thumbnail dim


          picheight=120


          width=1024


          height=768


 


          PROCEDURE init


                   USE d:\pictures\pixthumb


                   this.picwidth = this.Width / this.xpix


                   this.picheight = this.Height / this.ypix


                   this.DoArray()


          PROCEDURE keypress(nKeyCode, nShiftAltCtrl)


                   this.DoArray           


          PROCEDURE DoArray


                   local xx,yy,cname,oi


                   for yy = 1 to thisform.ypix


                             for xx = 1 to thisform.xpix


                                      cname = “im”+padl(yy,CWIDTH,‘0’)+padl(xx,CWIDTH,‘0’)


                                      cstr=“thisform.”+cname


                                      IF VARTYPE(&cstr) != ‘O’               && If it hasn’t been added yet


                                                thisform.AddObject(cname,“myimage”)


                                                oi = EVALUATE(“THISFORM.”+CNAME)


                                                oi.height = thisform.picheight


                                                oi.width = thisform.picwidth


                                                oi.top = 20 + oi.height * (yy – 1)


                                                oi.left = (xx – 1) * oi.width


                                                oi.visible=1


                                      ELSE


                                                oi = EVALUATE(“THISFORM.”+CNAME)


                                      ENDIF


                                      oi.pictureval=thumb


                                      skip


                             ENDFOR


                   ENDFOR


ENDDEFINE


DEFINE CLASS MyImage as Image


          * Add your own event handlers,etc.


ENDDEFINE


 


 

Comments (3)

  1. I encountered a "variable not found" error at the line "oi.pictureval=thumb".

    Prior to running the example provided, I created a table with a general field and an embedded jpg file, like this:

    CREATE TABLE junk (junk G)

    m.x = ADIR(aPic,"*.jpg")

    m.y = 1

    FOR m.y = 1 TO m.x

    APPEND BLANK

    APPEND GENERAL junk FROM (aPic(m.y,1))

    ENDFOR

    I had remarked the line "USE d:picturespixthumb" and stated "SELECT junk" instead (junk was the selected alias()).

  2. Calvin_Hsia says:

    Ken: please look at the link in the prior post on how to create the table of thumbnails. They are not in a general field. The MakeThumbDBF code creates the thumb as a blob.

  3. Thank You Calvin!!!!

    The display of result/thumbs takes place at a lightning speed!!  What can’t VFP do?!?

    For those following the thread, this is what I did to make it work (in a .prg):

    CREATE CURSOR MyPix (Fullname C(70), Rotate N(3,0))

    m.xPics = ADIR(aPic,"C:my path*.JPG")

    FOR m.xLoop = 1 TO m.xPics

    INSERT INTO MyPix (Fullname) VALUES(aPic(m.xLoop,1))

    ENDFOR

    SELECT 0

    =MakeThumbDbf()

    * The code of MakeThumbDbf() was copied/inserted from this Blog’s July 20, 2005 post: ( http://blogs.msdn.com/calvin_hsia/archive/2005/07/20/440822.aspx ).  It requires minor editing of FilePaths in order to work.