Results 1 to 19 of 19

Thread: Subclass Combobox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    Subclass Combobox

    I need to use a combo box without it being 3D. I just need it to be flat and with or without a border, b/c I change the border style at run-time. What API would I use to subclass the combo box?? Thanks

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Unfortunately there is no way to make a normal combobox flat, not using DrawEdge, Or any Style Combination I just spent a day searching for the same thing so I finally made my own. You can have it if you want, although it's not done completely, It doesn't have any databound props (cause I never use them anyway) but I did add autocomplete and sorting (changable at runtime) and you can add Items at designtime. Let me know if you want me to post it.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I wouldn't mind taking a look Edneeis (when its done).

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sure I'm almost done, making the dropdown list hang past the edge of the form and the like created a few problems, but I think I've found a way around most of them. I think I'll declare it 'Good enough' when I fix the scroll problem. Since I have to capture the mouse during dropdown to see if the user clicks outside of the control it made it so you can't scroll on the list. So I gotta fix that, but I added a SetTabs method and ListHeight, oh and a TransferList method so you can transfer the list to a list or combo box.

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Soemtimes it's far easier to cheat!!!

    there is a great project at www.vbAccelerator.com which makes ALL controls on the form flat
    Simply subclassing by the looks of it, apart from Steve, the author, uses a special custom subclassing DLL which confuses the **** out of me.

    Here's the correct link: Arrr, sod, embedded frames
    Just search for "flat" on the web site, that should do it.

    If you manage to strip out the code to flatten just a combo let me know.

    Woka

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well the vbAccelerator control is probably the best solution but here is what I got so far. Everything should work fine as long as the control is on the form itself and not on any containers (frames or tabs). I'm working on fixing that.

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    I use:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    4. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    5. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cY As Long, ByVal wFlags As Long) As Long
    6. Private Const GWL_EXSTYLE = (-20)
    7. Private Const WS_EX_CLIENTEDGE = &H200
    8. Private Const WS_EX_STATICEDGE = &H20000
    9. Private Const SWP_FRAMECHANGED = &H20
    10. Private Const SWP_NOACTIVATE = &H10
    11. Private Const SWP_NOMOVE = &H2
    12. Private Const SWP_NOOWNERZORDER = &H200
    13. Private Const SWP_NOREDRAW = &H8
    14. Private Const SWP_NOSIZE = &H1
    15. Private Const SWP_NOZORDER = &H4
    16. Private Const SWP_SHOWWINDOW = &H40
    17.  
    18. Public Function ThinBorder(ByVal lhWnd As Long, ByVal bState As Boolean)
    19. Dim lS As Long
    20.    lS = GetWindowLong(lhWnd, GWL_EXSTYLE)
    21.    If Not (bState) Then
    22.       lS = lS Or WS_EX_CLIENTEDGE And Not WS_EX_STATICEDGE
    23.    Else
    24.       lS = lS Or WS_EX_STATICEDGE And Not WS_EX_CLIENTEDGE
    25.    End If
    26.    SetWindowLong lhWnd, GWL_EXSTYLE, lS
    27.    SetWindowPos lhWnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOOWNERZORDER Or SWP_NOZORDER Or SWP_FRAMECHANGED
    28. End Function

    If you try to give a command button a thin border you end up with a really cool button I think so anyways...
    To use the above the controls border has to be set to None 1st then give a thin border using the above...which you can't do for a combo box text boxes, picture boxes etc look cool, try it on a command button

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Hello Mr Badger, do you have any drugs for me?

    Your code doesn't work, well on my machine anyways. Both combo's still have the same border, except your usercontrol, erCombo, is slow at displaying data
    When I right click and choose properties, VB shuts down

    I have Win 2000 and VB 6, SP 5...Hmmmm

    All that code just to make the combo box have a small border?

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking 1 oz please...green.

    Your auto complete does strange things to. Doesn't matter what I type it always selects the 1st item, which in this case is "testing"...

    Sorry to slag off your code, I feel bad now

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Hey its all good. Hmm that is strange I'm using a the same OS and VB version as you. And this is only my second control so I don't feel bad I'm still learning, although it worked good for me. I'll check it out, on Autocomplete were you using Partial or Exact?

    Hey thanks for the bug report.

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Sometimes a turtle is the only way...

    Hmmmm...Have no idea what is going on
    Just downloaded the app again, ran it and it works fine. Border, autocomplete and everything...

    Oh well, computers eh? Always keeping us on our toes
    Yes, it works, but is it possible to create the combo using API rather than textbox's, listbox's and pictures?

    How many posts do you have to do before you can change your 'status' to what ever you want? (ie Fanatic Member to Siesmic Badger)

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well the crash when going to the properties at designtime was my bad I didn't post the latest code here is the repleacement. As for the Autocomplete I couldn't reproduce the problem, if its on partial then it works liek you'd think if its on Exact then it just selects what you typed in the list, although nothing looks different since you already typed the whole word(s) until you dropdown the list and then it shows that item selected already.

    And now I fixed the problems for when it is not directly on the form.

    Opps I guess I should read before I post I missed your last post.
    Last edited by Edneeis; Mar 15th, 2002 at 12:30 PM.

  13. #13

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No I can't do that, I'm not that cool yet. Although I am looking in to it.

  15. #15
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No I can't do that, I'm not that cool yet. Although I am looking in to it.

    Here is the most recent version (of the combo).

  16. #16
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Moose pie and a slice of fish please.

    Here's a simple API example whicg creates 2 buttons, a textbox and a listbox...quite easy to understand once you get your head around subclassing and other nasty API stuff. Oh bugger, who am I kidding, it's a mess!

    Good example though...

    has a good example of a status bar also....Have fun
    Attached Files Attached Files

  17. #17
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Thanks!

  18. #18

  19. #19
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I guess I better get on it then :> !

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