• Welcome to Valhalla Legends Archive.
 

Window Transparency Class

Started by Telos, April 01, 2004, 02:10 PM

Previous topic - Next topic

Telos


'''''''''''''''''''''
' 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

Spht

You code like CupHead, but I guess that can be useful.

Noodlez

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

Telos

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

o.OV

Just so you know.. I saw such a class somewhere online in several places.
If the facts don't fit the theory, change the facts. - Albert Einstein

MyndFyre

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

?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Maddox

asdf.

Newby

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 ><
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Telos

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