Windows API to make userform frame transparent

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
So I need to to find a way to make a userform frame semi-transparent. I have found code to make a userform itself semi-transparent but I need the frame to be semi-transparent only. Any help would be great. Below is the semi transparent userform method I was referring too:

Code:
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (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 Declare Function GetActiveWindow Lib "user32.dll" () 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 BringWindowToTop Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "User32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "User32" (ByVal hWnd As Long) As Long


Const GWL_STYLE = -16
Const WS_CAPTION = &HC00000




Const WS_SYSMENU = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Dim hWnd As Long


Private Sub UserForm_Initialize()
    Dim lngWindow As Long, lFrmHdl As Long
    lFrmHdl = FindWindow(vbNullString, Me.Caption)
    lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
    lngWindow = lngWindow And (Not WS_CAPTION)
    Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
    Call DrawMenuBar(lFrmHdl)
End Sub


Private Sub Userform_Activate()
    Dim ufcap As String
    ufcap = Lightbox.Caption
    hWnd = FindWindow("ThunderDFrame", ufcap)


    TransparentUserForm Me, 180 'increase to make darker
End Sub
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I am talking about the frame within the user-form. I was hoping this was doable and if not a way of creating a semi transparent layer over a userform (not another userform because I understand there is a userform transparency property in windows api but I do not want another userform).
 
Last edited:
Upvote 0
Making a userform frame (title bar) transparent requires the ability to draw on the titlebar .. Unfortunately, this seems to be impossible using legacy GDI api calls.

I gave this a shot and the best I could came up with was a tacky hack that uses a transparent helper userform placed underneath the userform window but the final visual output is less than ideal.

I'll keep on investigating this and if anything better comes up, I'll post it here.
 
Upvote 0
Its strange there is a method to make a complete userform transparent but not target controls such as a frame or label. Thanks for your help so far and I will continue to look as well.
 
Upvote 0

Forum statistics

Threads
1,216,303
Messages
6,129,983
Members
449,549
Latest member
birdguy_1930

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top