Darken background when Msgbox appears

Coming back to this, if I wanted to just dim the tab control on a the form in the background, could this be done?
I'm not replying to this; last time i got accused of infecting the forum with a virus lol
 
Disregard, figured it out...
 
Actually, no I didn't, what I thought would work failed miserably.
If anyone knows how to apply this FadeIn/Out feature to just the Access Window, please weigh in. I tried to "grab" with positions and then resize the frmOverLay, but that voodoo is well beyond my ken.

I considered using ChatGPT/Gemini but I am trying to wean myself off LMM's when it comes to VBA and use this forum instead.
 
Actually, no I didn't, what I thought would work failed miserably.
If anyone knows how to apply this FadeIn/Out feature to just the Access Window, please weigh in. I tried to "grab" with positions and then resize the frmOverLay, but that voodoo is well beyond my ken.

I considered using ChatGPT/Gemini but I am trying to wean myself off LMM's when it comes to VBA and use this forum instead.
Are you of Scottish descent at all? :)
 
Actually, no I didn't, what I thought would work failed miserably.
If anyone knows how to apply this FadeIn/Out feature to just the Access Window, please weigh in. I tried to "grab" with positions and then resize the frmOverLay, but that voodoo is well beyond my ken.

I considered using ChatGPT/Gemini but I am trying to wean myself off LMM's when it comes to VBA and use this forum instead.

This is what i use...

Just remember to Call EnableFade hwnd before SetFormOpacity to ensure the window supports transparency.

Code:
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 Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" ( _
    ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr

Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" ( _
    ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr

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

Public Sub EnableFade(hwnd As LongPtr)
    Dim exStyle As LongPtr
    exStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
    SetWindowLong hwnd, GWL_EXSTYLE, exStyle Or WS_EX_LAYERED
End Sub

Public Sub SetFormOpacity(hwnd As LongPtr, alpha As Byte)
    SetLayeredWindowAttributes hwnd, 0, alpha, LWA_ALPHA
End Sub
 
This is what i use……

Just remember to Call EnableFade hwnd before SetFormOpacity to ensure the window supports transparency.

Code:
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 Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" ( _
    ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr

Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" ( _
    ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr

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

Public Sub EnableFade(hwnd As LongPtr)
    Dim exStyle As LongPtr
    exStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
    SetWindowLong hwnd, GWL_EXSTYLE, exStyle Or WS_EX_LAYERED
End Sub

Public Sub SetFormOpacity(hwnd As LongPtr, alpha As Byte)
    SetLayeredWindowAttributes hwnd, 0, alpha, LWA_ALPHA
End Sub

To have a smooth fade in/out use:

Code:
Public Sub FadeInWindow(hwnd As LongPtr, Optional stepSize As Byte = 15, Optional delayMs As Long = 30)
    Dim i As Byte
    Call EnableFade(hwnd)
    For i = 0 To 255 Step stepSize
        Call SetFormOpacity(hwnd, i)
        Sleep delayMs
    Next i
End Sub

' === Fade Out: Smoothly decrease opacity ===
Public Sub FadeOutWindow(hwnd As LongPtr, Optional stepSize As Byte = 15, Optional delayMs As Long = 30)
    Dim i As Byte
    Call EnableFade(hwnd)
    For i = 255 To 0 Step -stepSize
        Call SetFormOpacity(hwnd, i)
        Sleep delayMs
    Next i
End Sub

Example: -


Code:
' Fade out the Access form itself
Call FadeOutWindow(Me.hWnd)
 

Users who are viewing this thread

Back
Top Bottom