We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,398 times

Related Categories

Making Windows Transparent

-=D=-

Here's some code demonstrating how to make a form in VB transparent!

Option Explicit

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
 lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()

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 bAlpha As Byte, _
 ByVal dwFlags As Long) As Long

Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1


Private Sub Form_Load()
DarkMe
End sub

Public Function DarkMe()
Dim rtn As Long
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 200, LWA_ALPHA
End Function

Comments

  • Re:

    Posted by armandolanda on 02 Feb 2008

    As you will see, if you change the window style in the form load event,
    then the bitblting becomes very choppy.  If you wait and change the
    window style in the form unload event, just before...

  • pllease help me

    Posted by jc_23 on 07 Mar 2007

    Im a computer student and I have a case study which is i will connect my databased to Media Player anyone can elp me please?..

  • Good Code

    Posted by Twitchell on 12 Aug 2005

    Thanks for the code. Works a treat, but the form is not entirely transparent - just semi-transparent

  • Posted by Joe C on 02 Aug 2004

    Yes, thanks for the help. The following code is an example of the problem:

    Option Explicit

    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByV...

  • Posted by -=D=- on 30 Jul 2004

    if possible, can u send the code to me? maybe i wil help u to solve the problem

    again, when u use the code, it wil slow ur application down.