Solved

Full Screen Text (On Top) and transparency

Posted on 2002-04-12
3
138 Views
Last Modified: 2010-05-02
I am writing an activex control that I wish to enable text to be written onto the top screen.
The control itself uses pop up forms etc that remain on top.  I wish to place text on top of the controlling app.
I can of course use a text box or simple form but, I wnat it to give text notices with transparent background on top of the active application.
I have use transparent forms and have also used animated gifs on top of everything but text doesn't work.
I can write text on the screen but it can not be removed or changed easily.
I dont want a form or anything to be visible except the text with a trasparent background.
Secondly, many transparent forms simply use picture snapshots of the background. Is there a way of having an active transparent form. IE if animations are going on in the background app then they are visible. If you have a animated gif running in explorer and you place a transparent form over the top then I want to see the animation still running, not a still of it.
(I want to see the fridge light with the door closed.)
0
Comment
Question by:ProgramIT
  • 2
3 Comments
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Hi

Option Explicit
'=======Clipping text staff===============
Private Declare Function SelectClipPath Lib "gdi32" (ByVal hdc As Long, ByVal iMode 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 PathToRegion Lib "gdi32" (ByVal hdc 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 Const RGN_COPY = 5

'===========Always on top staff============
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_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOREDRAW = &H8

Private Sub Form_Load()
  'Don't forget set BorderStyle property to None at design time!
  Const TXT = " Cool programm" & vbCrLf & "           from" & vbCrLf & "  Cool Company" & vbCrLf & "CopyLeft by Ark"
  Dim hRgn As Long
  Font.Name = "Times New Roman"
  Font.Bold = True
  Font.Size = 60
  Width = TextWidth(TXT)
  Height = TextHeight(TXT)
  BeginPath hdc
    CurrentX = 0
    CurrentY = 0
    Print TXT
  EndPath hdc
  hRgn = PathToRegion(hdc)
  SetWindowRgn hWnd, hRgn, False
  AutoRedraw = True

'Now, you can color you text by loading any picture
'Picture = LoadPicture("c:\windows\clouds.bmp")

'or using color lines. All drowings will affect only text.

Line (1, 1)-(Width, Height / 4), vbRed, BF
Line (1, Height / 4)-(Width, Height / 2), vbBlue, BF
Line (1, Height / 2)-(Width, 3 * Height / 4), vbGreen, BF
Line (1, 3 * Height / 4)-(Width, Height), vbYellow, BF
  Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
End Sub

Private Function Window_SetAlwaysOnTop(hwnd As Long, bAlwaysOnTop As Boolean) As Boolean
   Window_SetAlwaysOnTop = SetWindowPos(hwnd, -2 - bAlwaysOnTop, 0, 0, 0, 0, SWP_NOREDRAW Or SWP_NOSIZE Or SWP_NOMOVE)
End Function

Enjoy :)
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
Comment Utility
Oops, forgot to add call to Window_SetAlwaysOnTop function at the end of Form_Load event
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
A long time ago, i used this:

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function BeginPath 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 EndPath Lib "gdi32" _
    (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" _
    (ByVal hdc As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" _
    (ByVal hRgn As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32" _
    (lpRect As RECT) As Long
Private Declare Function CombineRgn Lib "gdi32" _
    (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
    ByVal hSrcRgn2 As Long, _
    ByVal nCombineMode As Long) As Long
Private Const RGN_AND = 1
Private Declare Function DeleteObject Lib "gdi32" _
    (ByVal hObject 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 ReleaseCapture Lib "user32" _
    () As Long
Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Dim Texto(0 To 2) As String
Dim strLength(0 To 2) As Integer
Dim XPos(0 To 2) As Integer

Private Function GetTextRgn(strTexto As String, intCounter As Integer, XPos As Integer) As Long
    Dim hRgn1 As Long, hRgn2 As Long
    Dim rct As RECT
    'Create a path on the form's device context...
    BeginPath hdc
    TextOut hdc, XPos, 0, strTexto, intCounter 'Chr$(88) & Chr$(88), 2
    EndPath hdc
    '... convert that path to a region for our form...
    hRgn1 = PathToRegion(hdc)
    GetRgnBox hRgn1, rct
    hRgn2 = CreateRectRgnIndirect(rct)
    '... and invert the region.
    CombineRgn hRgn2, hRgn2, hRgn1, RGN_AND

    DeleteObject hRgn1
    GetTextRgn = hRgn2
End Function

Private Sub GradateColors(Colors() As Long, _
ByVal Color1 As Long, ByVal Color2 As Long)
    On Error Resume Next

    Dim i As Integer
    Dim dblR As Double, dblG As Double, dblB As Double
    Dim addR As Double, addG As Double, addB As Double
    Dim bckR As Double, bckG As Double, bckB As Double

    dblR = CDbl(Color1 And &HFF)
    dblG = CDbl(Color1 And &HFF00&) / 255
    dblB = CDbl(Color1 And &HFF0000) / &HFF00&
    bckR = CDbl(Color2 And &HFF&)
    bckG = CDbl(Color2 And &HFF00&) / 255
    bckB = CDbl(Color2 And &HFF0000) / &HFF00&
    addR = (bckR - dblR) / UBound(Colors)
    addG = (bckG - dblG) / UBound(Colors)
    addB = (bckB - dblB) / UBound(Colors)

    For i = 0 To UBound(Colors)
        dblR = dblR + addR
        dblG = dblG + addG
        dblB = dblB + addB
        If dblR > 255 Then dblR = 255
        If dblG > 255 Then dblG = 255
        If dblB > 255 Then dblB = 255
        If dblR < 0 Then dblR = 0
        If dblG < 0 Then dblG = 0
        If dblG < 0 Then dblB = 0
        Colors(i) = RGB(dblR, dblG, dblB)
    Next
End Sub

Private Sub Form_Click()
Unload Me
End Sub

Private Sub Form_DblClick()
    'Always nice to have a way out
    Unload Me
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
x As Single, Y As Single)
    'Allow dragging of the form, even
    'without a titlebar.
    ReleaseCapture
    SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End Sub

Private Sub Form_Paint()
    'Use a fancy gradient for the demo,
    'instead of that drab vbButtonFace.
    Dim Colors() As Long
    Dim Iter As Long

    Const Banding = 8

    ReDim Colors(ScaleHeight \ Banding) As Long
    GradateColors Colors(), vbWhite, vbBlack
    For Iter = 0 To ScaleHeight Step Banding
        Line (0, Iter)-(ScaleWidth, Iter + Banding), _
            Colors(Iter \ Banding), BF
    Next
End Sub

Private Sub Timer1_Timer()
Dim x As Long
Static Contador As Integer
Dim hRgn As Long
Me.Visible = True
Texto(0) = ")1998 - Done by"
strLength(0) = 15
XPos(0) = 0

Texto(1) = "Prowler_666."
strLength(1) = 12
XPos(1) = 50

Texto(2) = "Bye!"
strLength(2) = 4
XPos(2) = 200

If Contador = 3 Then Contador = 0

    hRgn = GetTextRgn(Texto(Contador), strLength(Contador), XPos(Contador))
    SetWindowRgn hwnd, hRgn, 1
    x = GetTextRgn(Texto(Contador), strLength(Contador), XPos(Contador))
    Debug.Print Texto(Contador), strLength(Contador), XPos(Contador)
    Contador = Contador + 1
   
    Me.Refresh
End Sub


0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now