Results 1 to 7 of 7

Thread: Transparent ComboLBox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetComboBoxInfo Lib "user32.dll" _
    4.   (ByVal hwndCombo As Long, _
    5.   ByRef pcbi As PCOMBOBOXINFO) As Long
    6.  
    7. Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" _
    8.   (ByVal hwnd As Long, _
    9.   ByVal nIndex As Long, _
    10.   ByVal dwNewLong As Long) As Long
    11.  
    12. Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
    13.   (ByVal hwnd As Long, _
    14.   ByVal nIndex As Long) As Long
    15.      
    16. Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" _
    17.   (ByVal hwnd As Long, _
    18.   ByVal crKey As Long, _
    19.   ByVal bAlpha As Byte, _
    20.   ByVal dwFlags As Long) As Long
    21.      
    22. Private Type RECT
    23.   Left As Long
    24.   Top As Long
    25.   Right As Long
    26.   Bottom As Long
    27. End Type
    28.  
    29. Private Type PCOMBOBOXINFO
    30.   cbSize As Long
    31.   rcItem As RECT
    32.   rcButton As RECT
    33.   stateButton As Long
    34.   hwndCombo As Long
    35.   hwndItem As Long
    36.   hwndList As Long
    37. End Type
    38.  
    39. Private Const GWL_EXSTYLE As Long = -20
    40. Private Const LWA_ALPHA As Long = &H2
    41. Private Const WS_EX_LAYERED As Long = &H80000
    42.  
    43. Private Sub Form_Load()
    44.   Combo1.AddItem "moo"
    45.   Combo1.AddItem "meep"
    46.   Combo1.AddItem "baaa"
    47.  
    48.   Dim pcbi As PCOMBOBOXINFO, lRet As Long
    49.  
    50.   pcbi.cbSize = Len(pcbi)
    51.  
    52.   lRet = GetComboBoxInfo(Combo1.hwnd, pcbi)
    53.  
    54.   Call SetWindowLong(pcbi.hwndList, GWL_EXSTYLE, GetWindowLong(pcbi.hwndList, GWL_EXSTYLE) Or WS_EX_LAYERED)
    55.   Call SetLayeredWindowAttributes(pcbi.hwndList, 0, 50, LWA_ALPHA)
    56. End Sub
    Cheers, adehh.

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    I get this error dude.....

    Attached Images Attached Images  

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    It's win2k/xp only
    -adehh

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    oh well

  5. #5
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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
  •  



Click Here to Expand Forum to Full Width