Is it possible to create a form that is semi transparent, It should be visible over any open windows, not hidden behind ? Please guide!
'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
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