Results 1 to 16 of 16

Thread: Menubar/Transparency/Etc..

  1. #1

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Arrow Menubar/Transparency/Etc..

    I tried checking out the other threads I could find regarding form transparency for VB6.0, but I can't quite find the answer I'm looking for..

    How would I go about setting a form's window background to transparency, whereas all other controls and objects remain fully visible enabled and accessable.. In essence doing a cutout of the unneeded part of my form window.

    My part of the app in question is a toolbar-ish form that sits at the top of the screen using always-on-top api to hold it in view.. but I need transparency for the rest of it..

    Also, a side note.. how could I introduce a label/picturebox on top of the menubar on the far left side?..

    Great thanks in advance

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

    Re: Menubar/Transparency/Etc..

    There are a couple of ways to make a form transparent, here is just one.
    Put a label on a 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 Function
    79.  
    80. Private Function ToggleCaption(ByVal Value As Boolean) As Boolean
    81.    Dim nStyle As Long
    82.       ' Retrieve current style bits.
    83.    nStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
    84.    ' Set WS_SYSMENU On or Off as requested.
    85.    If Value Then
    86.       nStyle = nStyle Or WS_CAPTION Or WS_THICKFRAME
    87.    Else
    88.       nStyle = nStyle And Not WS_CAPTION
    89.       nStyle = nStyle And Not WS_THICKFRAME
    90.    End If
    91.       ' Try to set new style.
    92.    If SetWindowLong(Me.hWnd, GWL_STYLE, nStyle) Then
    93.       If nStyle = GetWindowLong(Me.hWnd, GWL_STYLE) Then
    94.          ToggleCaption = True
    95.       End If
    96.    End If
    97.    ' Redraw window with new style.
    98.    SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE
    99. End Function
    100.  
    101. Private Sub Form_Load()
    102. 'setup label
    103.     Label1.AutoSize = True
    104.     Label1.Caption = "Click Me"
    105.  
    106. 'make transparent
    107.      'Toggle titlebar off.
    108.       'Call ToggleCaption(False)
    109.            
    110.       m_ColorKey = vbGreen
    111.       MakeTransparent Me.hWnd
    112.      
    113.       ' Set backgrounds to green so they
    114.       ' become transparent too.
    115.       Me.BackColor = vbGreen
    116.       Label1.BackColor = vbGreen
    117.      
    118. End Sub
    119.  
    120. Private Sub Label1_Click()
    121. Unload Me
    122. End Sub

  3. #3
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346

    Re: Menubar/Transparency/Etc..

    This should conatin everything you'll need...
    Attached Files Attached Files
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  4. #4

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Re: Menubar/Transparency/Etc..

    Thanks, I'll look into that
    IWS

  5. #5
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Menubar/Transparency/Etc..

    I am having exactly the same problem and neither of theese axamples works for me.

    What I need is a truly transparant form, not a form that is a hole.
    It realy should work as a pane of glass, you can see what is below it but you can't touch it, mouseclicks and so on should not affect the underlaying objects

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

    Re: Menubar/Transparency/Etc..

    you might want to do something like this
    http://www.vbforums.com/showthread.php?t=368322

  7. #7
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Menubar/Transparency/Etc..

    Yes! thats the type of function I want but now I need a method to get it to update itself without flickering all to much
    Last edited by mats42; Dec 23rd, 2005 at 01:56 PM.

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

    Re: Menubar/Transparency/Etc..

    good luck

  9. #9
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Menubar/Transparency/Etc..

    I could use it for a full screen.

    I have some code that will copy everything displayed on the desktop and put that as my background. It's just one "smaller" problem that it catches my window to...

  10. #10
    Lively Member
    Join Date
    Dec 2003
    Location
    Mucia, Sunny Spain
    Posts
    111

    Re: Menubar/Transparency/Etc..

    This isn’t an attempt to hijack the thread but, as it happens, I’ve been struggling to do much the same thing for a day or two..... Moeur’s code (above) nearly works for me except that label1’s background remains as bilious green instead of transparent. Did I set a property wrong somewhere? If only it could be made to be transparent I’d be happy.

    Dave

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

    Re: Menubar/Transparency/Etc..

    Dave,

    If you want to zip up all the files from the project and upload them I can look at what you did.

  12. #12
    Lively Member
    Join Date
    Dec 2003
    Location
    Mucia, Sunny Spain
    Posts
    111

    Re: Menubar/Transparency/Etc..

    Moeur,

    Sorry for the delay in answering (Christmas festivities/multiple lagers getting in the way) but I’ve managed to sort it all out now.

    1) I’d set the form properties to ‘no border’ (because that’s what I thought wanted) but the transparency works with all form types except ‘no border’ ….
    2) Having set the border property to something else I just un-commented the 'Call ToggleCaption(False)’ line – to make the border transparent - and everything works fine.

    A lovely bit of code. Thanks for sharing.

    ATB

    Dave

  13. #13
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Menubar/Transparency/Etc..

    I'm making progress!

    Currently I'm using a "hole" form and api calls to get thou mouseposition, mousebuttonstate and windowstate.

    Currently it will detect a click through my app and reset focus back to my app. It's not truely glass but it will do the jobb. The major problem was to handle mouseclicks when another app wa laying above. Since I use api calls i still got those clicks to but by checking active window that can be handled

  14. #14
    Lively Member Tegan's Avatar
    Join Date
    Jun 2005
    Location
    Lincoln, NE
    Posts
    108

    Re: Menubar/Transparency/Etc..

    Am I understanding you correctly?

    You want the form background to be transparent and you want all clicks to the transparent part to be passed to the form underneath? If this is all you need to do, and you don't need any other fancy options like dragging the transparent form by its controls, the answer is simple. I have a code snippet on my computer right now thats not more than 30 lines long and it produces true transparency. Controls on forms beneath can be clicked and I believe you can even adjust the degree of transparency from 0% to 100%. If this sounds useful to you, I'll post the code. Maybe it'll save you a lot of time because I know it took me a long time to figure out how to do that.
    Tegan Snyder

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

    Re: Menubar/Transparency/Etc..

    I think he wants the other way.
    Controls under transparent part must not be clicked.

  16. #16
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Menubar/Transparency/Etc..

    exactly

    I need a pane of glass in vb. See but not touch whats behind it. And with the option to place controls on this pane of glass to.

    One applikation is to overlay a presentation from another system and add functions to certain ponts of that presentation

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