Results 1 to 6 of 6

Thread: Opacity in VB 6.0

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96

    Opacity in VB 6.0

    I was wondering if there is a simple way to change opacity in VB 6.0 in VB.Net it's very simple just form1.opacity=%%

    If not it's cool
    It is like wiping your ass with silk, I love it!

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Here is some code that I got off of the forums, but modified. Slide
    the slider control to make your form change in opacity. This will
    work on Win2k +

    VB Code:
    1. Option Explicit
    2. 'Add a slider control to the project (Slider1)
    3. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
    4. (ByVal lpLibFileName As String) As Long
    5.  
    6. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
    7. ByVal lpProcName As String) As Long
    8.  
    9. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    10.  
    11. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    12. (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    13.  
    14. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, _
    15. ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    16.  
    17. Private Const GWL_EXSTYLE = (-20)
    18. Private Const WS_EX_LAYERED = &H80000
    19. Private Const LWA_ALPHA = &H2
    20.  
    21. Private mlHwnd As Long
    22.  
    23. Public Sub AlphaBlendForm(ByVal lHwnd As Long, ByVal intTranslucenceLevel As Integer)
    24.     If APIExists("SetLayeredWindowAttributes", "User32") Then
    25.         SetWindowLong lHwnd, GWL_EXSTYLE, WS_EX_LAYERED
    26.         SetLayeredWindowAttributes lHwnd, 0, intTranslucenceLevel, LWA_ALPHA
    27.     Else
    28.         MsgBox "Your OS does not support Alpha Blending.", vbExclamation, "Alpha Blend"
    29.     End If
    30. End Sub
    31.  
    32. Public Function APIExists(ByVal pstrFunctionName As String, ByVal pstrDllName As String) As Boolean
    33.     Dim lngHandle   As Long
    34.     Dim lngAddr     As Long
    35.     lngHandle = LoadLibrary(pstrDllName)
    36.     If Not (lngHandle = 0) Then
    37.         lngAddr = GetProcAddress(lngHandle, pstrFunctionName)
    38.         FreeLibrary lngHandle
    39.     End If
    40.     APIExists = Not (lngAddr = 0)
    41. End Function
    42.  
    43. Private Sub Form_Load()
    44.     Slider1.Max = 255
    45.     Slider1.Min = 10
    46.     Slider1.LargeChange = 5
    47.     If mlHwnd = 0 Then
    48.         mlHwnd = Me.hwnd
    49.     End If
    50.     AlphaBlendForm mlHwnd, 255 'MAX VALUE = OPAIC/ MIN VALUE = 0 CANT SEE
    51.     Slider1.Value = 255
    52. End Sub
    53.  
    54. Private Sub Slider1_Scroll()
    55.     AlphaBlendForm mlHwnd, Slider1.Value
    56. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Forgot the attachment!

    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96
    Ii'm going to modify your code even further and make it vary depending on a timer, then when the user opens or closes my program it fades in or out respectively...THANKS!!
    It is like wiping your ass with silk, I love it!

  5. #5
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    No prob. Your making it like Outlooks email notification
    window which popsup and fades over a certain number of
    seconds. I always did like that effect! With Outlooks it goes 100%
    opaic when you mouse over it and resumes fading when you
    mouseout. Maybe add that effect too.


    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96
    Good idea, except i'm not doing this for idle programs, i'm doin this for a cool intro to my prog, i know it's flashy and no one cares, but i like it lol

    Thanks!! I'll mess with it some more!!
    It is like wiping your ass with silk, I love it!

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