Page 1 sur 1

cherch meilleur maniere de coder la colorisation de combobox

Publié : lun. 30/juin/2014 21:19
par supercdfr
Bonjour,

voici un code qui permets de colorer plusieurs combobox de differentes couleurs :

Code : Tout sélectionner

Global oldcombproc

Procedure ComboCallBack(hWnd, Message, wParam, lParam)
  If (Message = #WM_CTLCOLOREDIT) Or (Message = #WM_CTLCOLORLISTBOX)
    SetBkMode_(wParam,#TRANSPARENT)
    If hWnd = GadgetID(9)
      SetTextColor_(wParam,#Red)
      Result = CreateSolidBrush_(#Yellow)
    ElseIf hWnd = GadgetID(10)
      SetTextColor_(wParam,#White)
      Result = CreateSolidBrush_(#Blue)
    EndIf
  Else
    Result = CallWindowProc_(oldcombproc, hWnd, Message, wParam, lParam )
  EndIf
  ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered)
    
ComboBoxGadget( 9,    100, 0, 115, 25 , #PB_ComboBox_Editable)
ComboBoxGadget( 10,    100, 50, 115, 25 , #PB_ComboBox_Editable)

oldcombproc = SetWindowLong_(GadgetID(9), #GWL_WNDPROC, @ComboCallBack())
oldcombproc = SetWindowLong_(GadgetID(10), #GWL_WNDPROC, @ComboCallBack())

AddGadgetItem(9,-1,"test 1")
AddGadgetItem(9,-1,"test 2")
AddGadgetItem(10,-1,"test 3")
AddGadgetItem(10,-1,"test 4")

Repeat
  WaitWindowEvent()
ForEver
Cela fonctionne bien, mais le code n'est vraiment pas élégant.
D'abord a cause du

Code : Tout sélectionner

Global oldcombproc
qui fait un peu tache, et surtout a cause des appels

Code : Tout sélectionner

SetWindowLong_
a faire a chaque combobox.
Qui peut me dire si ont peut arranger ça.

Re: cherch meilleur maniere de coder la colorisation de comb

Publié : lun. 30/juin/2014 23:43
par Backup
..........

Re: cherch meilleur maniere de coder la colorisation de comb

Publié : mar. 01/juil./2014 11:00
par Mesa
On peut utiliser une variable shared à la place d'une globale mais pour les SetWindowLong_, je ne vois pas d'autre solution.

Code : Tout sélectionner


Procedure ComboCallBack(hWnd, Message, wParam, lParam)
  Shared oldcombproc ; <============
  
  If (Message = #WM_CTLCOLOREDIT) Or (Message = #WM_CTLCOLORLISTBOX) 
    SetBkMode_(wParam,#TRANSPARENT) 
    If hWnd = GadgetID(9) 
      SetTextColor_(wParam,#Red) 
      Result = CreateSolidBrush_(#Yellow) 
    ElseIf hWnd = GadgetID(10) 
      SetTextColor_(wParam,#White) 
      Result = CreateSolidBrush_(#Blue) 
    EndIf 
  Else 
    Result = CallWindowProc_(oldcombproc, hWnd, Message, wParam, lParam ) 
  EndIf 
  ProcedureReturn Result 
EndProcedure

OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)

ComboBoxGadget( 9,    100, 0, 115, 25 , #PB_ComboBox_Editable)
ComboBoxGadget( 10,    100, 50, 115, 25 , #PB_ComboBox_Editable)

oldcombproc = SetWindowLong_(GadgetID(9), #GWL_WNDPROC, @ComboCallBack())
;oldcombproc = SetWindowLong_(GadgetID(10), #GWL_WNDPROC, @ComboCallBack())
SetWindowLong_(GadgetID(10), #GWL_WNDPROC, @ComboCallBack())

AddGadgetItem(9,-1,"test 1")
AddGadgetItem(9,-1,"test 2")
AddGadgetItem(10,-1,"test 3")
AddGadgetItem(10,-1,"test 4")

Repeat
  Event = WaitWindowEvent()
  
Until Event = #PB_Event_CloseWindow

M.

Re: cherch meilleur maniere de coder la colorisation de comb

Publié : mer. 02/juil./2014 6:35
par kernadec
bonjour à tous
Pour la couleur avec le combobox sous Windows j'utilise le code de Gnozal

Cordialement

Code : Tout sélectionner

;http://www.purebasic.fr/english/viewtopic.php?f=13&t=17426
;auteur gnozal ---- Mar 01, 2008 

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) 


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


ComboBoxGadget( 2, 10, 60, 180, 20, #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_(#Green))

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
End

Re: cherch meilleur maniere de coder la colorisation de comb

Publié : jeu. 03/juil./2014 15:30
par supercdfr
c'est justement parce que les lib de gnozla ne fonctionnent plus en 5.2x que j'essaye autrement.

Re: cherch meilleur maniere de coder la colorisation de comb

Publié : jeu. 03/juil./2014 16:29
par Backup
le code de Kernadec , ne fait pas appel a une lib de Gnozal

c'est un code de Gnozal ....