Results 1 to 16 of 16

Thread: Transperant Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87

    Transperant Form

    Is there any way that I can make the form transperant (invisible), but can still see the controls I place on there e.g pictures command buttons etc. I use to have an example but it recently got deleted. So can anybody point me in the right direction? Thanks
    "Most cars on our roads have only one occupant, usually the driver."
    - Carol Malia, BBC Anchorwoman

    "I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
    - Jacques le Blanc, French ambassador on nuclear weapons

    "Solutions are not the answer."
    - Richard Nixon, former U.S. President

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Transperant Form

    Here we go
    Attached Files Attached Files


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

  4. #4
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Re: Transperant Form

    Quote Originally Posted by manavo11
    Here we go

    Nice example Manavo11, i needed too!!!
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transperant Form

    Here is another method for semi-transparent forms.
    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. Public Sub AlphaBlendForm(ByVal lHwnd As Long, ByVal intTranslucenceLevel As Integer)
    22.     If APIExists("SetLayeredWindowAttributes", "User32") Then
    23.         SetWindowLong lHwnd, GWL_EXSTYLE, WS_EX_LAYERED
    24.         SetLayeredWindowAttributes lHwnd, 0, intTranslucenceLevel, LWA_ALPHA
    25.     Else
    26.         MsgBox "Your OS does not support Alpha Blending.", vbExclamation, "Alpha Blend"
    27.     End If
    28. End Sub
    29.  
    30. Public Function APIExists(ByVal pstrFunctionName As String, ByVal pstrDllName As String) As Boolean
    31.     Dim lngHandle   As Long
    32.     Dim lngAddr     As Long
    33.     lngHandle = LoadLibrary(pstrDllName)
    34.     If Not (lngHandle = 0) Then
    35.         lngAddr = GetProcAddress(lngHandle, pstrFunctionName)
    36.         FreeLibrary lngHandle
    37.     End If
    38.     APIExists = Not (lngAddr = 0)
    39. End Function
    40.  
    41. Private Sub Form_Load()
    42.     Slider1.Max = 255
    43.     Slider1.Min = 10
    44.     Slider1.LargeChange = 5
    45.     AlphaBlendForm Me.hwnd, 255 'MAX VALUE = OPAIC/ MIN VALUE = 0 CANT SEE
    46.     Slider1.Value = 255
    47. End Sub
    48.  
    49. Private Sub Slider1_Scroll()
    50.     AlphaBlendForm Me.hwnd, Slider1.Value
    51. 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

  6. #6
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Re: Transperant Form

    Yes, but it makes transparent and the controls!

    Zeka needs an example to tranparent the form and still show the controls inside the form!!!
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transperant Form

    Oh, I missed that. I have another example for that but its basically the same APIs that manavo11 posted.

    If you guys want to see it I can post it.
    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

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Transperant Form

    Quote Originally Posted by DarkX_Greece
    Nice example Manavo11, i needed too!!!
    Thanks, although I can't take credit for it

    Rob, I'd like to see an example


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transperant Form

    Here you go. Only four APIs .

    Now that will be $1,000,000.00
    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

  10. #10
    Member
    Join Date
    Jan 2005
    Posts
    58

    Re: Transperant Form

    you think you could make a demo of this form?? casue i tried using your code you posted but i get an error.

    [/img]http://www.vbforums.com/attachment.php?attachmentid=30635[/img]

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transperant Form

    Whats your error? Are you running Windows 2000+? The code I posted is a demo.
    You just need to add a slider control to your project and paste all the code behind the form.

    Project > Components > Controls tab > select "Microsoft Windows Common Controls 6.0", click ok.

    Then in your toolbox add a slider to your form.
    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

  12. #12
    Member
    Join Date
    Jan 2005
    Posts
    58

    Re: Transperant Form

    ok thankz.. lets say i want it on 60.. but i dont want the slider there. how can i make it 60 withload the transparent slider

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transperant Form

    Ok, take the Slider1_Scroll code procedure out and this will replace your Form_Load code.
    VB Code:
    1. Private Sub Form_Load()
    2.     AlphaBlendForm Me.hwnd, 60 'MAX VALUE = OPAIC/ MIN VALUE = 0 CANT SEE
    3. 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

  14. #14
    New Member VBfang's Avatar
    Join Date
    Jan 2005
    Location
    in front of a computor
    Posts
    13

    Re: Transperant Form

    WOW! that is really fun code, but i was woundering, is there any way to remove the box around a lable? i mean so that you could just have words on the screen with out that ugly box?
    here is a question you can never get right:
    "is the answer to this qestion no?"

    "no, i am not crazy... a grown man on his front lawn in a tutu screeming "i'm a cantalope" now that is crazy" - me

  15. #15
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Transperant Form

    Here's an example that gets rid of the label background that I copied from
    Karl E. Peterson http://www.mvps.org/vb
    Anything you want yo make transparent, set color to vbGreen
    Make a project with a form and put a label in the form
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
    4.     ByVal hWnd As Long, _
    5.     ByVal nIndex As Long _
    6. ) As Long
    7.  
    8. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
    9.     ByVal hWnd As Long, _
    10.     ByVal nIndex As Long, _
    11.     ByVal dwNewLong As Long _
    12. ) As Long
    13.  
    14. Private Declare Sub SetWindowPos Lib "user32" ( _
    15.     ByVal hWnd As Long, _
    16.     ByVal hWndInsertAfter As Long, _
    17.     ByVal x As Long, _
    18.     ByVal y As Long, _
    19.     ByVal cx As Long, _
    20.     ByVal cy As Long, _
    21.     ByVal wFlags As Long _
    22. )
    23.  
    24. Private Declare Function SetLayeredWindowAttributes Lib "user32" ( _
    25.     ByVal hWnd As Long, _
    26.     ByVal crKey As Long, _
    27.     ByVal bAlpha As Long, _
    28.     ByVal dwFlags As Long _
    29. ) As Long
    30.  
    31. Private Const GWL_EXSTYLE = (-20)
    32. Private Const WS_EX_LAYERED = &H80000
    33. Private Const LWA_COLORKEY = &H1&
    34. Private Const LWA_ALPHA = &H2&
    35. Private Const LWA_OPAQUE = &HFF&
    36.  
    37. Private Const GWL_STYLE = (-16)
    38. Private Const WS_CAPTION = &HC00000
    39. Private Const WS_THICKFRAME = &H40000
    40.  
    41. Private Const HWND_TOPMOST = -1
    42. Private Const SWP_NOSIZE = &H1
    43. Private Const SWP_NOMOVE = &H2
    44. Private Const SWP_NOACTIVATE = &H10
    45. Private Const SWP_SHOWWINDOW = &H40
    46. Private Const SWP_NOZORDER = &H4
    47. Private Const SWP_FRAMECHANGED = &H20
    48.  
    49. Private m_ColorKey As OLE_COLOR
    50.  
    51. Private Declare Function GetSysColor Lib "user32" ( _
    52.     ByVal nIndex As Long _
    53. ) As Long
    54.  
    55. Private Function CheckSysColor(ByVal ColorRef As OLE_COLOR) As Long
    56.    Const HighBit = &H80000000
    57.    If ColorRef And HighBit Then
    58.       CheckSysColor = GetSysColor(ColorRef And Not HighBit)
    59.    Else
    60.       CheckSysColor = ColorRef
    61.    End If
    62. End Function
    63.  
    64. Private Function MakeTransparent(ByVal hWnd As Long) As Boolean
    65.    Dim nStyle As Long
    66.    If hWnd Then
    67.       nStyle = GetWindowLong(hWnd, GWL_EXSTYLE) And Not WS_EX_LAYERED
    68.          If SetWindowLong(hWnd, GWL_EXSTYLE, nStyle) Then
    69.             nStyle = nStyle Or WS_EX_LAYERED
    70.             If SetWindowLong(hWnd, GWL_EXSTYLE, nStyle) Then
    71.                      MakeTransparent = CBool(SetLayeredWindowAttributes( _
    72.                      hWnd, CheckSysColor(m_ColorKey), _
    73.                      0, _
    74.                      LWA_COLORKEY))
    75.             End If
    76.          End If
    77.    End If
    78. End Sub
    79.  
    80. Private Function ToggleCaption(ByVal Value As Boolean) As Boolean
    81.    Dim nStyle As Long
    82.    
    83.    ' Retrieve current style bits.
    84.    nStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
    85.    ' Set WS_SYSMENU On or Off as requested.
    86.    If Value Then
    87.       nStyle = nStyle Or WS_CAPTION Or WS_THICKFRAME
    88.    Else
    89.       nStyle = nStyle And Not WS_CAPTION
    90.       nStyle = nStyle And Not WS_THICKFRAME
    91.    End If
    92.    
    93.    ' Try to set new style.
    94.    If SetWindowLong(Me.hWnd, GWL_STYLE, nStyle) Then
    95.       If nStyle = GetWindowLong(Me.hWnd, GWL_STYLE) Then
    96.          ToggleCaption = True
    97.       End If
    98.    End If
    99.    ' Redraw window with new style.
    100.    SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE
    101. End Function
    102.  
    103. Private Sub Command1_Click()
    104. Unload Me
    105.  
    106. End Sub
    107.  
    108. Private Sub Form_Load()
    109. 'setup label
    110.     Label1.AutoSize = True
    111.     Label1.Caption = "Click Me"
    112.  
    113. 'make transparent
    114.      'Toggle titlebar off.
    115.       Call ToggleCaption(False)
    116.            
    117.       m_ColorKey = vbGreen
    118.       MakeTransparent Me.hWnd
    119.      
    120.       ' Set backgrounds to green so they
    121.       ' become transparent too.
    122.       Me.BackColor = vbGreen
    123.       Label1.BackColor = vbGreen
    124.      
    125. End Sub
    126.  
    127. Private Sub Label1_Click()
    128.   Unload Me
    129. End Sub

  16. #16
    New Member VBfang's Avatar
    Join Date
    Jan 2005
    Location
    in front of a computor
    Posts
    13

    Re: Transperant Form

    wow! cool, thanks alot, that is some realy usefull code

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