Чтобы корректно вычислить длину, можно использовать шрифт с фиксированной шириной
http://www.vbstreets.ru/ActiveX/GUI/66197.aspx
uhm писал(а):Как вариант (не знаю, может, плохой) - Сделать Label, и по таймеру присваивать Label.Caption значение Mid$(строка_текста, старт, длина). Старт опять же по таймеру увеличивается на 1. Чтобы корректно вычислить длину, можно использовать шрифт с фиксированной шириной
5% (2.8 (2.1) GHz)
keks-n писал(а):Это жрёт 100 MHz... На ОДНУ бегущую строку. То есть 4 таких сожрут ВСЕ ресурсы Intel Celeron 433MHz.
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 CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function CreateFontA Lib "gdi32" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Const RunningText As String = "Бегущая строка"
Dim MemDC As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim MemBMP As Long, rc As RECT, hFont As Long
MemDC = CreateCompatibleDC(0)
MemBMP = CreateCompatibleBitmap(Me.hdc, Me.TextWidth(RunningText) + 40, _
Me.TextHeight(RunningText))
SelectObject MemDC, MemBMP
rc.Right = Me.TextWidth(RunningText) + 40
rc.Bottom = Me.TextHeight(RunningText)
FillRect MemDC, rc, CreateSolidBrush(Me.BackColor)
With Me.Font
hFont = CreateFontA(.Size, 0, 0, 0, .Weight, .Italic, .Underline, .Strikethrough, .Charset, 0, 0, 2, 0, .Name)
End With
DeleteObject SelectObject(MemDC, hFont)
SetBkMode MemDC, 1
TextOut MemDC, 0, 0, RunningText, Len(RunningText)
End Sub
Private Sub Timer1_Timer()
Static CurPos As Long
CurPos = CurPos - 5
If CurPos < -Me.TextWidth(RunningText) Then CurPos = Me.ScaleWidth + Me.TextWidth(RunningText)
BitBlt Me.hdc, CurPos, 0, Me.TextWidth(RunningText) + 40, _
Me.TextHeight(RunningText), _
MemDC, 0, 0, vbSrcCopy
End Sub
Option Explicit
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Const RunningText = "Бегущая строка"
Private Sub Form_Load()
Dim hRgn As Long
Const sText = "Click Here!"
Picture1.Top=0
Picture1.FontName = "Arial"
Picture1.FontSize = 16
Picture1.BackColor = vbRed
Picture1.Width = Picture1.TextWidth(RunningText)
Picture1.Height = Picture1.TextHeight(RunningText)
BeginPath Picture1.hdc
TextOut Picture1.hdc, 0, 0, RunningText, Len(RunningText)
EndPath Picture1.hdc
hRgn = PathToRegion(Picture1.hdc)
SetWindowRgn Picture1.hWnd, hRgn, True
DeleteObject hRgn
Timer1_Timer
End Sub
Private Sub Timer1_Timer()
Static CurPos As Long
CurPos = CurPos - 50
If CurPos < -Picture1.Width Then CurPos = Me.ScaleWidth + Picture1.Width
Picture1.Left = CurPos
End Sub
keks-n писал(а):5% (2.8 (2.1) GHz)
Это жрёт 100 MHz... На ОДНУ бегущую строку. То есть 4 таких сожрут ВСЕ ресурсы Intel Celeron 433MHz. И это по твоему нормально!? Интервейс не должен использовать столько ресурсов для фоновой работы. Он может жрать ресурсы, когда таскают форму, её элементы, что-то там нажимают, показывается новое окно, т. е. идёт активная перерисовка. А за такой вот "хороший код", мало кто скает спасибо...
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 71