|
-
Dec 19th, 2003, 05:34 PM
#1
Thread Starter
Hyperactive Member
Transparent ComboLBox
I'm using the following code in an attempt to make a the listbox of a combobox transparent, with no luck tho. Add a combo to a form and try it please. It seems to just 'crash' the list.
VB Code:
Option Explicit
Private Declare Function GetComboBoxInfo Lib "user32.dll" _
(ByVal hwndCombo As Long, _
ByRef pcbi As PCOMBOBOXINFO) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" _
(ByVal hwnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type PCOMBOBOXINFO
cbSize As Long
rcItem As RECT
rcButton As RECT
stateButton As Long
hwndCombo As Long
hwndItem As Long
hwndList As Long
End Type
Private Const GWL_EXSTYLE As Long = -20
Private Const LWA_ALPHA As Long = &H2
Private Const WS_EX_LAYERED As Long = &H80000
Private Sub Form_Load()
Combo1.AddItem "moo"
Combo1.AddItem "meep"
Combo1.AddItem "baaa"
Dim pcbi As PCOMBOBOXINFO, lRet As Long
pcbi.cbSize = Len(pcbi)
lRet = GetComboBoxInfo(Combo1.hwnd, pcbi)
Call SetWindowLong(pcbi.hwndList, GWL_EXSTYLE, GetWindowLong(pcbi.hwndList, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(pcbi.hwndList, 0, 50, LWA_ALPHA)
End Sub
Cheers, adehh.
-
Dec 19th, 2003, 05:37 PM
#2
Supreme User
-
Dec 19th, 2003, 05:38 PM
#3
Thread Starter
Hyperactive Member
It's win2k/xp only 
-adehh
-
Dec 19th, 2003, 05:39 PM
#4
-
Dec 19th, 2003, 05:52 PM
#5
Fanatic Member
Well I tried it and it just seems to drop the list down and then once I select something the list is still shown. It seems as if the refresh event for the form does not repaint the form or atleast that section of where the list is shown.
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Dec 19th, 2003, 07:37 PM
#6
Thread Starter
Hyperactive Member
Indeed, exactly the same result I get. It's the WS_EX_LAYERED flag that causes it, maybe it's something that just cannot be done..
-adehh
-
Dec 20th, 2003, 01:15 AM
#7
Thread Starter
Hyperactive Member
I've sussed it - why it won't work that is. The ComboLBoxes containing the list for the ComboBox work by being a child of the desktop, thus making them the active window whilst still leaving focus to the current window. I discovered all of this from an article here.
This sort of child window (possibly only child windows of the desktop) don't seem to like having their layered window attributes set, they accept the WS_EX_LAYERED style and dissapear like all other windows but after trying to set LWA_ALPHA they crash and all sorts of (what I believe are) repainting errors occur.
Bummer of Windows I suppose - cheers, adehh.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|