23/08/08 12:39
gaffre
Ciao a tutti!
Prima di fare questa domanda ho un po' cercato tra i topic vecchi e non ho trovato l'effetto desiderato. Vorrei sapere se c'è un modo per far diventare il form e/o i pulsanti un po' trasparenti tipo 40%, oppure il form 60 e il resto degli oggetti 40. Insomma qualcosa del genere è possibile?
Grazie
aaa
23/08/08 12:51
penso non esista in vb6, forse in delphi o vb.net,
ma non credo
cmq io penso di no
23/08/08 13:58
GrG
invece è possibile:
in un modulo:
Option Explicit
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 UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, 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 GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000
Public Function isTransparent(ByVal hWnd As Long) As Boolean
On Error Resume Next
Dim Msg As Long
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED Then
isTransparent = True
Else
isTransparent = False
End If
If Err Then
isTransparent = False
End If
End Function
Public Function MakeTransparent(ByVal hWnd As Long, Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next
If Perc < 0 Or Perc > 255 Then
MakeTransparent = 1
Else
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
Msg = Msg Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hWnd, 0, Perc, LWA_ALPHA
MakeTransparent = 0
End If
If Err Then
MakeTransparent = 2
End If
End Function
Public Function MakeOpaque(ByVal hWnd As Long) As Long
Dim Msg As Long
On Error Resume Next
Msg = GetWindowLong(hWnd, GWL_EXSTYLE)
Msg = Msg And Not WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hWnd, 0, 0, LWA_ALPHA
MakeOpaque = 0
If Err Then
MakeOpaque = 2
End If
End Function
poi nel form:
Private Sub Form_Load()
MakeTransparent Me.hWnd, VALORE da 0 a 255
End Sub
dove ho scritto VALORE da 0 a 255 più il numero starà vicino al 255 e più il form sarà visibile, più il numero si avvicinerà allo 0 più il form sarà trasparente. (mi pare sia così l'ordine).
Ultima modifica effettuata da GrG 23/08/08 13:58
aaa
24/08/08 11:58
gaffre
effetto magnifico, veramente splendido grazie!
aaa
05/10/08 13:32
super rambo
Scusate se rispondo ad un topic vecchio e non ne apro uno nuovo.. ho provato il codice, e funziona. per impostare la trasparenza ho aggiunto una una slider con questo codice:
Private Sub Slider1_Scroll()
MakeTransparent Form2.hwnd, Slider1.Value
End Sub
vorrei sapere come fare ad annullare l'effetto perchè se metto la slider al massimo un pò di trasparenza rimane sempre io vorrei che tramite un command l'effetto svanisca..si può fare??
Ultima modifica effettuata da super rambo 05/10/08 13:34
aaa
05/10/08 14:04
GrG
se lo fai manualmente (mettendo 255) rimane semprel a trasparenza?
aaa