Aussiebear
03-23-2008, 04:23 AM
I found the following code at Colo's but it fails to change the transparency.
Private Declare Function GetActiveWindow Lib "USER32" () As Long
Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal lngWinIdx As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal lngWinIdx As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "USER32" _
(ByVal hWnd As Long, ByVal crKey As Integer, ByVal bAlpha As Integer, _
ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC
Dim hWnd As Long
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub ScrollBar1_Change()
Call Semitransparent(Me.ScrollBar1.Value)
End Sub
Private Sub UserForm_Activate()
Me.ScrollBar1.Value = 50
End Sub
Private Sub Semitransparent(ByVal intLevel As Integer)
Dim lngWinIdx As Long
hWnd = GetActiveWindow
lngWinIdx = GetWindowLong(hWnd, GWL_EXSTYLE)
SetWindowLong hWnd, GWL_EXSTYLE, lngWinIdx Or WS_EX_LAYERED
SetLayeredWindowAttributes hWnd, 0, ((255) * intLevel) / 100, LWA_ALPHA
Label1.Caption = "Semitransparent level is ..." & (100 - intLevel) & "%"
End Sub
The code fails on the line
SetLayeredWindowAttributes hWnd, 0, ((255) * intLevel) / 100, LWA_ALPHA
Help suggests that this is an Overflow (Error 6)
An overflow results when you try to make an assignment that exceeds the limitations of the target of an assignment
The result of an assignment, calculation, or datatype conversion is too large to be represented within the range of values allowed for that type of variable
An assignment to a property exceeds the maximum value the property can acceptWhat do I need to change here?
Private Declare Function GetActiveWindow Lib "USER32" () As Long
Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal lngWinIdx As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal lngWinIdx As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "USER32" _
(ByVal hWnd As Long, ByVal crKey As Integer, ByVal bAlpha As Integer, _
ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC
Dim hWnd As Long
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub ScrollBar1_Change()
Call Semitransparent(Me.ScrollBar1.Value)
End Sub
Private Sub UserForm_Activate()
Me.ScrollBar1.Value = 50
End Sub
Private Sub Semitransparent(ByVal intLevel As Integer)
Dim lngWinIdx As Long
hWnd = GetActiveWindow
lngWinIdx = GetWindowLong(hWnd, GWL_EXSTYLE)
SetWindowLong hWnd, GWL_EXSTYLE, lngWinIdx Or WS_EX_LAYERED
SetLayeredWindowAttributes hWnd, 0, ((255) * intLevel) / 100, LWA_ALPHA
Label1.Caption = "Semitransparent level is ..." & (100 - intLevel) & "%"
End Sub
The code fails on the line
SetLayeredWindowAttributes hWnd, 0, ((255) * intLevel) / 100, LWA_ALPHA
Help suggests that this is an Overflow (Error 6)
An overflow results when you try to make an assignment that exceeds the limitations of the target of an assignment
The result of an assignment, calculation, or datatype conversion is too large to be represented within the range of values allowed for that type of variable
An assignment to a property exceeds the maximum value the property can acceptWhat do I need to change here?