->設置各控件的屬性如下:
Form1:AutoRedraw:True
ScaleMode:3
Picture1:AutoRedraw:True
ScaleMode:3
Visible:False
2代碼編寫
Modull.bas中的內容(聲明BitBlt函數):
PublicConstSRCCOPY=&HCC0020'(DWORD)dest=source
DeclareFunctionBitBltLib"gdi32"Alias"BitBlt"(ByValhDestDCAsLongByValxAsLongByValyAsLongByValnWidthAsLongByValnHeightAsLongByValhSrcDCAsLongByValxSrcAsLongByValySrcAsLongByValdwRopAsLong)AsLong
這兩句只要從Win32api.txt文件中粘貼即可。
Form1中的代碼:
在Declare中定義全局變量:
Constbmpfilemax=5&總共5個bmp文件
Dimbmpfile(bmpfilemax)AsString&bmp文件的文件名數組
Dimdrawbmpmode(bmpfilemax)AsInteger&各畫顯示時的切換方式
Dimbmpnum,movestep,xmax,ymaxAsInteger
DimkxyAsSingle&x,y二個方向的比例
程序運行時先作初始化工作:
PrivateSubForm-Load()
bmpnum=0&當前文件號=0,第一個文件
bmpfile(0)=App.Path ''mp1.bmp''bmpfile(1)=App.Path ''mp2.bmp''
bmpfile(2)=App.Path ''mp3.bmp''
bmpfile(3)=App.Path ''mp4.bmp''
bmpfile(4)=App.Path ''mp5.bmp''
drawbmpmode(0)=1
drawbmpmode(1)=5
drawbmpmode(2)=3
drawbmpmode(3)=4
drawbmpmode(4)=2
movestep=0&步進參數
xmax=Form.ScaleWidth/2
ymax=Form.ScaleHeight/2
kxy=ymax/xmax
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
Timer1.Interval=30&定時器起動
EndSub
響應鼠標:
PrivateSubForm-Click()
End&當有擊鼠標動作時程序結束
EndSub
切換演示工作主要在定時器中完成:
PrivateSubTimer1-Timer()
hDestDC=Form1.HDC&目標DC
hSrcDC=Picture1.hDC&源DC,畫是從不可見的Picture1中拷貝到窗體
drawflag=drawbmpmode(bmpnum)&當前畫出現的方式
SelectCasedrawflag
Case1&從中間逐步放大
endmax=xmax&用於結束判斷
X1=xmax-movestep
w=movestep*2
Y1=Cint(ymax-movestep*kxy)
h=Cint(2*movestep*kxy)
i=BitBlt(hDestDC,X1,Y1,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case2&從左到右
endmax=xmax
w=movestep*2
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,X1,Y1,SRCCOPY)
Case3'左右向中間
endmax=xmax
w=movestep
h=Form1.ScaleHeight
i=BitBlt(hDestDC,0,0,w,h,hSrcDC,0,0,SRCCOPY)&左面部分
X1=Form1.ScaleWidth-movestep
i=BitBlt(hDestDC,X1,0,w,h,hSrcDC,X1,0,SRCCOPY)&左面部分
Case4'柵條狀
endmax=CInt(2*xmax/10)&共分階10條
tempi=CInt(2*xmax/10)
w=movestep
h=Form1.ScaleHeight
Forij=0To9
i=BitBlt(hDestDC,tempi*ij,0,w,h,hSrcDC,tempi*ij,0,SRCCOPY)
Nextij
Case5'稜形狀
endmax=CInt(2*xmax/10)
tempi=CInt(2*xmax/10)
w=movestep
Forih=0Tow-1
Forik=0To9
Forij=0To9
l=tempi*ik tempi/2
t=tempi*ij tempi/2
i=BitBlt(hDestDC,1-(w-ih),t-ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t-ih,SRCCOPY)
i=BitBlt(hDestDC,1-(w-ih),t ih,(w-ih)*2,1,hSrcDC,1-(w-ih),t ih,SRCCOPY)
Nextij
Nextik
Nextih
EndSelect
Form1.Refresh
movestep=movestep 2&步進增加
Ifmovestep>endmaxThen&若步進夠大,畫面都已顯示,本張畫結束切換
bmpnum=bmpnum 1&進到下一張畫
Ifbmpnum>=bmpfilemaxThen&若5張畫已顯示完則再從第一張開始
bmpnum=0
EndIf
movestep=0
Picture1.Picture=LoadPicture(bmpfile(bmpnum))
EndIf
EndSub->->