用VB制作家庭影集2010-01-02冯雪榆你想拥有自己的电子家庭影集吗?其实用VB就能实现。方法如下:准备:家庭普通照片经扫描后储存。构想:照片一张接一张出现在屏幕中间,出现时的方式采取动态切换,上方一行标题从左向右移过, 标题与照片的背景色随机变化。关键:调用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( ) End Ene Sub Private Sub Form_Load( ) Labell.Lert=0 Labell.Caption="Family Album" Picturel.AutoSize=True Picturel,Visible=False Bmpfile(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/xmax Picture1.picture=LoadPicture(bmpfile(bmpnum)) Timerl.Interval=30 End Sub Private Sub Timer1_Timer() M=Forml.scaleWidth/_Pic_turel.width/照片显示结束时的X方向居中定位 N=Forml.scaleHeight/_Pic_turel.Height/照片显示结束时的Y方向居中定位 HDestDC=Forml.Hdc HsrcDC=picture1.Hdc Drawflag=drawbmpmode(bmpnum)照片显示时的切换方式 Select Case drawflag Case1 切换方式为从左右向中间进行 Time Interval=30 Endmax=xmax W=movestep H=picture1,Height I=BitBlt(hDestDC,0+m,0+n,w,h,hSrcDC,0,0SRCCORY) X1=Picture,width_movestep I=BitBlt(hDestDC,X1+m,0+n,w,h,hSrcDC,X1,0,SRCCOPY)Case2切换方式为从中间向四周扩散进行Timer1.Interval=30 Endmax=xmax X1=xmax_movestep W=movestep*2 Y1=cint(ymax-movestep*kxy) H=cint(2*movestep) I=BitBlt(hDestDC,X1+m,Y1+n,w,h,hSrcDC,X1,Y1,SRCCOPY) Case3切换方式为栅栏翻转进行 Timer1.Interval=200 Ednmax=Cint(2*xmax/10) Tempi=Cint(2*xmax/10) W=movestep H=Picture1.ScaleHeight For ij=0 TO 9 I=BitBlt(hDestDC,tempi*ij+m,0+n,w,h,hSrcDC,tempi*ij,0,SRCCOPY) Next ij Case4切换方式为从左向右进行 Timer1.Interval=30 Endmax=xmax W=movestep*2 H=Forml.ScaleHeight I=BitBlt(hDestDC,0=m,0+n,w,h,hSrcDC,X1,Y1,SRCCOPY) Ends Select Forml.Refresh Movestep=movestep+4 Labell.left=movestep Ifmovestep>endmax+60Then Bmpnum=bmpnum+1 Ifbmpnum>bmpfilemax then Bmpnum=0 End IF Cls Movestep=0 Picture1.Picture=LoadPic_1+int(Rnd()*4) Backcolor=QBColor(Rnd*15) Labell.ForeClolr=QBColor(Rnd*10) If backcolor=Labell.ForeColor Then Labell.forecolor=vbBlack End if Labell.Caption=family album" Labell.top=picturel.top End if End subModluel中的内容如下:Option explicit Public comst SRCCOPY=&HCC0020(DWORD)dest=source Declare 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