PDA

Click to See Complete Forum and Search --> : picture box cannot be made transparent


fbokker
Apr 25th, 2001, 09:38 AM
I just tried to make a transparent picturebox using SetWindowLongA. It doesn't get transparent! do i make something wrong or is it a bug?
And if it is a bug, is there any way to make my picturebox transparent then?

try this code: (add a picturebox, a command-button and something that is hidden beneath the picturebox)

Const GWL_EXSTYLE = (-20)
Const WS_EX_TRANSPARENT = &H20&

Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Sub Command1_Click()
Dim result As Long
Picture1.ZOrder
result = SetWindowLong(Picture1.hwnd, GWL_EXSTYLE, _
WS_EX_TRANSPARENT)
End Sub

in MSDN this acutally is reported to be a bug in VB 5.0, but they don't tell about VB6. (and shouldn't they have fixed it in the meantime, if they already knew at the times of VB5 of this bug?) msdn:Q185626

Megatron
Apr 25th, 2001, 02:29 PM
Try:

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&

Private Sub Command1_Click()
Dim lStyle As Long
lStyle = GetWindowLong(Picture1.hwnd, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_TRANSPARENT
SetWindowLong Picture1.hwnd, GWL_EXSTYLE, lStyle
End Sub

fbokker
Apr 26th, 2001, 01:37 AM
This code also does not work!