Flux rss

[VB6] Making a form transparent

Published by netty5, last update on Wednesday November 19, 2008 07:20:06 AM by netty5

[VB6] Making a form transparent





Getting started


Here is a brief explanation on how to use the transparency based upon:
The desired format, including controls, according to a ratio.
Having the bottom of the form be invisible and controls, according to a ratio.

Restriction


Does not work on color having negative sign.
A color palette must be included.

In a module


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 crKey As Long, ByVal bDefaut As Byte, ByVal dwFlags As Long) As Long

Private Const GWL_EXSTYLE       As Long = (-20)
Private Const LWA_COLORKEY      As Long = &H1
Private Const LWA_Defaut         As Long = &H2
Private Const WS_EX_LAYERED     As Long = &H80000

'
Public Function Transparency(ByVal hWnd As Long, Optional ByVal Col As Long = vbBlack, _
    Optional ByVal PcTransp As Byte = 255, Optional ByVal TrMode As Boolean = True) As Boolean
' Return : True if there is no error.
' hWnd   : hWnd of the window to make transparent
' Col : Color to make transparent if TrMode=False
' PcTransp  : 0 à 255 >> 0 = transparent  -:- 255 = Opaque
Dim DisplayStyle As Long
    On Error GoTo Exit
    VoirStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
    If DisplayStyle<> (DisplayStyle Or WS_EX_LAYERED) Then
        DisplayStyle = (DisplayStyle Or WS_EX_LAYERED)
        Call SetWindowLong(hWnd, GWL_EXSTYLE, DisplayStyle)
    End If
    Transparency = (SetLayeredWindowAttributes(hWnd, Col, PcTransp, IIf(TrMode, LWA_COLORKEY Or LWA_Defaut, LWA_COLORKEY)) <> 0)
    
Exit:
    If Not Err.Number = 0 Then Err.Clear
End Function

Public Sub ActiveTransparency(M As Form, d As Boolean, F As Boolean, _
     T_Transparency As Integer, Optional Color As Long)
Dim B As Boolean
        If d And F Then
        'Makes color (here the background color of the shape) transparent
        'upon value of T_Transparency
            B = Transparency(M.hWnd, Color, T_Transparency, False)
        ElseIf d Then
            'Makes form, including all components, transparent
            'upon value of T_Transparency
            B = Transparency(M.hWnd, 0, T_Transparency, True)
        Else
            'Restores the form opaque.
            B = Transparency(M.hWnd, , 255, True)
        End If
End Sub

As used in a form


Private Sub Form_Load()
Dim i As Integer
    'Ex: all transparent at ratio 140/255
    'ActiveTransparency Me, True, False, 140, Me.BackColor
    'Ex: Form transparent, visible component at ratio 140/255
    'ActiveTransparency Me, True, True, 140, Me.BackColor
    
    'Example display the form transparency degradation
    ActiveTransparency Me, True, False, 0
    Me.Show
    For i = 0 To 255 Step 3
        ActiveTransparency Me, True, False, i
        Me.Refresh
    Next i
End Sub
Video and digital imaging - The MKV format The MKV format (Matroska Video) is an entirely free video format. More precisely, it is a container (hence the name Matroska, in reference to the Russian dolls contained within another) making it possible to contain video (DivX, Xvid, RV9, etc),... en.kioskea.net/video/mkv-matroska.php3
Download HP USB Disk Storage Format Tool HP USB Disk Storage Format Tool is a small utility allowing to format a key USB or READER MP4. It also allows to make a key (Bootable). This software works with all keys and readers MP4 of the market. To make work this utility under Windows... en.kioskea.net/telecharger/telecharger-127-hp-usb-disk-storage-format-tool
Download Stereo Movie Maker Several cameras in digital mode have two modes videos that is a resolution 320x240 or 640x480 and among which the most part record videos in the .MOV format of Quick Time. StereoMovie Maker can read these videos with a program of assistant called... en.kioskea.net/telecharger/telecharger-432-stereo-movie-maker
Formatting with start up diskFormatting with start up disk Before Formatting Back of your important data Verify that you have all in hand Make sure the boot disk starts with the CD player Formatting Before Formatting Back of your import en.kioskea.net/faq/sujet-971-formatting-with-start-up-disk
[Google]Searching for files using a specific format[Google]Searching for files using a specific format Some files are easier to find when looking for them as a specific format, E.g as a manufacturer documentation often (in pdf format). To make use of this feature of Google just use the... en.kioskea.net/faq/sujet-1058-google-searching-for-files-using-a-specific-format
Verifying date format in PHPVerifying date format in PHP There are several ways to check the format of a date in PHP; the simplest method is to make use regular expressions. To confirm a date format DD/MM/YYYY, where the days and/or month can be given as single... en.kioskea.net/faq/sujet-999-verifying-date-format-in-php
Date format in excel.Hello again, Is there a way to make excel read fields left padded with a 0. For example I have a program that only reads date format like this yymmdd, so when I open the csv file in excel it reads 080725 as 80725 instead. Then when I save any changes... en.kioskea.net/forum/affich-16756-date-format-in-excel
Conditional formating - apply on more cellsHello, i'm not so familiar with conditional formatting, so i would like to ask something: I'm making a doc where Column A has number values, column B also numbers, of rank positions. Conditional formating of cell in column B would be: if... en.kioskea.net/forum/affich-41481-conditional-formating-apply-on-more-cells
Video formattingHello, Actually doing some video formatting @ work hmmm i wanted to if you have any suggestion of the best software to use. I have to make small cut of 5 mins and then format into avi. en.kioskea.net/forum/affich-43403-video-formatting
Download Free Sound RecorderFree Sound Recorder makes exactly that his name says. He allows to record all sounds which take out sound from your card free. Files can be directly exported in format MP3, WAV or WMA. Free Sound Recorder is the ideal tool to record your own voice... en.kioskea.net/telecharger/telecharger-447-free-sound-recorder
Download Network NotepadSimple, efficient, free:-) to simplify a small network, network notepad proves to be enough efficiency. He allows to export schemata accomplished in format BMP, GIF or else PNG. He allows furthermore to make pings, to establish connections telnet... en.kioskea.net/telecharger/telecharger-321-network-notepad
Download StaxRip StaxRip is a free software to convert your DVD. With this tool, you can easily convert into MPEG-4 your DVD, make captures of DVB, or convert from other formats as DivX, XviD and x264. StaxRip is completely customizable and can put on in day... en.kioskea.net/telecharger/telecharger-399-staxrip
EU to scrutinise Microsoft's promise to open up OfficeMicrosoft software on sale a MicroCenter computer store in Fairfax, Virginia. The European Commission has said it will scrutinise a decision by Microsoft to make its Office programme compatible with a rival document format. The European Commission... en.kioskea.net/actualites/eu-to-scrutinise-microsoft-s-promise-to-open-up-office-10396-actualite.php3
EU to scrutinise Microsoft's promise to open up OfficeMicrosoft software on sale a MicroCenter computer store in Fairfax, Virginia. The European Commission said it would scrutinise a decision by Microsoft to make its Office programme compatible with a rival document format. The European Commission said... en.kioskea.net/actualites/eu-to-scrutinise-microsoft-s-promise-to-open-up-office-10397-actualite.php3
Video and digital imaging - The DivX format The DivX is a video compression/decompression format which allows videos to be compressed to very small volumes with a quite reasonable loss of quality. Thus, the DivX format makes it possible to store a complete film on a 650 or 700 MB CD-ROM. The... en.kioskea.net/video/divx.php3
Email This is one of the most widely used services on the internet making it possible to send messages in the form of a text file. The Académie française uses the name "mél" while the Canadians (generally more imaginative) have adopted the name "courriel".... en.kioskea.net/utile/email.php3
Attacks - False HTPP data Most web application attacks involving soliciting a website with manually entered data to generate an unexpected context. The HTTP protocol, a communication protocol on the web, makes it possible to convey parameters in the form of requests; it can... en.kioskea.net/attaques/falsification-donnees.php3