你想拥有自己的电子家庭影集吗?其实用VB就能实现。方法如下:
准备:家庭普通照片经扫描后储存。
构想:照片一张接一张出现在屏幕中间,出现时的方式采取动态切换,上方一行标题从左向右移过,标题与照片的背景色随机变化。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)关键:调用Bitblt Windows API函数实现照片的动态切换。
内容:工程由Forml和modluel构成。
FORML中的内容如下:
Comst bmpfilemax=11 照片数目常量Const bmpfile(bmpfilemax)As String照片的文件组Dim brawbmpmode(bmpfilemax)As in-teger 照片的切换方式Dim bmpnum,mouvstep,xmax,ymax,endmax,lleft,r,n ,As Integer 照片的序号,步进参数Dim kxy As Single x y方向的比例Private Sub Exit_Click( )EndEne SubPrivate Sub Form_Load( )Labell.Lert=0Labell.Caption="Family Album"Picturel.AutoSize=TruePicturel,Visible=FalseBmpfile(0)=App,path+" sonl.jpg"Bmpfile(1)=App.Path+" mom_sonl.jpg"Bmpfile(2)=App.Path+" daddy_son.jpg"Bmpfile(3)=App.path+" yu99yantai.jpg"Bmpfile(4)=App.Path+" yu98singap2.jpg"Bmpfile(5)=App.Path+" yu98singapore.jpg"Bmpfile(6)=App.Path+" mom_son2.jpg"Bmpfile(7)=App.Path+" yu99yan2.jpg"Bmpfile(8)=App.Path+" fami_ly.jpg"Bmpfile(9)=App.Path+" fan_yantai.jpg"Bmpfile(10)=App.Path+" yu99yan3.jpg"Drawbmpmode(bmpnum) =1+int (Rnd()*4)Movestep=0 步进参数Xmax=Forml.scaleWidth/Ymax=Forml.scaleHeight/Kxy=ymax/xmaxPicture1.picture=LoadPicture(bmpfile(bmpnum))Timerl.Interval=30End Sub Private Sub Timer1_Timer()M=Forml.scaleWidth/_Pic_turel.width/照片显示结束时的X方向居中定位N=Forml.scaleHeight/_Pic_turel.Height/照片显示结束时的Y方向居中定位HDestDC=Forml.HdcHsrcDC=picture1.HdcDrawflag=drawbmpmode(bmpnum)照片显示时的切换方式Select Case drawflagCase1 切换方式为从左右向中间进行Time Interval=30Endmax=xmaxW=movestepH=picture1,HeightI=BitBlt(hDestDC,0+m,0+n,w,h,hSrcDC,0,0SRCCORY)X1=Picture,width_movestepI=BitBlt(hDestDC,X1+m,0+n,w,h,hSrcDC,X1,0,SRCCOPY)
Case2切换方式为从中间向四周扩散进行
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)
Timer1.Interval=30Endmax=xmaxX1=xmax_movestepW=movestep*2Y1=cint(ymax-movestep*kxy)H=cint(2*movestep)I=BitBlt(hDestDC,X1+m,Y1+n,w,h,hSrcDC,X1,Y1,SRCCOPY)Case3切换方式为栅栏翻转进行Timer1.Interval=200Ednmax=Cint(2*xmax/10)Tempi=Cint(2*xmax/10)W=movestepH=Picture1.ScaleHeightFor ij=0 TO 9I=BitBlt(hDestDC,tempi*ij+m,0+n,w,h,hSrcDC,tempi*ij,0,SRCCOPY)Next ijCase4切换方式为从左向右进行Timer1.Interval=30Endmax=xmaxW=movestep*2H=Forml.ScaleHeightI=BitBlt(hDestDC,0=m,0+n,w,h,hSrcDC,X1,Y1,SRCCOPY)Ends SelectForml.RefreshMovestep=movestep+4Labell.left=movestepIfmovestependmax+60ThenBmpnum=bmpnum+1Ifbmpnumbmpfilemax thenBmpnum=0End IF ClsMovestep=0Picture1.Picture=LoadPic_1+int(Rnd()*4)Backcolor=QBColor(Rnd*15)Labell.ForeClolr=QBColor(Rnd*10)If backcolor=Labell.ForeColor ThenLabell.forecolor=vbBlackEnd ifLabell.Caption=family album"Labell.top=picturel.topEnd if End sub
Modluel中的内容如下:
Option explicitPublic comst SRCCOPY=&HCC0020(DWORD)dest=sourceDeclare Function BitBlt Lib"gdi32"(byval hDestDCAs_Long,byval x as long,byval y as long ,byval n width_Byval xsrc as long,byval ysre as long ,byval dwrop as long)as long