Re: Bouton sur image
Publié : ven. 05/avr./2024 17:38
Hum je ne pense pas que Fred pense comme toi ??
D'une part, il y a ce que pense Fred et, là-dessus, je me garderais bien de prétendre savoir ce qu'il (en) pense, je n'ai pas de don de mediumnité,
Code : Tout sélectionner
Global.f DPIX=DesktopScaledX(100)/100,DPIY=DesktopScaledY(100)/100
LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\PureBasic.bmp")
;
Procedure GestionAffichageConteneur()
Protected.u NoConteneur=GetWindowData(0),NouveauConteneur
Protected.s TexteBouton
Debug "ok"
Select NoConteneur
Case 0:NouveauConteneur=4:TexteBouton="Cacher conteneur 2"
Case 4:NouveauConteneur=0:TexteBouton="Cacher conteneur 1"
EndSelect
SetWindowData(0,NouveauConteneur)
HideGadget(NoConteneur,#True)
HideGadget(NouveauConteneur,#False)
SetGadgetText(8,TexteBouton)
EndProcedure
;
OpenWindow(0,0,0,200,240,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ContainerGadget(0,0,0,400,155)
ButtonImageGadget(1,10,10,ImageWidth(0),ImageHeight(0),ImageID(0))
ButtonImageGadget(2,10,50,ImageWidth(0),ImageHeight(0),ImageID(0))
ImageGadget(3,10,110,168/DPIX,35/DPIY,ImageID(0))
CloseGadgetList()
ContainerGadget(4,0,0,400,155)
ButtonGadget(5,10,10,168,35,"Bouton normal 1")
ButtonGadget(6,10,50,168,35,"Bouton normal 2")
ButtonGadget(7,10,110,168,35,"Bouton normal 3")
CloseGadgetList()
ButtonGadget(8,10,160,168,35,"Cacher conteneur 1")
HideGadget(4,#True)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget()=8 And EventType()=#PB_EventType_LeftClick
GestionAffichageConteneur()
EndIf
EndSelect
ForEver
Je ne sais pas si tu rencontres aussi le même problème pour les checkbox, mais comme Mesa l'évoque, ici une solution qui fonctionne aussi bien pour les CheckBoxGadget() que pour les OptionGadget().Bmld76 a écrit : Merci si vous avez une solution.
Code : Tout sélectionner
CompilerIf #PB_Compiler_Version=602
CompilerError "Ce code ne fonctionne pas sous PB 6.02 à cause d'un bug !"
End
CompilerEndIf
;
Global CoulFondGadgets=CreateSolidBrush_(#White)
;
Procedure.l Callback(ArgID,ArgMessage,ArgWParam,ArgLParam)
Select ArgMessage
Case #WM_CTLCOLORSTATIC
Select GetDlgCtrlID_(ArgLParam)
Case 0 ; + Autres n° de gadgets si besoin
ProcedureReturn CoulFondGadgets
EndSelect
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,200,100,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0,#White)
CheckBoxGadget(0,10,10,180,24,"Checkbox 1")
CheckBoxGadget(1,10,50,180,24,"Checkbox 2")
; SetGadgetColor(0,#PB_Gadget_BackColor,#White) ; Inutile car ne fonctionne pas !
SetWindowCallback(@Callback())
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(CoulFondGadgets)
Ok, MLD ! J'arrête là l'échange qui polluerait inutilement ce topic.MLD a écrit : [...]
Code : Tout sélectionner
;====================================================
; Program: CheckBox Colors Demo
; Author: netmaestro
; Date: November 29, 2006
;====================================================
Global GadgetBkg = CreateSolidBrush_(#Green)
Global BoxBkg = CreateSolidBrush_(#Yellow)
Global Checkcolor = #Blue
Global Textcolor = #Red
Global NullPen = CreatePen_(#PS_NULL, 0, 0)
Procedure GadgetProc(hwnd, msg, wparam, lparam)
Shared oldproc
result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
Select msg
Case #WM_PAINT, #WM_LBUTTONUP, #WM_LBUTTONDOWN
dc = GetDC_(hwnd)
SelectObject_(dc, BoxBkg)
SelectObject_(dc, NullPen)
Rectangle_(dc,2,5,12,15)
If GetGadgetState(GetDlgCtrlID_(hwnd))
Restore check
For i = 1 To 21
Read x
Read y
SetPixel_(dc,x+2,y+5, CheckColor)
Next
EndIf
ReleaseDC_(hwnd, dc);
EndSelect
ProcedureReturn result
EndProcedure
Procedure WindowProc(hWnd, Msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If Msg=#WM_CTLCOLORSTATIC
If GetDlgCtrlID_(lparam) = 1
SetBkMode_(wParam,#TRANSPARENT)
SetTextColor_(wParam, Textcolor)
result = GadgetBkg
EndIf
EndIf
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")
oldproc = SetWindowLong_(GadgetID(1),#GWL_WNDPROC,@GadgetProc())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(GadgetBkg)
DeleteObject_(BoxBkg)
DeleteObject_(NullPen)
DataSection
check:
Data.l 7,1,6,2,7,2,1,3,5,3,6,3,7,3,1,4,2,4,4,4,5,4,6,4,1,5,2,5,3,5,4,5,5,5,2,6,3,6,4,6,3,7
EndDataSection
;***************************************************************************************************************************************************
Enumeration
#MainForm
#Panel
#Wrapper1
#Wrapper2
#Option
#Check
#AnotherCheck
EndEnumeration
Global YellowColor.i, GreenColor.i
YellowColor = CreateSolidBrush_($B2FCFD)
GreenColor = CreateSolidBrush_($B8F8CE)
Procedure WindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_CTLCOLORSTATIC
Select lparam
Case GadgetID(#Option)
SetBkMode_(wParam,#TRANSPARENT)
SetTextColor_(wParam, $0862F7)
Result = YellowColor
Case GadgetID(#Check)
SetBkMode_(wParam,#TRANSPARENT)
SetTextColor_(wParam, $0862F7)
Result = YellowColor
Case GadgetID(#AnotherCheck)
SetBkMode_(wParam,#TRANSPARENT)
;SetTextColor_(wParam, $0862F7)
SetTextColor_(wParam,$0000FF )
Result = GreenColor
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
Procedure MainformShow()
If OpenWindow(#Mainform, 422, 335, 400, 225, "Test", #PB_Window_SystemMenu)
PanelGadget(#Panel, 10, 20, 250, 180)
AddGadgetItem(#Panel, -1, "Tab #1")
TextGadget(#Wrapper1, 0,0,250,180,"")
SetGadgetColor(#Wrapper1, #PB_Gadget_BackColor, $B2FCFD)
OptionGadget(#Option, 35, 25, 230, 20, "Option Gadget")
CheckBoxGadget(#Check, 35, 50, 230, 20, "Check Gadget")
AddGadgetItem(#Panel, -1, "Tab #2")
TextGadget(#Wrapper2, 0,0,250,180,"")
SetGadgetColor(#Wrapper2, #PB_Gadget_BackColor, $B8F8CE)
CheckBoxGadget(#AnotherCheck,20,20,200,20, "Another Check")
CloseGadgetList()
EndIf
SetWindowCallback(@WindowCallback())
EndProcedure
MainFormShow()
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
;***********************************************************************************************************************************************************
Global GadgetBkg
GadgetBkg = CreateSolidBrush_(#Green)
Procedure WindowProc(hWnd, msg, wParam, lParam)
If msg=#WM_CTLCOLORSTATIC
Select GetDlgCtrlID_(lParam) ;; sweet API call: allows choosing gadgets by their number
Case 1 To 3; ce chiffre peut etre variable de 1 a XX
; uncomment those 2 if compiling WITHOUT XP support
; SetBkMode_(wParam,#TRANSPARENT)
; SetTextColor_(wParam, #Red)
ProcedureReturn gadgetBkg
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")
OptionGadget(2,10,40,245,20,"Checkbox gadget with a green background")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(GadgetBkg)
;******************************************************************************************************************************************
Global hBrush = CreateSolidBrush_(RGB(0,$8f,0))
Procedure WinProc(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLORSTATIC
ProcedureReturn hBrush
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,100,120,"BUTTONSHADOW")
SetWindowColor(0,RGB($00,$8f,$00))
SetWindowCallback(@WinProc())
ButtonGadget(3,10,10,80,40,"Button")
CheckBoxGadget(4,10,60,80,20,"CheckBox")
OptionGadget(5,10,90,80,20,"Option")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;****************************************************************************************************************************************************
;========================================================
; CheckOptionColor() sets the foreground & background
; colours of the OptionGadget() and CheckBoxGadget()
;
; requires a window-level callback - for WINDOWS ONLY
;
; tested with PureBasic v5.31 on Windows 8.1 Pro (x64)
;
; by TI-994A - free to use, improve, share...
;
; 30th November 2014
;========================================================
Procedure WndProc(hWnd, uMsg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If uMsg = #WM_CTLCOLORSTATIC
gadgetNo = GetProp_(lParam, "PB_ID")
fgColor = GetProp_(GadgetID(gadgetNo), "fgc")
bgColor = GetProp_(GadgetID(gadgetNo), "bgc")
If fgColor Or bgColor
SetTextColor_(wParam, fgColor)
SetBkMode_(wParam, #TRANSPARENT)
ProcedureReturn bgColor
EndIf
EndIf
ProcedureReturn result
EndProcedure
Procedure CheckOptionColor(gadgetNo, fgColor = #Black, bgColor = #White)
SetProp_(GadgetID(gadgetNo), "fgc", fgColor)
SetProp_(GadgetID(gadgetNo), "bgc", CreateSolidBrush_(bgColor))
OpenLibrary(0, "uxtheme.dll")
CallFunction(0, "SetWindowTheme", GadgetID(gadgetNo), @none, @none)
CloseLibrary(0)
EndProcedure
;demo code
Enumeration
#MainWindow
#option1
#option2
#option3
#check1
#check2
#check3
EndEnumeration
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 150, "Options & Checks", wFlags)
SetWindowColor(#MainWindow, #Gray)
SetWindowCallback(@WndProc())
OptionGadget(#option1, 20, 15, 120, 30, "Red/Yellow")
CheckOptionColor(#option1, #Red, #Yellow)
OptionGadget(#option2, 160, 15, 120, 30, "Default/Cyan")
CheckOptionColor(#option2, #Null, #Cyan) ;default fore colour
CheckBoxGadget(#check1, 20, 55, 120, 30, "Blue/Default")
CheckOptionColor(#check1, #Blue) ;default back colour
CheckBoxGadget(#check2, 160, 55, 120, 30, "White/Red")
CheckOptionColor(#check2, #White, #Red)
OptionGadget(#option3, 160, 100, 120, 30, "Standard Option")
CheckBoxGadget(#check3, 20, 100, 120, 30, "Standard Check")
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Réponse par MP !MLD a écrit : Tu ne manque pas de culot![]()
![]()
petit échantillons pour rire![]()
![]()
![]()
![]()
![]()
![]()
Code : Tout sélectionner
DisableGadget(Image du fond,1)
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 1400-20, 2200, 32, RGB(239, 239, 239)) And StartDrawing(ImageOutput(0))
Box(1,i,1400-20, 40, RGB(216, 244, 254))
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
DisableGadget(0,1)
ButtonGadget(1, 10, 10, 200, 20, "Standard Button")
Repeat
Event = WaitWindowEvent()
Gadget = EventGadget();
Type_Event= EventType()
Select Event
Case #PB_Event_Gadget
Select Gadget
Case 1
Debug "bouton"
EndSelect
EndSelect
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If LoadImage(0, #PB_Compiler_Home + "/Examples/Sources/Data/PureBasic.bmp"): EndIf
If CreateImage(1, 1400-20, 2200, 32, RGB(239, 239, 239)) And StartDrawing(ImageOutput(1))
Box(1,i,1400-20, 100, RGB(216, 244, 254))
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(1))
EndIf
DisableGadget(0,1)
ButtonGadget(1, 10, 10, 200, 20, "Standard Button")
ButtonImageGadget(2, 10, 40, 180, 40, ImageID(0))
Repeat
Event = WaitWindowEvent(2)
Gadget = EventGadget();
Type_Event= EventType()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "bouton"
Case 2
Debug "bouton img"
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Code : Tout sélectionner
Procedure im2()
OpenWindow(2, WindowX(0)+ 100, WindowY(0) +110, 222, 50, "ButtonGadgets 2")
EndProcedure
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If LoadImage(0, #PB_Compiler_Home + "/Examples/Sources/Data/PureBasic.bmp"): EndIf
If CreateImage(1, 1400-20, 2200, 32, RGB(239, 239, 239)) And StartDrawing(ImageOutput(1))
Box(1,i,1400-20, 100, RGB(216, 244, 254))
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(1))
EndIf
DisableGadget(0,1)
ButtonGadget(1, 10, 10, 200, 20, "Standard Button")
ButtonImageGadget(2, 10, 40, 180, 40, ImageID(0))
Repeat
Event = WaitWindowEvent(2)
Gadget = EventGadget();
Type_Event= EventType()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
im2()
Debug "bouton"
Case 2
Debug "bouton img"
CloseWindow(2)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf