[blue]Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1
Private Const SWP_HIDEWINDOW = &H80
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal Hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Const LWA_COLORKEY = &H1&
'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 BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function StrokeAndFillPath Lib "gdi32" (ByVal hdc As Long) As Long
Private subtitles(0 To 5) As String
Private Sub Form_Load()
Dim StyleEx As Long
' Various setup stuff
With Form2
.ScaleMode = vbPixels
.AutoRedraw = True
.BackColor = RGB(10, 20, 30)
.FontName = "Verdana"
.FontBold = True
.FontSize = 16
.FillStyle = vbSolid
.ForeColor = vbBlack
End With
' Ok, play the transparent trick
StyleEx = GetWindowLong(Hwnd, GWL_EXSTYLE)
StyleEx = StyleEx Or WS_EX_LAYERED
SetWindowLong Hwnd, GWL_EXSTYLE, StyleEx
SetLayeredWindowAttributes Hwnd, RGB(10, 20, 30), 0, LWA_COLORKEY
' SOme example subtitles
subtitles(0) = "First subtitle"
subtitles(1) = "Second subtitle"
subtitles(2) = "Third subtitle"
subtitles(3) = "Fourth subtitle"
subtitles(4) = "Fifth subtitle"
subtitles(5) = "Sixth subtitle"
Timer1.Interval = 5000
' Make sure we are top of application's Z order
SetWindowPos Me.Hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
' Example of dealing with form resize
Private Sub Form_Resize()
Form1.Move Me.Left, Me.Top, Me.Width, Me.Height
DisplaySubtitle "Ooh, I just resized ...", RGB(255, 0, 0)
End Sub
Private Function DisplaySubtitle(strOut As String, Optional NewFillColor As Long = &HFFFFFF)
With Form2
.Cls
.FillColor = NewFillColor
BeginPath .hdc
Form2.ScaleMode = vbPixels
Form2.CurrentY = Me.ScaleHeight - TextHeight(strOut)
Form2.CurrentX = (Me.ScaleWidth - TextWidth(strOut)) / 2
Form2.Print strOut
EndPath .hdc
StrokeAndFillPath .hdc
End With
End Function
' Cycle through example subtitles
Private Sub Timer1_Timer()
Static WhichSubtitle
DisplaySubtitle subtitles(WhichSubtitle)
WhichSubtitle = (WhichSubtitle + 1) Mod 6
End Sub[/blue]