用VB5制作家庭影集

2008-04-09 04:42:58来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

你想拥有自己的电子家庭影集吗?其实用VB就能实现。方法如下:

  准备:家庭普通照片经扫描后储存。

  构想:照片一张接一张出现在屏幕中间,出现时的方式采取动态切换,上方一行标题从左向右移过,标题与照片的背景色随机变化。

  关键:调用Bitblt Windows API函数实现照片的动态切换。

  内容:工程由Form1和modlue1构成。

  Form1中的内容如下:

  Const bmpfilemax = 11 ′照片数目常量
  Dim bmpfile(bmpfilemax) As String ′照片的文件组
  Dim drawbmpmode(bmpfilemax) As Integer '照片的切换方式
  Dim bmpnum, movestep, xmax, ymax, endmax, lleft, r, n As Integer ′照片的序号、步进参数等
  Dim kxy As Single ′x、y方向的比例
  Private Sub Exit_Click()
  End
  End Sub
  Private Sub Form_Load()
  Label1.Left = 0
  Label1.Caption = ″Family Album″
  Picture1.AutoSize = True
  Picture1.Visible = False
  bmpfile(0) = App.Path + ″ \son1.jpg″
  bmpfile(1) = App.Path + ″\mom_son1.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 + ″\family.jpg″
  bmpfile(9) = App.Path + ″\fan-yantai.jpg″
  bmpfile(10) = App.Path + ″\yu99yan3.jpg″
  drawbmpmode(bmpnum) = 1 + Int(Rnd() * 4)
  movestep = 0 ′步进参数
  xmax = Form1.ScaleWidth /
  ymax = Form1.ScaleHeight /
  kxy = ymax / xmax
  Picture1.Picture = LoadPicture(bmpfile(bmpnum))
  Timer1.Interval = 30
  End Sub
  Private Sub Timer1_Timer()
  m = Form1.ScaleWidth / - Picture1.Width / ′照片显示结束时的X方向居中定位
  n = Form1.ScaleHeight / - Picture1.Height / ′照片显示结束时的Y方向居中定位
  hDestDC = Form1.hDC
  hSrcDC = Picture1.hDC
  drawflag = drawbmpmode(bmpnum) ′照片显示时的切换方式
  Select Case drawflag
  Case 1 ′切换方式为从左右向中间进行
  Timer1.Interval = 30
  endmax = xmax
  w = movestep
  h = Picture1.Height
  i = BitBlt(hDestDC, 0 + m, 0 + n, w, h, hSrcDC, 0, 0, SRCCOPY)
  X1 = Picture1.Width - movestep
  i = BitBlt(hDestDC, X1 + m, 0 + n, w, h, hSrcDC, X1, 0, SRCCOPY)
  Case 2 ′切换方式为从中间向四周扩散进行
  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)
  Case 3 ′切换方式为栅栏翻转进行
  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
  Case 4 ′切换方式为从左向右进行
  Timer1.Interval = 30
  endmax = xmax
  w = movestep * 2
  h = Form1.ScaleHeight
  i = BitBlt(hDestDC, 0 + m, 0 + n, w, h, hSrcDC, X1, Y1, SRCCOPY)
  End Select
  Form1.Refresh
  movestep = movestep + 4
  Label1.Left = movestep
  If movestep > endmax + 60 Then
  bmpnum = bmpnum + 1
  If bmpnum >= bmpfilemax Then
  bmpnum = 0
  End If
  Cls
  movestep = 0
  Picture1.Picture = LoadPicture(bmpfile(bmpnum))
  drawbmpmode(bmpnum) = 1 + Int(Rnd() * 4)
  BackColor = QBColor(Rnd * 15)
  Label1.ForeColor = QBColor(Rnd * 10)
  If BackColor = Label1.ForeColor Then
  Label1.ForeColor = vbBlack
  End If
  Label1.Caption = ″Family Album″
  Label1.Top = Picture1.Top
  End If
  End Sub
  Modlue1中的内容如下:
  Option Explicit
  Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
  Declare Function BitBlt Lib ″gdi32″ (ByVal hDestDC As _
  Long, ByVal x As Long, ByVal Y As Long, ByVal nWidth _
  As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
  ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:VB制作图片浏览器

下一篇:用VB编写'投注'程序

热门词条
热门标签