快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

手机澳门银河总站娱乐平台_集报网



姜卫东、华云

今朝有许多软件都采纳了类似于“电视字幕”的滚动字幕的形式(如电子小说涉猎器以及诸如Winamp的“关于”界面等)。在VB中平日用一个Timer控件来节制文本的滚动速率,然则它的毛病便是跳跃感太强,效果不好。本文将先容在VB中经由过程API手机澳门银河总站娱乐平台函数DrawText来实现文本的平滑滚动。

函数阐明

该函数的用法如下:

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

其感化是将文本描画到指定的矩形中返回值Long:描画翰墨的高度

参数类型及阐明

hdc:欲在此中显示翰墨的一个设备场景的句柄;

lpStr:欲描画的文本字串;

nCount:欲描画的字符数量。假如要描画全部字串(直到空终止符),则可将这个参数设为-1;

lpRect:指定用于绘图的一个款式化矩形(采纳逻辑坐标);

wFormat:一手机澳门银河总站娱乐平台个标志位数组,抉择了以何种形式履行绘图。

法度榜样实现

进入VB,在默认窗体FORM1上放一个Picture控件“Picmain”,一个敕令按钮“Command1”,然后输入如下代码:

Option Explicit

Private 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

Private Declare Function GetTickCount Lib "kernel32" () As Long

Const DT_BOTTOM As Long = &&H8

Const DT_CALCRECT As Long = &&H400

Const DT_CENTER As Long = &&H1

Const DT_WORDBREAK As Long = &&H10

Private Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Const ScrollText As String = "滚动字幕示例" && vbCrLf && vbCrLf && vbCrLf && "作者:姜卫东" && vbCrLf && _ vbCrLf && "地址:黑龙江省农业经济黉舍" && vbCrLf && vbCrLf && "有问题请给我来信!!!" && vbCrLf && "E-MAIL:hyjs@yeah.net" && vbCrLf && vbCrLf && vbCrLf && "感谢应用"

Dim isend As Boolean

Private Sub Command1_Click()

If isend = False Then

isend = True

Else

isend = False

frmAbout.Refresh

scrollme

End If

End Sub

Private Sub Form_A手机澳门银河总站娱乐平台ctivate()

scrollme

End Sub

Private Sub Form_Load()

picmain.ForeColor = vbGreen

picmain.FontSize = 14

End Sub

Private Sub scrollme()

Dim LastFrameTime As Long

'设置光阴距离,即滚动速率

Const IntervalTime As Long = 10

Dim rt As Long

Dim DrawingRect As RECT

'设置所画矩形的左边位置。

Dim tmpX As 手机澳门银河总站娱乐平台Long, tmpY As Long

Dim RectHeight As Long

'显示窗体

frmAbout.Refresh

'得到所画矩形的尺寸

rt = DrawText(picmain.hdc, ScrollText, -1, DrawingRect, DT_CALCRECT)

If rt = 0 Then

MsgBox "掉足", vbExclamation

isend = True

Else

'设置矩形的位置

DrawingRect.Top = picmain.ScaleHeight

DrawingRect.Left = 0

DrawingRect.Right = picmain.ScaleWidth

'设置矩形的高度

RectHeight = DrawingRect.Bottom

DrawingRect.Bottom = DrawingRect.Bottom + picmain.ScaleHeight

End If

Do While Not isend

If GetTickCount() - LastFrameTime > IntervalTime Then

picmain.Cls

DrawText picmain.hdc, ScrollText, -1, DrawingRect, DT_CENTER Or DT_WORDBREAK

DrawingRect.Top = DrawingRect.Top - 1

DrawingRect.Bottom = DrawingRect.Bottom - 1

'节制文本的轮回滚动

If DrawingRect.Top < -(RectHeight) Then

DrawingRect.Top = picmain.ScaleHeight

DrawingRect.Bottom = RectHeight + picmain.ScaleHeight

End If

picmain.Refresh

LastFrameTime手机澳门银河总站娱乐平台 = GetTickCount()

End If

DoEvents

Loop

Set frmAbout = Nothing

End Sub

Private Sub Form_Unload(Cancel As Integer)

isend = True

End Sub Sub

以上法度榜样在Windows+VB6.0中文企业版中运行经由过程。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: