前几天心血来潮,做了一个屏幕剥落的小效果~拿出来和大家分享,同时也要感谢MySticBoy在API的使用上对我的指导~
首先按照管理,窗体的AutoRedraw为True,BorderStyle为0,ScaleMode为3,另外就是WindowState设为2。然后添加Timer控件命名为tmr,PictureBox命名为picBack,AutoRedraw为True,AutoSize为True,并将它的ScaleMode也设为3。下面写上代码:
Option Explicit
Private 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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Const POINT_NUM = 200
Private Const BACK_COLOR = &HFFFFFF
Private Type POINT
x As Long
y As Long
V As Long
End Type
Private pPoints() As POINT
Private lTop As Long
Private lCountNow As Long
Dim i As Long
Dim j As Long
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then End
End Sub
Private Sub Form_Load()
BitBlt Me.hdc, 0, 0, Screen.Width, Screen.Height, GetDC(GetDesktopWindow()), 0, 0, SRCCOPY
picBack.Picture = Me.Image
Show
picBack.Left = Me.ScaleWidth
ReDim pPoints(POINT_NUM)
lTop = -2
For i = 0 To POINT_NUM
Randomize
pPoints(i).x = Rnd * Me.ScaleWidth
Randomize
pPoints(i).y = Rnd * 50 + lTop
Randomize
pPoints(i).V = Rnd * 50 + 10
picBack.Line (pPoints(i).x, pPoints(i).y)-(pPoints(i).x + 3, pPoints(i).y + 3), vbWhite, BF
Next i
lCountNow = lCountNow + POINT_NUM
tmr.Enabled = True
End Sub
Private Sub tmr_Timer()
For i = 0 To POINT_NUM
BitBlt Me.hdc, pPoints(i).x, pPoints(i).y, 4, 4, picBack.hdc, pPoints(i).x, pPoints(i).y, SRCCOPY
BitBlt Me.hdc, pPoints(i).x, pPoints(i).y + pPoints(i).V, 4, 4, picBack.hdc, pPoints(i).x, pPoints(i).y, SRCCOPY
pPoints(i).y = pPoints(i).y + pPoints(i).V
If pPoints(i).y >= Me.ScaleHeight Then
WrongPoint:
Randomize
pPoints(i).x = Rnd * Me.ScaleWidth
Randomize
pPoints(i).y = Rnd * 50 + lTop
Randomize
pPoints(i).V = Rnd * 50 + 10
picBack.Line (pPoints(i).x, pPoints(i).y)-(pPoints(i).x + 3, pPoints(i).y + 3), vbWhite, BF
lCountNow = lCountNow + 1
End If
If lCountNow * 2 >= Me.ScaleWidth Then
lTop = lTop + 2
lCountNow = 0
End If
Next i
Me.Refresh
DoEvents
End Sub
如何?效果还不错吧~反正我觉得速度是快多了(还要感谢MysticBoy的提醒啊)
最终通过环境:VB6+Win2000