win32 programmers.....CBEX and work around
- Posted by jordah ferguson <jorfergie03 at yahoo.com> Jul 24, 2002
- 610 views
Hi everyone, I have tried most methods i can think of ATM, but i have failed to remove the bug we have with comboboxex controls. if you don't know what i'm meaning then run de comboboxex example that comes with win32lib. There always appears to be a "selected" sort of line above the edit control of the comboboxex. I have tried using SetWindowPos after setting an image list to the control as told in the SDK but hell no, the bug won't leave. I found out, the vertical height of the comboboxex(not the dropdown) depends on the size of the image list. Anyway, i tried making a smaller image list but it looks like the minimum image list size of comboboxex is 14 by 14 pixels. I later started creating my comboboxex's with the Extended style CBES_EX_NOSIZELIMIT as default, with this i was able to use SetWindowPos to make the control smaller(vertically) than the default, but still there was no way, i would get a combo box that didn't seem to be highlighted all the time. After, that failed attempt. I tried retrieving the handle of the EditControl, then "moving it" one step higher using setRect()to cover that selected line within then control itself, still failed. i later found out the RECT of the EditControl was always {0,0,0,14}. so i decided to do use SetWindowPos() and setRect() specifying the RECT as {0,-2,0,14} but i still failed. As i'm writting this, i'm remaining with one more method to try, that is i'm going to set-up a "onSelection " handler of the combo and after i select an item, i setfocus off the combo. this is the only work around i have left and i'm sure it will work but it wouldn't be so elegant, now would it? anyway, please try out your work arounds too, we see if we can get this control to display items correctly. I really don't think i would consider this a Microsoft bug in common controls, cause i haven't seen this happen in other languages. Anyway, is there a C++ programmer out there(Tone Skoda) who could try to create a comboboxex example in C++ and see if they could replicate the same bug. Also, i have failed to give the comboboxex a 3D look because every time i do that using WS_EX_STATICEDGE as the exStyle. It seems to cover the DropDown Button. Ok people, I can easily solve these bugs by creating a full blown owner-draw for a combobox control. But that would mean iam re-inventing the wheel as the ComboBoxEx was primarily created to do this. If there is no/failed final attempt to rid these bugs, then i would suggest we clear the ComboBoxEx control from win32lib and make a simulated comboboxex(by performing owner-draws internally in win32lib) Here is my ugly final code that "attempts", --XX CUT HERE -- ComboBoxEx.exw -- Matt Lewis Modified to show work-around by me with trace without warning include win32lib.ew constant Win = create( Window, "ComboBoxEx Demo", 0, 20, 20, 400, 400, 0), CBE = create( ComboBoxEx, "", Win, 5, 20, 210, 300, 0 ), MLE = create( MleText, "", Win, 5, 60, 210, 200, 0) -- Start: Jordah atom EditCtl -- Get handle of the Edit Control of the ComboBoxEx EditCtl = w32Func(xSendMessage,{getHandle(CBE),(WM_USER + 7),0,0})--CBEM_GETEDITCONTROL atom iMsg,Code,cmd procedure onEvent_(atom id,integer event,object params) iMsg = params[1] if iMsg = WM_COMMAND then Code = hi_word(params[2]) cmd = params[3] if Code = CBN_SELCHANGE or Code = CBN_CLOSEUP or Code = CBN_SELENDOK or Code = CBN_SELENDCANCEL then if id = CBE then -- Just to make sure. Sh'd probably omit this if statement w32Proc(xSetFocus,{0}) w32Proc(xSetFocus,{EditCtl}) end if end if end if end procedure setHandler(CBE,w32HEvent,routine_id("onEvent_")) procedure start_up(atom id,integer event,object params) -- This helps killing the Default Focus the CBE has on startup -- By giving the mainwindow focus w32Proc(xSetFocus,{0}) w32Proc(xSetFocus,{id}) end procedure setHandler(Win,w32HActivate, routine_id("start_up")) -- End: Jordah atom ptr, iExw ptr = allocate_string( "exw" ) iExw = w32Func(xLoadIcon,{instance(), ptr} ) free(ptr) constant closefolder = addIcon( extractIcon( "clsdfold.ico" ) ), openfolder = addIcon( extractIcon( "openfold.ico" )), win = addIcon( iExw ), dos = addIcon( extractIcon( "disk05.ico" )), linux = addIcon( extractIcon( "disk06.ico" )), generic = addIcon( extractIcon( "disks04.ico" )) addItem( CBE, {"Select to open", closefolder, openfolder }) addItem( CBE, {"Disk icons.", dos, linux }) WinMain( Win, Normal ) --------XX Cut here I hope someone comes up with a better solution. Happy research everyone. This is just a hack to enable people to use a ComboboxEX but with a more appealing look. :) Jordah Ferguson aka Sir_LoJiK