VB6 Transparency

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aviraldg
    New Member
    • Sep 2007
    • 21

    VB6 Transparency

    In VB6 , is it possible to have the form invisible but the things inside it visible?
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by aviraldg
    In VB6 , is it possible to have the form invisible but the things inside it visible?
    You have to use windows api in VB6:

    Declarations:
    Code:
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32"  Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long,  ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_LAYERED = &H80000
    Private Const LWA_ALPHA = &H2&
    Using the api:
    Code:
     Dim bytOpacity As Byte       'Set the transparency level    
    bytOpacity = 128    
    Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)    
    Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, LWA_ALPHA)

    finally, restoring the windows opacity;

    Code:
     Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And (Not WS_EX_LAYERED))
    Reference: http://articles.techrepublic.com.com...-5031805.html#

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Originally posted by VBPhilly
      You have to use windows api in VB6:

      Declarations:
      Code:
      Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
      Private Declare Function SetWindowLong Lib "user32"  Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long,  ByVal dwNewLong As Long) As Long
      Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
      Private Const GWL_EXSTYLE = (-20)
      Private Const WS_EX_LAYERED = &H80000
      Private Const LWA_ALPHA = &H2&
      Using the api:
      Code:
       Dim bytOpacity As Byte       'Set the transparency level    
      bytOpacity = 128    
      Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)    
      Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, LWA_ALPHA)

      finally, restoring the windows opacity;

      Code:
       Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And (Not WS_EX_LAYERED))
      Reference: http://articles.techrepublic.com.com...-5031805.html#
      I've used that method before, but is it possible to make the Form transparente while the controls in it are not?
      That'll be really cool

      Comment

      • VBPhilly
        New Member
        • Aug 2007
        • 95

        #4
        Originally posted by kadghar
        I've used that method before, but is it possible to make the Form transparente while the controls in it are not?
        That'll be really cool
        I see what you mean. That would be cool.

        I dont know of any quick way.

        Although, if your desktop is black, you could simply make your form black.

        Another idea is to make your visible controls become forms themselves (make the form borderless and the same size as the visible control) and layer them on top of the transparent form. Thats alot of form tracking though.

        Anyway, good luck with it.

        Comment

        • aviraldg
          New Member
          • Sep 2007
          • 21

          #5
          Thanks guys ,but
          1) I'd tried the Control-is-a-form method before posting here...But what if you have a circle shape?I Doubt you can have circular forms...
          2) I'll try the API Functions Later...
          3) <Not Related : How do you add bytes?>

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by aviraldg
            1) I'd tried the Control-is-a-form method before posting here...But what if you have a circle shape?I Doubt you can have circular forms...
            I think you can. I've seen a demo of a circular clock or something, which was done just to show off differently-shaped windows. Try a quick search for expressions like "round clock". It may have even been mentioned previously on TheScripts, so you can try our search box up the top.

            Originally posted by aviraldg
            2) I'll try the API Functions Later...
            3) <Not Related : How do you add bytes?>
            To what?

            By the way, one way you might be able to simulate a transparent form is by taking a snapshot of the screen before displaying your form (standard stuff when writing a screensaver) then paint that picture (appropriately positioned) onto your form.

            Oh, one other thing. I didn't read the code form that link (don't have time) but is it possible that it could be applied to one or more controls? That is, set the form to transparent, then set control(s) to non-transparent?

            Comment

            • aviraldg
              New Member
              • Sep 2007
              • 21

              #7
              Set the form to invisible and the controls visible
              Pre-Tried,Useless
              Nothing found " Round forms";"Circula r Forms"

              Comment

              • VBPhilly
                New Member
                • Aug 2007
                • 95

                #8
                Originally posted by aviraldg
                Pre-Tried,Useless
                Nothing found " Round forms";"Circula r Forms"
                Good old irregular shaped forms.
                check out this link:
                Create irregularly shaped forms and forms with holes in them from VB using Windows regions

                Comment

                • aviraldg
                  New Member
                  • Sep 2007
                  • 21

                  #9
                  Thank you
                  <:TOPIC SOLVED:>

                  Comment

                  Working...