Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Transparency (Not like old posts) 2

Status
Not open for further replies.

AkutaSame

Programmer
Oct 5, 2002
97
US
I know that it is possible to use API calls to modify the alpha state of the forms in VB6... This isn't really what I'm referring to (which is why it's not like the other posts found when doing search). What I want to know is this:

Is it possible to make the background for the form transparent, yet leave all of the objects for which I have chosen to remain visible to actually show. i.e. The alpha for ONLY the form background is changed.

I am thinking of writing a program with an amoebic interface, but if I can't make the rest transparent, what would be the point, right? :p

Thanks for any help,
Akuta
 
Thank you much, Sir. I'd actually been doing a lot of research on this. This looks like most direct way of doing it.

Sorry for the late "thanks" :) Haven't been back at tek-tips for a while.

Akuta
 
You can use the SetLayeredWindowAttributes function to create both an alpha-transparency effect; or and ameobic clipping interface.

Here is a quick example.

Place some common UI controls on your form like buttons, checks, lists, combos, texts and so on...

Insert the following code and run the program.
___
[tt]
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 Sub Form_Load()
Dim ExStyle As Long
BackColor = vbRed
ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
ExStyle = ExStyle Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, ExStyle
SetLayeredWindowAttributes hwnd, vbRed, 0, LWA_COLORKEY
End Sub[/tt]
___

This will essentially produce the effect you need.

See also thread222-493597 to see both operating modes of the SetLayeredWindowAttributes function.

Note that this function in only supported on Windows 2000 and Windows XP, otherwise you should go for Regions as suggested by vb5prgrmr and also in the above-mentioned thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top