Colouring the static-field in an un-editable ComboBox

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks, now I can't go to bed. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Request for Fred/Freak: Can coloring be added for ComboBoxGadgets, please?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks gnozal, good example with the props. :)
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

srod asking a question?
now, THAT took my by surprise
(of course I have no clue what the question is all about)
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
HarrysLad
User
User
Posts: 59
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

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

Post 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
Post Reply