Results 1 to 8 of 8

Thread: TransParent Form Q.

  1. #1

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    TransParent Form Q.

    Ive searched on the forums, and havent found what i needed. Ive been working on an mp3 player, and am basically done with it, but forgot about the whole transparent form part of it. I have everything but the controls as one picture, the forms picture, is there a way to just take one color of it and make it transparent? Or will i have to go back to bitblt, or setwindowlong or something?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: TransParent Form Q.

    If you are using XP/2000, you can use Alpha Blending to make transparencies.
    Here is a demo project that uses it.

    http://www.vbforums.com/attachment.p...chmentid=36096

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: TransParent Form Q.

    VB Code:
    1. Option Explicit
    2. Const WM_NCLBUTTONDOWN = &HA1
    3. Const HTCAPTION = 2
    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" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    9. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    10. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    11.  
    12. Private Sub Form_Load()
    13.  Dim Ret As Long
    14.     'Set the window style to 'Layered'
    15.     Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    16.     Ret = Ret Or WS_EX_LAYERED
    17.     SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    18.     'Set the opacity of the layered window to 128
    19. SetLayeredWindowAttributes Me.hWnd, 0, 100, LWA_ALPHA
    20. End Sub

    makes a form transparent..hope thats what you needed

  4. #4

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: TransParent Form Q.

    oops, sorry, i used the wrong terms, I want to mask a color on the forms picture to be transparent. Thanks for the alpha blending tips though, that will also come in handy.

  5. #5
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: TransParent Form Q.

    the only way i can think of is using getpixel and finding if the color is you color then changing it...but that is really slow

  6. #6

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: TransParent Form Q.

    Should i use bitblt then?

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: TransParent Form Q.

    Here is a mask program.
    Attached Files Attached Files

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: TransParent Form Q.

    Also if you would like to apply that sort of thing to a form you can pass an RGB colour key value to the SetLayeredWindowAttributes API call and then only pixels of that colour on your form will be drawn alpha-blended.

    e.g.
    VB Code:
    1. ' LWA_COLORKEY = &H1
    2. SetLayeredWindowAttributes Me.hWnd, RGB(0, 0, 0), 100, LWA_ALPHA Or LWA_COLORKEY
    ... makes all black pixels alpha-blended.

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