Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
timer2.timerval=20
dim slen as string '要移动的文字
Me.Picture1.Picture 和me.pic2.picture相同
dim outrec as rect
With outRect
.Bottom = 60
.Top = 10
.Left = 760
.Right = 760
End With
Private Sub Timer2_Timer()
On Error GoTo ToExit '打开错误陷阱
'------------------------------------------------
'slen = Len(Lstr) * Pic1.FontSize * 2
slen = LenB(StrConv(Lstr, vbFromUnicode)) * Pic1.FontSize
If outRect.Right - outRect.Left < slen Then
Me.Pic2.ForeColor = &H400000
Me.Pic2.PaintPicture Me.Picture1.Picture, 0, 0, Me.Pic2.Width, Me.Pic2.Height, 0, 0, Me.Pic2.Width, Me.Pic2.Height
sHdc = Me.Pic2.hdc
DrawText sHdc, Lstr, -1, outRect, DT_LEFT
outRect.Left = outRect.Left - 2
Me.Pic2.Refresh
Else
With outRect
.Bottom = 60
.Top = 10
.Left = 760
.Right = 760
End With
End If
'------------------------------------------------
Private Sub RunMain(picScroll As PictureBox) 其中scrolltext为要滚动的文字
' 滚动字幕
Dim LastFrameTime As Long
Const IntervalTime As Long = 40
Dim rt As Long
Dim DrawingRect As RECT
Dim UpperX As Long, UpperY As Long 'Upper left point of drawing rect
Dim RectHeight As Long
Form1.Refresh
rt = DrawText(picScroll.hdc, ScrollText, -1, DrawingRect, DT_CALCRECT)
If rt = 0 Then 'err
MsgBox "Error scrolling text", vbExclamation
EndingFlag = True
Else
DrawingRect.Top = picScroll.ScaleHeight
DrawingRect.Left = 0
DrawingRect.Right = picScroll.ScaleWidth
RectHeight = DrawingRect.Bottom
DrawingRect.Bottom = DrawingRect.Bottom + picScroll.ScaleHeight
End If
Do While Not EndingFlag
If GetTickCount() - LastFrameTime > IntervalTime Then
picScroll.Cls
DrawText picScroll.hdc, ScrollText, -1, DrawingRect, DT_CENTER 'Or DT_WORDBREAKDT_SINGLELINE And
DrawingRect.Top = DrawingRect.Top - 1
DrawingRect.Bottom = DrawingRect.Bottom - 1
If DrawingRect.Top < -(RectHeight) Then 'time to reset
DrawingRect.Top = picScroll.ScaleHeight
DrawingRect.Bottom = RectHeight + picScroll.ScaleHeight
End If
picScroll.Refresh
LastFrameTime = GetTickCount()
End If
DoEvents
Loop
End Sub
Private Sub Timer3_Timer()
Dim hei As Integer
tiAo = False
Form1.Height = Form1.Height - 50
hei = ScaleY(Form1.Height, vbTwips, vbPixels) - Picture4.Height ', vbTwips, vbPixels)
Picture4.Top = hei - 2 ' Picture4.Top + 1
If Form1.Height < 2745 Then
Timer3.Enabled = False
Label4.Enabled = True
cmdT.Enabled = True
End If