Results 1 to 7 of 7

Thread: Transparent

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Does anyone can show me how to make a transparent Form?

    Thanks

  2. #2
    Guest
    To make a form transparent:


    Code:
    Private Declare Function SetWindowLong _
    Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As _
    Long, ByVal nIndex As Long, ByVal dwNewLong As _
    Long) As Long
    
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_transparent = &H20&
    
    
    Private Sub Form_Activate()
        SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_transparent
    End Sub

  3. #3

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Wow, Thanks Matthew, it work grate.
    By the way, what wrong with you Status after my long break from VB World Forum.

  4. #4
    Guest
    I don't have a status anymore. I hated being judged by my title, so I chose not to have one. As Megatron, chose to have one, other than Guru. His is Decepticon which a group that Megatron was the leader of in this animated series.

  5. #5
    Guest
    Transformers!

  6. #6

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Matthew and Megatron, when I'll have a chance to edit my status by myself?

  7. #7
    Member
    Join Date
    Feb 2001
    Location
    Kerala, India
    Posts
    42

    Talking Lets Try this code

    'module : mdlTransparent.bas
    'description : This module contains functions to make a form transparent
    'author : (pramod kumar)I don't know who actualy written this code (I made some changes)
    'e-mail : [email protected]


    Option Explicit
    Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
    Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
    Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Public Const RGN_OR = 2
    Public Const WM_NCLBUTTONDOWN = &HA1
    Public Const HTCAPTION = 2

    Public Function MakeRegion(picSkin As PictureBox) As Long

    ' Make a windows "region" based on a given picture box'
    ' picture. This done by passing on the picture line-
    ' by-line and for each sequence of non-transparent
    ' pixels a region is created that is added to the
    ' complete region. I tried to optimize it so it's
    ' fairly fast, but some more optimizations can
    ' always be done - mainly storing the transparency
    ' data in advance, since what takes the most time is
    ' the GetPixel calls, not Create/CombineRgn

    Dim X As Long, Y As Long, StartLineX As Long
    Dim FullRegion As Long, LineRegion As Long
    Dim TransparentColor As Long
    Dim InFirstRegion As Boolean
    Dim InLine As Boolean ' Flags whether we are in a non-tranparent pixel sequence
    Dim hDC As Long
    Dim PicWidth As Long
    Dim PicHeight As Long

    hDC = picSkin.hDC
    PicWidth = picSkin.ScaleWidth
    PicHeight = picSkin.ScaleHeight

    InFirstRegion = True: InLine = False
    X = Y = StartLineX = 0

    ' The transparent color is always the color of the
    ' top-left pixel in the picture. If you wish to
    ' bypass this constraint, you can set the tansparent
    ' color to be a fixed color (such as pink), or
    ' user-configurable
    TransparentColor = GetPixel(hDC, 0, 0)

    For Y = 0 To PicHeight - 1
    For X = 0 To PicWidth - 1

    If GetPixel(hDC, X, Y) = TransparentColor Or X = PicWidth Then
    ' We reached a transparent pixel
    If InLine Then
    InLine = False
    LineRegion = CreateRectRgn(StartLineX, Y, X, Y + 1)

    If InFirstRegion Then
    FullRegion = LineRegion
    InFirstRegion = False
    Else
    CombineRgn FullRegion, FullRegion, LineRegion, RGN_OR
    ' Always clean up your mess
    DeleteObject LineRegion
    End If
    End If
    Else
    ' We reached a non-transparent pixel
    If Not InLine Then
    InLine = True
    StartLineX = X
    End If
    End If
    Next
    Next

    MakeRegion = FullRegion
    End Function

    'module : frmTransparent.frm
    'description : This form should contain a picture box and its picture should set runtime
    ' or design time
    'author : (pramod kumar)
    'e-mail : [email protected]
    Option Explicit
    Dim WindowRegion As Long
    Private Sub Form_Load()
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True
    Picture1.AutoSize = True
    Picture1.BorderStyle = vbBSNone
    Me.BorderStyle = vbBSNone
    'Set Picture1.Picture = LoadPicture("c:\windows\desktop\trans.bmp")
    WindowRegion = MakeRegion(Picture1)
    Picture1.Top = 0
    Picture1.Left = 0
    Me.Width = Picture1.Width
    Me.Height = Picture1.Height
    SetWindowRgn hWnd, WindowRegion, True
    End Sub
    GetHelp <-> LetHelp

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