tags:

views:

56

answers:

2

Is it possible to create a form that is semi transparent, It should be visible over any open windows, not hidden behind ? Please guide!

+3  A: 

Sure, see Karl Peterson's "Translucent" example: http://vb.mvps.org/samples/Translucent/

To keep the form visible over other windows, you want to use the SetWindowPos API function.

Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const OnTopFlags = SWP_NOMOVE Or SWP_NOSIZE

Public Sub FormOnTop(frm As Form)
    Call SetWindowPos(frm.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, OnTopFlags)
End Sub
Joe
Sorry but it did not help.I downloaded the code from the link provided and pasted the code provided by Joe.But if a new window, say any browser is opened it hides behind the browser window.
Dario Dias
GSerg - I searched google for the code but only found codes to make the form window translucent not what I want.Translucent over all windows not hidden similar to bandwidth meters where the graphs are shown over the browser windows.
Dario Dias
I would look at the example and code I posted again; you can use the CTranslucent class in your project and simply call for transparency on any form_load you wish. Also on form_load, call the FormOnTop function using the Me object, i.e. "Call FormOnTop(Me)"
Joe
Thanks Joe. the form_load code Call FormOnTop(Me) worked perfectly.Please edit the code in the answer provided so that I can tick your answer.
Dario Dias
A: 
'function to make transparent'

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long,ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

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 Const G = (-20)
Private Const LWA_COLORKEY = &H1        'to trans'
Private Const LWA_ALPHA = &H2           'to semi trans'
Private Const WS_EX_LAYERED = &H80000

Private Sub Form_Activate()
    Me.BackColor = vbBlue
    Trans 1
End Sub

Private Sub Trans(Level As Integer)
    Dim Msg As Long
    Msg = GetWindowLong(Me.hwnd, G)
    Msg = Msg Or WS_EX_LAYERED
    SetWindowLong Me.hwnd, G, Msg
    SetLayeredWindowAttributes Me.hwnd, vbBlue, Level, LWA_COLORKEY
End Sub
dave