扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
(1)Bitblt( )函数只能实现图像的位块传输,那么如何实现背景与控件界面一同擦视;
(2)调用Bitblt( )函数需要传递一长串繁琐的参数,那么如何用一个通用过程将其模块化,使其通用性强,使用简单。
窗体中的控件虽然不能被擦视,但图像能实现,我们可以首先“拍”下要切换的两个窗体界面的图片,当需要擦视切换时,将一个载有该图片的过渡窗体Show出来,在该窗体上实现擦视切换(以下给出了5种擦视方法),擦视完毕后将其Hide,并将第二个窗体Show出来,这样在视觉上毫无破绽,具体方法如下:
编写一个通用的Wipe过程实现擦视
(1)在一个新工程中添加一个窗体,该窗体只含一个PictureBox控件,属性设置如下:
对象 Name AutoRedraw ScaleMode Visible BorderStyle
Form FrmWipe True 3---pixel 0---None
PictureBox PicResource True 3---pixel False
(2)添加一个标准模块Wipe.bas其代码如下:
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
Public FrmOriginal As Form
Public FrmNextOne As Form
Public WipeMode As Integer
Public strDestine, strResource As String
’ 定义Wipe过程
Public Sub Wipe(iMode As Integer, WipeStrDestine As String, WipeStrResource As String, frmHide As Form,_ frmShow As Form) ‘iMode为擦视方式,WipeStrDestine和WipeStrResource为图片路径,frmHide和
WipeMode = iMode ‘frmShow为切换窗体
Set FrmNextOne = frmShow
Set FrmOriginal = frmHide
strDestine = WipeStrDestine
strResource = WipeStrResource
FrmWipe.Show ‘Show出过度窗体
End Sub
(3)在FrmWipe窗体的Form_Initialize( )、Form_Activate( )和Form_Deactivate( )事件中添加代码如下:
Private Sub Form_Activate()
Dim iMoveStep, xMax, yMax, iEndMax As Integer
Dim w, h, iTemp, i, X1, Y1, ij As Integer
Dim kxy As Single
Dim blnStop As Boolean
MousePointer = 11 ’让鼠标成沙漏
FrmWipe.Picture = LoadPicture(strDestine)
PicResource.Picture = LoadPicture(strResource)
blnStop = False
iMoveStep = 0
xMax = FrmWipe.ScaleWidth / 2
yMax = FrmWipe.ScaleHeight / 2
kxy = yMax / xMax
h = FrmWipe.ScaleHeight
While blnStop = False
Select Case WipeMode ’擦视方式
Case 1 ’从中间向周围擦视
iEndMax = xMax
X1 = xMax - iMoveStep
w = iMoveStep * 2
Y1 = CInt(yMax - iMoveStep * kxy)
h = CInt(2 * iMoveStep * kxy)
i = BitBlt(FrmWipe.hDC, X1, Y1, w, h, PicResource.hDC, X1, Y1, &HCC0020)
Case 2 ’从左向右擦视
iEndMax = xMax
w = iMoveStep * 2
i = BitBlt(FrmWipe.hDC, 0, 0, w, h, PicResource.hDC, X1, Y1, &HCC0020)
Case 3 ’从左右向中间擦视
iEndMax = xMax
w = iMoveStep
i = BitBlt(FrmWipe.hDC, 0, 0, w, h, PicResource.hDC, 0, 0, &HCC0020)
X1 = ScaleWidth - iMoveStep
i = BitBlt(FrmWipe.hDC, X1, 0, w, h,
PicResource.hDC, X1, 0, &HCC0020)
Case 4 ’呈百叶窗状擦视
iEndMax = CInt(2 * xMax / 10)
iTemp = CInt(2 * xMax / 10)
w = iMoveStep - 7
For ij = 0 To 9
i = BitBlt(FrmWipe.hDC, iTemp * ij, 0, w, h,
PicResource.hDC, iTemp * ij, 0, &HCC0020)
Next
Case 5 ’从中间向左右
iEndMax = xMax
w = iMoveStep * 2
X1 = xMax - iMoveStep
i = BitBlt(FrmWipe.hDC, X1, 0, w, h,
PicResource.hDC, X1, 0, &HCC0020)
End Select
Refresh
iMoveStep = iMoveStep + 8 ‘加上不同的常量可改变擦视速度
If iMoveStep > iEndMax Then ‘结束条件
blnStop = True
End If
Wend
FrmNextOne.Show ’show出第二个窗体
FrmOriginal.Hide ’隐藏原窗体,也可以Unload
FrmWipe.Hide ’隐藏过渡窗体,也可以Unload
End Sub
Private Sub Form_Deactivate()
FrmWipe.Picture = LoadPicture() ‘清空图片释放内存
PicResource.Picture = LoadPicture()
End Sub
Private Sub Form_Initialize()
FrmWipe.WindowState = FrmOriginal.WindowState ’ 使各个窗体的大小、位置一致
If FrmOriginal.WindowState < > 2 Then
FrmWipe.Width = FrmNextOne.Width
FrmWipe.Height = FrmNextOne.Height
FrmWipe.Top = FrmOriginal.Top
FrmWipe.Left = FrmOriginal.Left
FrmNextOne.Top = FrmOriginal.Top
FrmNextOne.Left = FrmOriginal.Left
FrmNextOne.Width = FrmOriginal.Width
FrmNextOne.Height = FrmOriginal.Height
End If
End Sub
应用举例
当程序设计中窗体切换需要擦视时,只需将上述窗体FrmWipe.frm和模块Wipe.bas添加到您的工程中,并在您需要擦视的事件中调用Wipe过程即可轻松地实现擦视技术。假设您需要通过单击按钮(名为cmdChangeToForm1和cmdChangeToForm2),在Form1和Form2间相互擦视切换,可在Form1中的cmdChangeToForm2_Click( )和Form2中的cmdChangeToForm1_Click( )事件中调用Wipe过程。假设“拍”下来两幅界面图片放在:VB5\Background\子目录下名为:PicForm1.jpgPic和PicForm2.jpg。(用Windows中的画图、图片编辑器或PhotoShop均可实现)
Private Sub cmdChangeToForm2_Click()
Wipe 4, App.Path + "\back\PicForm1.jpg", App.Path + "\back\PicForm2.jpg", Form1, Form2
End Sub ‘调用Wipe过程,4表示用第四种方法擦视
Private Sub cmdChangeToForm1_Click()
Wipe 1, App.Path + "\back\PicForm2.jpg", App.Path + "\back\PicForm1.jpg", Form2, Form1
End Sub
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者