
My starting point was an older thread in which Sparkie and srod already demonstrated how to change text and background color of an enabled ComboBoxGadget (http://www.purebasic.fr/english/viewtopic.php?t=17426). So my first approach was the utilisation of a callback to change the background from grey to white:

Code: Select all
Procedure.L MainCallback(WindowHandle.L, Msg.L, wParam.L, lParam.L)
Shared BackgroundBrush.L
If Msg = #WM_CTLCOLORSTATIC And lParam = GadgetID(0)
ProcedureReturn BackgroundBrush
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
BackgroundBrush.L = CreateSolidBrush_(#White)
ComboBoxEnabled.L = #True
If OpenWindow(0, 0, 0, 270, 190, "Enable/Disable ComboBox", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@MainCallback())
ComboBoxGadget(0,10,40,250,150)
ButtonGadget(1, 70, 10, 120, 20, "Disable ComboBox")
For i = 0 To 10
AddGadgetItem(0, -1, "ComboBox item " + Str(i))
Next i
SetGadgetState(0, #True)
Repeat
WindowEvent = WaitWindowEvent()
If WindowEvent = #PB_Event_Gadget
If EventGadget() = 1
If ComboBoxEnabled
DisableGadget(0, #True)
SetGadgetText(1, "Enable ComboBox")
ComboBoxEnabled = #False
Else
DisableGadget(0, #False)
SetGadgetText(1, "Disable ComboBox")
ComboBoxEnabled = #True
EndIf
EndIf
EndIf
Until WindowEvent = #PB_Event_CloseWindow
DeleteObject_(BackgroundBrush)
EndIf
I started a second try after finding a different solution in C on the codeguru website which doesn't need a callback and displays black text on a white background but has the drawback that the entries of the combo box have to be editable:

Code: Select all
; http://www.codeguru.com/cpp/controls/combobox/article.php/c1803
; Moshe Stolar
; // Make the disabled combo's edit control appear as enabled & R/O
;
; // 1. The first child window of a combo is its edit control
; CEdit* pComboEdit=(CEdit*)(GetDlgItem( IDC_COMBO )->GetWindow(GW_CHILD ));
;
; // 2. Enable combo's edit control, not the combo itself, and set R/O
; pComboEdit->EnableWindow( TRUE );
; pComboEdit->SetReadOnly();
ComboBoxEnabled.L = #True
If OpenWindow(0, 0, 0, 270, 190, "Enable/Disable ComboBox", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
ComboBoxGadget(0, 10, 40, 250, 150, #PB_ComboBox_Editable)
ButtonGadget(1, 70, 10, 120, 20, "Disable ComboBox")
For i = 0 To 15
AddGadgetItem(0, -1, "ComboBox item " + Str(i))
Next i
SetGadgetState(0, 1)
ComboBoxHandle = GadgetID(0)
ComboBoxEditControlHandle = GetWindow_(ComboBoxHandle, #GW_CHILD)
Repeat
WindowEvent = WaitWindowEvent()
If WindowEvent = #PB_Event_Gadget
If EventGadget() = 1
If ComboBoxEnabled
DisableGadget(0, #True)
SetGadgetText(1, "Enable ComboBox")
EnableWindow_(ComboBoxEditControlHandle, #True)
ComboBoxEnabled = #False
Else
DisableGadget(0, #False)
SetGadgetText(1, "Disable ComboBox")
ComboBoxEnabled = #True
EndIf
EndIf
EndIf
Until WindowEvent = #PB_Event_CloseWindow
EndIf