Solved Is there a solution to getting sub forms fade in/out (1 Viewer)

I gave it a shot and created this module:
Code:
Option Explicit

Private Declare PtrSafe Function SetWindowLong _
    Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
 
Private Declare PtrSafe Function GetWindowLong _
    Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long
 
Private Declare PtrSafe Function SetLayeredWindowAttributes _
    Lib "user32" (ByVal hwnd As LongPtr, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const GWL_EXSTYLE = -20
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2

Public Sub SetFormOpacity(FormObject As Form, opacity As Long)
    Dim currentWindowStyle As Long
    currentWindowStyle = GetWindowLong(FormObject.hwnd, GWL_EXSTYLE)

    Dim targetWindowStyle As Long
    targetWindowStyle = SetWindowLong(FormObject.hwnd, GWL_EXSTYLE, currentWindowStyle Or WS_EX_LAYERED)

    SetLayeredWindowAttributes FormObject.hwnd, 0, opacity, LWA_ALPHA
End Sub

That module helps setting the opacity of any form object, including those inside subforms. I achieved the fade in effect using the timer, but it has its issues. I didn't test using the Sleep API call, but it might make it more stable.

Please download the attached file to test its effects, I added two:
1. Fade in on timer (2 versions)
2. Fade using a slider
Thanks - I think I've got the desired effect I want by optical illusion.
 

Users who are viewing this thread

Back
Top Bottom