Page 1 sur 1

couleur combobox

Publié : mar. 26/févr./2013 13:58
par supercdfr
bonjour,

voici un tout petit bout de code pour coloriser une combobox :

Code : Tout sélectionner

Enumeration
  #Window_0
  #combo_recherche_nom
EndEnumeration

Global BackBrush = CreateSolidBrush_(#Yellow)
Global oldcombproc

Procedure ComboCallBack(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_CTLCOLOREDIT, #WM_CTLCOLORLISTBOX
      SetBkMode_(wParam,#TRANSPARENT)
      SetTextColor_(wParam,#Black)
      SetBkColor_(wParam,#Blue)
      result = BackBrush
    Default
      result = CallWindowProc_(oldcombproc, hWnd, uMsg, wParam, lParam )
  EndSelect
  ProcedureReturn result
EndProcedure


OpenWindow(#Window_0, 0, 0, 300, 200, "test", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
ComboBoxGadget(#combo_recherche_nom,0,35,300,20)
oldcombproc = SetWindowLong_(GadgetID(#combo_recherche_nom), #GWL_WNDPROC, @ComboCallBack())

Repeat
  WaitWindowEvent(10)
ForEver
Le truc que je voudrais savoir, c'est comment coloriser aussi le combox en lui meme, pas que la selection.
Je sais que purecolor le fait, mais cela ferais trop grossir mon programme juste pour ca.

Re: couleur combobox

Publié : mar. 26/févr./2013 16:03
par Kwai chang caine
un genre de truc comme ça ???
Code de SROD

Code : Tout sélectionner

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 = CallWindowProc_(oldcombproc, hWnd, Message, wParam, lParam ) 
  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) 
  
oldcombproc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @ComboCallBack()) 

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
End 

Re: couleur combobox

Publié : sam. 02/mars/2013 11:23
par supercdfr
100% ce que je recherchait, merci

Re: couleur combobox

Publié : lun. 15/avr./2013 19:24
par Fortix
Intéressant :D
et pour "ProgressBar"?? :P

en "Smooth" si possible :lol: ))

Re: couleur combobox

Publié : lun. 15/avr./2013 19:50
par Backup
supercdfr a écrit :Je sais que purecolor le fait, mais cela ferais trop grossir mon programme juste pour ca.
ha ?? tu peux expliquer en quoi ça ferai grossir ton prg ?

Re: couleur combobox

Publié : lun. 15/avr./2013 20:09
par Fortix
Bone idée :D , mais malheureusement "Init_PVDynamic()" ne fonctionne pas :cry:

Code : Tout sélectionner

;/ Created with PureVisionXP v2.04
;/ Mon, 15 Apr 2013 21:10:37
;/ by TEAM DVT

Init_PVDynamic()
;-Global Variables and Constants
Global BubbleTipStyle.l:BubbleTipStyle=0
#PB_Image_BorderRaised =$1

;-Window Constants
Global Window_Form1

;-Gadget Constants
Enumeration 1
  ;Window_Form1
  #Gadget_Form1_xProgressBar3

EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue

;-Image Constants
Enumeration 1
  #Image_Form1_xProgressBar3

EndEnumeration
#ImageIndex=#PB_Compiler_EnumerationValue

Procedure.l Window_Form1()
  Window_Form1=OpenWindow(#PB_Any,346,292,253,64,"Work Form1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
  If Window_Form1
    If CreateGadgetList(WindowID(Window_Form1))
      PVGadgets_ProgressBar(#Gadget_Form1_xProgressBar3,Image_Form1_xProgressBar3,0,0,190,20,0,1,16777215,0,0,2)
      HideWindow(Window_Form1,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure


Procedure WindowCallback(WindowID,Message,wParam,lParam)
  ReturnValue=#PB_ProcessPureBasicEvents
  If Message=#WM_GETMINMAXINFO
    ReturnValue=PVDynamic_LockWindow(WindowID,lParam)
  EndIf
  If Message=#WM_SIZE
    ReturnValue=PVDynamic_Resize(WindowID)
  EndIf

  If Message=#WM_CTLCOLORSTATIC Or Message=#WM_CTLCOLOREDIT Or Message=#WM_CTLCOLORLISTBOX
    ReturnValue=PVDynamic_ColorGadget(lParam,wParam)
  EndIf

  ProcedureReturn ReturnValue
EndProcedure

;-Main Loop
If Window_Form1()
  SetWindowCallback(@WindowCallback())

  quitForm1=0
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=Window_Form1
          quitForm1=1
        EndIf

      Case #PB_Event_Gadget
        Select EventGadgetID()
        EndSelect

    EndSelect
  Until quitForm1
  CloseWindow(Window_Form1)
EndIf
End

Re: couleur combobox

Publié : lun. 15/avr./2013 22:38
par Backup
Fortix a écrit :Intéressant :D
et pour "ProgressBar"?? :P

en "Smooth" si possible :lol: ))

de je sais plus qui :

Code : Tout sélectionner


Declare  MyProgressBarCallback(hWnd,msg,wParam,lParam)
Declare  MyProgressBarGadget(gadget, x, y, Width, Height, Minimum, Maximum, Flags=0)
Declare  StyleMyProgressBar(gadget,imageID,backColor=-1)


Structure MyProgressBarData
	oldCallback.i
	imageID.i
	backColor.l
	vertical.l
EndStructure



Define EventID, state, bar3
Define i

CreateImage(1,1,20)
If StartDrawing(ImageOutput(1))
	DrawingMode(#PB_2DDrawing_Gradient)     
	BackColor(RGB($FF,$FF,$FF))
	FrontColor(RGB($00,$FF,$00))
	GradientColor(0.2,RGB($A0,$FF,$A0))
	LinearGradient(0, 0, 0, 20)   
	Box(0,0,1,20)
StopDrawing()
EndIf

CreateImage(2,1,20)
If StartDrawing(ImageOutput(2))
Box(0,0,1,20,RGB($00,$00,$FF))
For i = 2 To 20 Step 5
	Plot(0,i,RGB($FF,$FF,$00))
Next
StopDrawing()
EndIf

CreateImage(3,10,20)
If StartDrawing(ImageOutput(3))
	Box(0,0,10,20,RGB($FF,$00,$00))
	LineXY(0,0,10,20,RGB($FF,$FF,$FF))
StopDrawing()
EndIf


If OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
MyProgressBarGadget(1,10,10,WindowWidth(0)-20,20,0,100)
StyleMyProgressBar(1,ImageID(1))

MyProgressBarGadget(2,10,50,WindowWidth(0)-20,20,0,150)
StyleMyProgressBar(2,ImageID(2),RGB($00,$00,$00))

bar3 = MyProgressBarGadget(#PB_Any,10,90,WindowWidth(0)-20,20,0,200)
StyleMyProgressBar(bar3,ImageID(3),RGB($FF,$FF,$80))


AddWindowTimer(0,0,33)

Repeat
	EventID=WaitWindowEvent()
	If EventID = #PB_Event_CloseWindow
		End
		ElseIf EventID = #PB_Event_Timer
		state + 1
		SetGadgetState(1,state)
		SetGadgetState(2,state)
		SetGadgetState(bar3,state)
		If state = 100
			RemoveWindowTimer(0,0)
		EndIf
	EndIf
ForEver
EndIf

Procedure MyProgressBarCallback(hWnd,msg,wParam,lParam)
Protected *mem.MyProgressBarData
Protected w, h, state, range, minValue, p.f
Protected hDC, brush, ps.PAINTSTRUCT
Protected gadget = GetWindowLongPtr_(hWnd,#GWLP_ID)
*mem = GetGadgetData(gadget)
If Not *mem : ProcedureReturn DefWindowProc_(hWnd,msg,wParam,lParam) : EndIf
w     = GadgetWidth(gadget)
h     = GadgetHeight(gadget)
If msg = #WM_ERASEBKGND
	hDC = wParam
	If *mem\backColor <> -1
		SelectObject_(hDC, GetStockObject_(#NULL_PEN))
		brush = CreateSolidBrush_(*mem\backColor)
		SelectObject_(hDC, brush)
		Rectangle_(hDC,0,0,w,h+1)
		DeleteObject_(brush)
		ProcedureReturn #True
	EndIf
	ElseIf msg = #WM_PAINT
	hDC = BeginPaint_(hWnd,@ps)
	state = GetGadgetState(gadget) - minValue
	range = GetGadgetAttribute(gadget,#PB_ProgressBar_Maximum) - minValue
	If range < 0 : range = -range : EndIf
	p = (state / range)
	w = Int(w * p)
	If *mem\imageID
		brush = CreatePatternBrush_(*mem\imageID)
		SelectObject_(hDC, brush)
		PatBlt_(hDC,0,0,w,h+1,#PATCOPY)
		;Rectangle_(hDC,0,0,w,h)
		DeleteObject_(brush)
		
	EndIf
	EndPaint_(hWnd,@ps)
	ProcedureReturn 0   
EndIf
If *mem\oldCallback
	ProcedureReturn CallWindowProc_(*mem\oldCallback,hWnd,msg,wParam,lParam)
EndIf
EndProcedure

Procedure MyProgressBarGadget(gadget, x, y, Width, Height, Minimum, Maximum, Flags=0)
Protected *mem.MyProgressBarData
Protected g
g = ProgressBarGadget(gadget,x,y,Width,Height,Minimum,Maximum,Flags)
If gadget = #PB_Any
	gadget = g
EndIf
*mem = AllocateMemory(SizeOf(MyProgressBarData))
If *mem
	*mem\oldCallback = SetWindowLongPtr_(GadgetID(gadget),#GWLP_WNDPROC,@MyProgressBarCallback())
	*mem\backColor   = -1
	*mem\vertical    = Flags & #PB_ProgressBar_Vertical
	SetGadgetData(gadget,*mem)
EndIf
ProcedureReturn g
EndProcedure

Procedure StyleMyProgressBar(gadget,imageID,backColor=-1)
Protected *mem.MyProgressBarData
If IsGadget(gadget) And GadgetType(gadget)=#PB_GadgetType_ProgressBar
	*mem = GetGadgetData(gadget)
	If *mem
		*mem\backColor = backColor
		*mem\imageID   = imageID
		InvalidateRect_(GadgetID(gadget),0,1)
	EndIf
EndIf
EndProcedure




; 



; EPB

Re: couleur combobox

Publié : mar. 16/avr./2013 21:57
par Fortix
la vache :lol:
c'est hyper chouette, merci @Dobro :D

Re: couleur combobox

Publié : mer. 17/avr./2013 8:37
par Kwai chang caine
de je sais plus qui :
Code de DANILO
http://www.purebasic.fr/english/viewtop ... 3e#p371545

Re: couleur combobox

Publié : mer. 17/avr./2013 9:00
par Backup
il pourrait mettre son nom dans ces codes st'idiot :)

Re: couleur combobox

Publié : mer. 17/avr./2013 12:17
par Kwai chang caine
Certes....mais nous savons toi et moi, qui aimont bien stocker des codes, qu'il ne faut pas tres longtemps pour retrouver un auteur en partant de son code :wink:
Et on pourrait dire aussi, que quand un copain s'est fait un "fion" comme ça a créer un code, et a eu la générosité de l'offrir comme tres souvent tu le fait, ca coute pas beaucoup plus cher au "copieur" de mettre en entete le nom de l'auteur, ou bien comme je le fait le lien ou je l'ai trouvé.
Enfin c'est mon opinion, et c'est la moindre des justices, que je peux rendre en tant que lamer professionnel ,aux gens que j'admire 8)