Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Telos on April 01, 2004, 02:10 PM

Title: Window Transparency Class
Post by: Telos on April 01, 2004, 02:10 PM

'''''''''''''''''''''
' CTransparentForm
' By: Telos
' [email protected]
' 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
Title: Re:Window Transparency Class
Post by: Spht on April 02, 2004, 09:58 AM
You code like CupHead, but I guess that can be useful.
Title: Re:Window Transparency Class
Post by: Noodlez on April 02, 2004, 01:44 PM
Quote from: Spht on April 02, 2004, 09:58 AM
You code like CupHead, but I guess that can be useful.
CupHead ripped my style :p
Title: Re:Window Transparency Class
Post by: Telos on April 02, 2004, 04:01 PM
Quote from: Spht on April 02, 2004, 09:58 AM
You code like CupHead, but I guess that can be useful.

If you mean the hungarian notation lots of people use that
Title: Re:Window Transparency Class
Post by: o.OV on April 02, 2004, 11:03 PM
Just so you know.. I saw such a class somewhere online in several places.
Title: Re:Window Transparency Class
Post by: MyndFyre on April 03, 2004, 11:30 AM
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:

'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

?
Title: Re:Window Transparency Class
Post by: Maddox on April 03, 2004, 12:58 PM
http://www.jelovic.com/articles/stupid_naming.htm
Title: Re:Window Transparency Class
Post by: Newby on April 03, 2004, 01:28 PM
Quote from: Maddox on April 03, 2004, 12:58 PM
http://www.jelovic.com/articles/stupid_naming.htm
I hate naming stuff with the abbreviation. (C, cls, mod, frm, cmd, etc)

It just is annoying ><
Title: Re:Window Transparency Class
Post by: Telos on April 03, 2004, 03:47 PM
Quote from: Myndfyre on April 03, 2004, 11:30 AM
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:

'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

?

I vividly recall you lying in this post I suggest you check logs to see who it was you were really talking to