Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Animated cursor generator

Usefull Functions & Procedures

Animated cursor generator

by  vgulielmus  Posted    (Edited  )
ico2ani is a function that creates ANI files (animated cursors) from ICO or CUR files
Has three parameters:
- lcAni (in) string, Name of the resulted (ANI) file
- laIcons (in) array passed by reference, array containing fully qualified source files (icons or cursors)
- lnDelay (in, optional) integer, the time in 1/60 seconds each image will be displayed
- laSeq (in, optional) 2 dimensional array of integers
column 1: the order in which frames are displayed (first frame is frame number 0)​
column 2: time in 1/60 sec each step is displayed (speed of animation)​

The function creates the RIFF (ANI) file from the ICO / CUR files enlisted in laIcons

Next is the function, along with a test code.

[code Foxpro]* Code for testing purpose
CLEAR RESOURCES
CLEAR ALL
LOCAL laIcons[8],laIcons2[4]
SET SAFETY OFF

* create an animated cursor from 8 ICONS and set this to the form
laIcons[1] = HOME(4)+"Icons\Elements\MOON01.ICO"
laIcons[2] = HOME(4)+"Icons\Elements\MOON02.ICO"
laIcons[3] = HOME(4)+"Icons\Elements\MOON03.ICO"
laIcons[4] = HOME(4)+"Icons\Elements\MOON04.ICO"
laIcons[5] = HOME(4)+"Icons\Elements\MOON05.ICO"
laIcons[6] = HOME(4)+"Icons\Elements\MOON06.ICO"
laIcons[7] = HOME(4)+"Icons\Elements\MOON07.ICO"
laIcons[8] = HOME(4)+"Icons\Elements\MOON08.ICO"

lcAni = ico2ani("mm.ani",@laIcons,15)

* Create another animated cursor from 4 static CURSORS and set this to the optiongroup
laIcons2[1] = HOME(4)+"Cursors\H_WE.CUR"
laIcons2[2] = HOME(4)+"Cursors\H_NW.CUR"
laIcons2[3] = HOME(4)+"Cursors\H_NS.CUR"
laIcons2[4] = HOME(4)+"Cursors\H_NW.CUR"

lcAni = ico2ani("hh.ani",@laIcons2,15)

* Create the demo form with an optiongroup
PUBLIC ofrm
ofrm = CREATEOBJECT("form")

ofrm.MousePointer = 99
ofrm.MouseIcon = "mm.ani"

ofrm.addobject("optiongroup1","optiongroup")
ofrm.optiongroup1.buttoncount = 3
ofrm.optiongroup1.autosize = .t.
ofrm.optiongroup1.visible = .T.
ofrm.optiongroup1.MousePointer = 99
ofrm.optiongroup1.MouseIcon = "hh.ani"
ofrm.optiongroup1.setall("MousePointer", 99)
ofrm.optiongroup1.setall("MouseIcon", "hh.ani")

ofrm.show()


FUNCTION ico2ani
*****************************************************************
* Convert Icons (ICO) and cursor (CUR) to animated cursor (ANI) *
*****************************************************************
* Parameters
* - lcAni String Name of the resulted file
* - laIcons array (referrence) array containing fully qualified source files (icons or cursors)
* - lnDelay integer the time in 1/60 sec each image is displayed
* - laSeq array (refference) 2 dimensional array of integers containing :
* - column 1: the order in which frames are displayed (first frame is frame number 0)
* - column 2: time in 1/60 sec each step is displayed (speed of animation)
******************************************************************
LPARAMETERS lcAni,laIcons,lnDelay,laSeq
LOCAL lcIco[ALEN(m.laIcons)], lnLen[ALEN(m.laIcons)], lnLenIco, lnSteps, lcSeq, lcRate, lnLenSeq, lnLenRate, lnbfAttr
IF PCOUNT() < 2
RETURN
ENDIF
IF PCOUNT() = 2
lnDelay = 10
ENDIF
STORE 0 TO lnLenSeq, lnLenRate
STORE '' TO lcRate, lcSeq
lnbfAttr = 1
IF PCOUNT() < 4
lnSteps = ALEN(laIcons,1)
ELSE
lnSteps = ALEN(laSeq,1)
lnbfAttr = 3
FOR lni = 1 TO ALEN(laSeq,1)
IF TYPE("m.laSeq[1,1]") = "N"
lcSeq = m.lcSeq + BINTOC(m.laSeq[m.lni,1], "4RS")
ENDIF
IF TYPE("m.laSeq[1,2]") = "N"
lcRate = m.lcRate + BINTOC(m.laSeq[m.lni,2], "4RS")
ENDIF
NEXT
IF !EMPTY(m.lcRate)
lcRate = "rate" + BINTOC(LEN(m.lcRate), "4RS") + m.lcRate
ENDIF
IF !EMPTY(m.lcSeq)
lcSeq = "seq " + BINTOC(LEN(m.lcSeq), "4RS") + m.lcSeq
ENDIF
lnLenSeq = LEN(m.lcSeq)
lnLenRate = LEN(m.lcRate)
ENDIF

lnLenIco = 0
FOR lni = 1 TO ALEN(m.laIcons)
lcIco[m.lni] = FILETOSTR(m.laIcons[m.lni])
lnLen[m.lni] = LEN(m.lcIco[m.lni])
lnLenIco = m.lnLenIco + 8 + lnLen[m.lni]
NEXT

lcResult = "RIFF" + BINTOC(12 + 36 + 8 + 4 + m.lnLenIco + m.lnLenSeq + m.lnLenRate, "4RS")

lcResult = m.lcResult + "ACONanih" + BINTOC(36, "4RS") + BINTOC(36, "4RS") + BINTOC(ALEN(m.laIcons,1), "4RS") + BINTOC(m.lnSteps, "4RS") + ;
REPLICATE(CHR(0),16) + BINTOC(m.lnDelay, "4RS") + BINTOC(m.lnbfAttr, "4RS") + m.lcSeq + m.lcRate
lcResult = m.lcResult + "LIST" + BINTOC(4 + m.lnLenIco, "4RS")
lcResult = m.lcResult + "fram"
FOR lni = 1 TO ALEN(m.laIcons)
lcResult = m.lcResult + "icon" + BINTOC(m.lnLen[m.lni], "4RS") + m.lcIco[m.lni]
NEXT


STRTOFILE(m.lcResult, FORCEEXT(m.lcAni,"ani"))
RETURN FORCEEXT(m.lcAni,"ani")[/code]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top