Page 1 of 1

Posted: Sun Oct 30, 2005 9:45 pm
by Sparkie
Hi srod :) I fudged with your code a little and I'm not sure if it's what you're looking for, but try this.

Code: Select all

Global BackBrush.l 
BackBrush = CreateSolidBrush_(#blue) 

Procedure.l MainCallback( hwnd.l, uMsg.l, wparam.l, lparam.l ) 
  Protected result 
  result = #PB_ProcessPureBasicEvents
  If uMsg = #WM_CTLCOLOREDIT And lparam = GadgetID(1)
    SetBkMode_(wparam,#TRANSPARENT) 
    SetTextColor_(wparam,#red) 
    SetBkColor_(wparam,#blue) 
    result = BackBrush 
  EndIf 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0,0,0,270,440,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ComboBoxGadget") And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@MainCallback())
  ComboBoxGadget(1,10,40,250,150) 
   
  For a=0 To 15 : AddGadgetItem(1,-1,"ComboBox item "+Str(a)) : Next 
  
  SetGadgetState(1,0)    
  
  Repeat 
    EventID = WaitWindowEvent() 
    
    Select EventID 
      
      Case #PB_Event_Gadget 
        Select EventGadgetID() 
        EndSelect 
    EndSelect 
  Until EventID = #PB_Event_CloseWindow 
  DeleteObject_(BackBrush)
EndIf 

Posted: Sun Oct 30, 2005 11:01 pm
by srod
Sparkie you flaming genius - I didn't think of trying the parent of the combobox! That is actually better than I was originally aiming for, the way that only the static control is coloured and not the list box. Brilliant.

Your knack of finding solutions is amazing. :lol:

Thanks again.

Posted: Mon Oct 31, 2005 4:57 am
by Sparkie
You're very welcome srod, and thank you for the kind words. :)
Fred and the rest of the PureBasic team make finding the solutions that much easier for us all! 8)

Posted: Mon Nov 07, 2005 11:49 am
by PB
Anyone know a way of coloring the drop-down list of the ComboBox? :)

Posted: Mon Nov 07, 2005 12:13 pm
by srod
The following will colour the edit field and drop down list of an editable combo. If you switch to an uneditable combo, then the following still works on the drop down part, but not the static field. For that you will need Sparkie's code above.

Code: Select all

Global oldcombproc, BackBrush
BackBrush = CreateSolidBrush_(#blue) 

Procedure ComboCallBack( hWnd.l, Message.l, wParam.l, lParam.l ) 

  
  If (Message = #WM_CTLCOLOREDIT) Or (Message = #WM_CTLCOLORLISTBOX) 
    
      SetBkMode_(wParam,#TRANSPARENT)
      SetTextColor_(wParam,#red)
      SetBkColor_(wParam,#blue)
      Result = BackBrush
  Else
    Result.l = CallWindowProc_(oldcombproc, hWnd, Message, wParam, lParam ) 
  EndIf 
  
  ProcedureReturn Result 
  
EndProcedure 


OpenWindow( 0, 200,400,200,100, #PB_Window_SystemMenu, "Colorisation et Callback" ) 

CreateGadgetList( WindowID() ) 
ComboBoxGadget( 1, 10, 10, 180, 120, #PB_ComboBox_Editable ) 

  AddGadgetItem(1, -1, "123" ) 
  AddGadgetItem(1, -1, "456" ) 
  AddGadgetItem(1, -1, "789" ) 
  setgadgetstate(1,0)
  
oldcombproc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @ComboCallBack())

Repeat 
Until WaitWindowEvent() = #PB_EventCloseWindow 
End 
Hope it helps.

Posted: Mon Nov 07, 2005 12:53 pm
by PB
Thanks, now I can't go to bed. ;)

Posted: Sat Jan 27, 2007 12:50 pm
by PB
Request for Fred/Freak: Can coloring be added for ComboBoxGadgets, please?

Posted: Sat Mar 01, 2008 6:49 am
by PB
Anyone know how to do this with two or more ComboBoxGadgets?
I just tried with two but it makes the second gadget invisible! :shock:

What I mean is: I'm currently doing it via a callback for both gadgets,
but is there a way to combine both (and even more) into just a single
callback, to reduce bloat?

Posted: Sat Mar 01, 2008 9:41 am
by gnozal
PB wrote:Anyone know how to do this with two or more ComboBoxGadgets?
Here is some example (just added some props) :

Code: Select all

Procedure ComboCallBack( hwnd.l, message.l, wParam.l, lParam.l ) 
  
  oldcombproc = GetProp_(hwnd.l, "OldProc")
  Result.l = CallWindowProc_(oldcombproc, hwnd, message, wParam, lParam ) 
  If Result
    If (message = #WM_CTLCOLOREDIT) Or (message = #WM_CTLCOLORLISTBOX) 
      SetBkMode_(wParam,#TRANSPARENT) 
      SetTextColor_(wParam,GetProp_(hwnd.l, "TextColor")) 
      SetBkColor_(wParam,GetProp_(hwnd.l, "BackColor")) 
      Result = GetProp_(hwnd.l, "BackBrush")
    ElseIf message = #WM_DESTROY 
      RemoveProp_(hwnd.l, "OldProc")
      RemoveProp_(hwnd.l, "TextColor")
      RemoveProp_(hwnd.l, "BackColor")
      DeleteObject_(GetProp_(hwnd.l, "BackBrush"))
      RemoveProp_(hwnd.l, "BackBrush")
    EndIf 
  EndIf
  
  ProcedureReturn Result 
  
EndProcedure 


OpenWindow( 0, 200,400,200,100, "Colorisation et Callback", #PB_Window_SystemMenu) 

CreateGadgetList( WindowID(0) ) 

ComboBoxGadget( 1, 10, 10, 180, 120, #PB_ComboBox_Editable ) 
AddGadgetItem(1, -1, "123" ) 
AddGadgetItem(1, -1, "456" ) 
AddGadgetItem(1, -1, "789" ) 
SetGadgetState(1,0) 


ComboBoxGadget( 2, 10, 60, 180, 120, #PB_ComboBox_Editable ) 
AddGadgetItem(2, -1, "123" ) 
AddGadgetItem(2, -1, "456" ) 
AddGadgetItem(2, -1, "789" ) 
SetGadgetState(2,0) 
  
SetProp_(GadgetID(1), "OldProc", SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @ComboCallBack()) )
SetProp_(GadgetID(1), "TextColor", #White)
SetProp_(GadgetID(1), "BackColor", #Blue)
SetProp_(GadgetID(1), "BackBrush", CreateSolidBrush_(#Blue))

SetProp_(GadgetID(2), "OldProc", SetWindowLong_(GadgetID(2), #GWL_WNDPROC, @ComboCallBack()) )
SetProp_(GadgetID(2), "TextColor", #Red)
SetProp_(GadgetID(2), "BackColor", #White)
SetProp_(GadgetID(2), "BackBrush", CreateSolidBrush_(#White))

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
End

Posted: Sat Mar 01, 2008 11:42 am
by PB
Thanks gnozal, good example with the props. :)

Posted: Mon Mar 03, 2008 3:16 pm
by kinglestat
srod asking a question?
now, THAT took my by surprise
(of course I have no clue what the question is all about)

Re: Colouring the static-field in an un-editable ComboBox

Posted: Sun Feb 05, 2023 7:13 pm
by HarrysLad
An old thread but ...
Is it possible to set the foreground and/or background colours of a ComboBoxGadget?
This is not usually a problem but on one of my apps (and in Dark-Mode) I get a white foreground on a white background!

{edit:] this is on macOS. I should have mentioned that. :oops:

Dave