Results 1 to 4 of 4

Thread: Fade and Opacity

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    182

    Fade and Opacity

    Hi,

    Two questions:

    1) How do i change the opacity of a form

    2) How can i make a form fade in?

    Any help would be great!

    Thanks,

    Ross

  2. #2
    Lively Member Moneybucks's Avatar
    Join Date
    Apr 2006
    Location
    Kingston Upon Thames -UK
    Posts
    123

    Re: Fade and Opacity

    Use this API code:

    VB Code:
    1. ‘In general declarations
    2. Dim intA as integer
    3. Const LWA_COLORKEY = &H1
    4. Const LWA_ALPHA = &H2
    5. Const GWL_EXSTYLE = (-20)
    6. Const WS_EX_LAYERED = &H80000
    7.  
    8. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    9.    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    10. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    11.    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    12. Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    13.    (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
    14.    ByVal dwFlags As Long) As Long
    15.  
    16.  
    17.  
    18. Private Sub TmrTimer_timer
    19.  
    20. If intA <> 255 Then
    21. IntA = intA + 1
    22. Else
    23. tmrTimer.enabled = false
    24. End If
    25.  
    26. Dim Ret As Long
    27. Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    28. Ret = Ret Or WS_EX_LAYERED
    29. SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    30. 'Set the opacity of the layered window to intA
    31. SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
    32. End Sub
    33.  
    34. End Sub
    If, somehow, I help you, please rate the post using the scales icon in the left bar <---- .

    Please Use Naming Conventions in your projects! ------\/
    http://www.visibleprogress.com/vb_na...onventions.htm

    Me to Brother
    -Hey, look at this avater I made in about 5 seconds
    -What, morrisons?
    -AGHHHHHH

  3. #3
    Junior Member totonho's Avatar
    Join Date
    Dec 2006
    Location
    Aarhus, Denmark
    Posts
    22

    Re: Fade and Opacity

    Quote Originally Posted by Moneybucks
    Use this API code:

    VB Code:
    1. ‘In general declarations
    2. Dim intA as integer
    3. Const LWA_COLORKEY = &H1
    4. Const LWA_ALPHA = &H2
    5. Const GWL_EXSTYLE = (-20)
    6. Const WS_EX_LAYERED = &H80000
    7.  
    8. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    9.    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    10. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    11.    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    12. Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    13.    (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
    14.    ByVal dwFlags As Long) As Long
    15.  
    16.  
    17.  
    18. Private Sub TmrTimer_timer
    19.  
    20. If intA <> 255 Then
    21. IntA = intA + 1
    22. Else
    23. tmrTimer.enabled = false
    24. End If
    25.  
    26. Dim Ret As Long
    27. Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    28. Ret = Ret Or WS_EX_LAYERED
    29. SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    30. 'Set the opacity of the layered window to intA
    31. SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
    32. End Sub
    33.  
    34. End Sub

    hey dude i modify your code because the form was showing and before disapear... and after was showing again! now the form is show with fade! i thing that are so be good now

    look this


    VB Code:
    1. Option Explicit
    2.  
    3.  
    4.  
    5.  
    6. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    7.    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    8. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    9.    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    10. Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    11.    (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
    12.    ByVal dwFlags As Long) As Long
    13.  
    14.  
    15. Const LWA_COLORKEY = &H2
    16. Const LWA_ALPHA = &H2
    17. Const GWL_EXSTYLE = (-20)
    18. Const WS_EX_LAYERED = &H80000
    19.  
    20.  
    21.  
    22.  
    23.  
    24. Dim intA As Integer
    25.  
    26. Private Sub Form_Load()
    27. Form1.Visible = False
    28. End Sub
    29.  
    30. Private Sub TmrTimer_timer()
    31.  
    32. If intA <> 255 Then
    33. intA = intA + 1
    34. If intA > 1 Then
    35. Form1.Visible = True
    36. End If
    37. Else
    38. TmrTimer.Enabled = True
    39. End If
    40.  
    41. Dim Ret As Long
    42. Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    43. Ret = Ret Or WS_EX_LAYERED
    44. SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    45. 'Set the opacity of the layered window to intA
    46. SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
    47. End Sub
    [VBCODE]on error go to VBForums[/VBCODE]

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Fade and Opacity

    there's no need to constantly set the GWL_EXSTYLE, I'd do something more like:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    4.    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    5.    
    6. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    7.    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    8.    
    9. Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    10.    (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    11.  
    12. Private Const LWA_ALPHA = &H2
    13. Private Const GWL_EXSTYLE = (-20)
    14. Private Const WS_EX_LAYERED = &H80000
    15.  
    16. Private Sub Form_Load()
    17.     Dim lStyle As Long
    18.     lStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    19.     SetWindowLong Me.hWnd, GWL_EXSTYLE, lStyle Or WS_EX_LAYERED
    20.  
    21.     SetLayeredWindowAttributes Me.hWnd, 0&, 0&, LWA_ALPHA
    22.     Me.Show
    23.     Timer1.Enabled = True
    24. End Sub
    25.  
    26. Private Sub Timer1_timer()
    27.     Static lAlpha As Long
    28.    
    29.     lAlpha = lAlpha + 3
    30.     SetLayeredWindowAttributes Me.hWnd, 0&, lAlpha, LWA_ALPHA
    31.     If lAlpha = 255 Then Timer1.Enabled = False
    32. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width