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
Printable View
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
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.
I wouldn't mind taking a look Edneeis (when its done). ;)
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.
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
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.
I use:
VB Code:
Option Explicit 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 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 Private Const GWL_EXSTYLE = (-20) Private Const WS_EX_CLIENTEDGE = &H200 Private Const WS_EX_STATICEDGE = &H20000 Private Const SWP_FRAMECHANGED = &H20 Private Const SWP_NOACTIVATE = &H10 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOOWNERZORDER = &H200 Private Const SWP_NOREDRAW = &H8 Private Const SWP_NOSIZE = &H1 Private Const SWP_NOZORDER = &H4 Private Const SWP_SHOWWINDOW = &H40 Public Function ThinBorder(ByVal lhWnd As Long, ByVal bState As Boolean) Dim lS As Long lS = GetWindowLong(lhWnd, GWL_EXSTYLE) If Not (bState) Then lS = lS Or WS_EX_CLIENTEDGE And Not WS_EX_STATICEDGE Else lS = lS Or WS_EX_STATICEDGE And Not WS_EX_CLIENTEDGE End If SetWindowLong lhWnd, GWL_EXSTYLE, lS SetWindowPos lhWnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOOWNERZORDER Or SWP_NOZORDER Or SWP_FRAMECHANGED 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 :)
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?
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 :rolleyes:
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.
Hmmmm...Have no idea what is going on :(
Just downloaded the app again, ran it and it works fine. Border, autocomplete and everything...:confused:
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)
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.
Yea, it works! :o)
Can you do it by cretaing the controls in teh OCX using API :) Now that would be good...
No I can't do that, I'm not that cool yet. Although I am looking in to it.
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).
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 :)
Thanks!
Now you have no excuse for not rewriting the code using API :p
Well I guess I better get on it then :> !