Valhalla Legends Forums Archive | Visual Basic Programming | Window Transparency Class

AuthorMessageTime
Telos
[code]
'''''''''''''''''''''
' CTransparentForm
' By: Telos
' Telos@mindless.com
' Date: 4/1/2004
' Revision: 1
'''''''''''''''''''''

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const WS_EX_TRANSPARENT = &H20&
Private Const LWA_ALPHA = &H2&

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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" (ByVal hWnd As Long, ByVal crKey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private hWindow As Long

Public Property Get hWnd() As Long
hWnd = hWindow
End Property

Public Property Let hWnd(ByVal hWindowHandle As Long)
hWindow = hWindowHandle

' Get the old window style
Dim nCurrentWindowStyle As Long
nCurrentWindowStyle = GetWindowLong(hWindow, GWL_EXSTYLE)

' Or the old style with the layered style
' so that we can access transparency
Call SetWindowLong(hWindow, GWL_EXSTYLE, nCurrentWindowStyle Or WS_EX_LAYERED)

' Window will appear as totally transparent
' unless we set this right away
Call SetTransparency(0)
End Property

Public Sub SetTransparency(ByVal nPercent As Byte)
' Make the call that changes the window
' transparency.
'
' Accepts 0 - 100
' 0 = totally visible
' 100 = totally invisible
Call SetLayeredWindowAttributes(hWindow, 0, 255 - (255 * (nPercent / 100)), LWA_ALPHA)
End Sub
[/code]
April 1, 2004, 8:10 PM
Spht
You code like CupHead, but I guess that can be useful.
April 2, 2004, 3:58 PM
Noodlez
[quote author=Spht link=board=31;threadid=6126;start=0#msg53208 date=1080921516]
You code like CupHead, but I guess that can be useful.
[/quote]
CupHead ripped my style :p
April 2, 2004, 7:44 PM
Telos
[quote author=Spht link=board=31;threadid=6126;start=0#msg53208 date=1080921516]
You code like CupHead, but I guess that can be useful.
[/quote]

If you mean the hungarian notation lots of people use that
April 2, 2004, 10:01 PM
o.OV
Just so you know.. I saw such a class somewhere online in several places.
April 3, 2004, 5:03 AM
Myndfyr
So why aren't you giving credit where it's due, Telos? I vividly recall telling you of the "SetLayeredWindowAttributes" function the other day in Op [vL], because after we were done, I implemented the same project in C#. I tried to set it up with the handle to my cmd.exe window, and it didn't work -- returing with error code 87, "The parameter is incorrect." The window class is wrong with a console window.

Where's the:
[code]
'Thanks to MyndFyre for finding this function for me
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
[/code]
?
April 3, 2004, 5:30 PM
Maddox
http://www.jelovic.com/articles/stupid_naming.htm
April 3, 2004, 6:58 PM
Newby
[quote author=Maddox link=board=31;threadid=6126;start=0#msg53356 date=1081018736]
http://www.jelovic.com/articles/stupid_naming.htm
[/quote]
I hate naming stuff with the abbreviation. (C, cls, mod, frm, cmd, etc)

It just is annoying ><
April 3, 2004, 7:28 PM
Telos
[quote author=Myndfyre link=board=31;threadid=6126;start=0#msg53345 date=1081013406]
So why aren't you giving credit where it's due, Telos? I vividly recall telling you of the "SetLayeredWindowAttributes" function the other day in Op [vL], because after we were done, I implemented the same project in C#. I tried to set it up with the handle to my cmd.exe window, and it didn't work -- returing with error code 87, "The parameter is incorrect." The window class is wrong with a console window.

Where's the:
[code]
'Thanks to MyndFyre for finding this function for me
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
[/code]
?
[/quote]

I vividly recall you lying in this post I suggest you check logs to see who it was you were really talking to
April 3, 2004, 9:47 PM

Search