Code : Tout sélectionner
; RollOver effects par Jacobus
; Astuce rendue possible grâce à DrDri et son Image Toggle
;
Enumeration
#win
#Btn_1
#Txt_Btn_1
#Btn_2
#Txt_Btn_2
#texto
#Statusbar
EndEnumeration
Global MyHand,Start,Image0, Image1,Font0
MyHand = LoadCursor_(0, #IDC_HAND);curseur main
Start = LoadCursor_(0, #IDC_APPSTARTING);curseur démarrage application
Image0 = CatchImage(0, ?Image0)
Image1 = CatchImage(1, ?Image1)
Font0 = LoadFont(0, "Verdana", 9,#PB_Font_Bold|#PB_Font_HighQuality)
DataSection
Image0 : IncludeBinary "Images\Image0.ico"; <***INDIQUEZ LE CHEMIN DE VOS ICONES OU IMAGES***
Image1 : IncludeBinary "Images\Image1.ico"
EndDataSection
Procedure IsMouseOver(wnd)
GetWindowRect_ (wnd,re.RECT)
re\left = re\left
re\top = re\top
re\right = re\right
re\bottom = re\bottom
GetCursorPos_ (pt.POINT)
ProcedureReturn PtInRect_ (re,pt\x,pt\y)
EndProcedure
Macro ImageGadgetBorderWidth()
GetSystemMetrics_(#SM_CXEDGE)
EndMacro
Macro ImageGadgetBorderHeight()
GetSystemMetrics_(#SM_CYEDGE)
EndMacro
Procedure.l SetImageGadgetBorder(Gadget.l, State.l)
Protected Set.l = #False, GadgetID.l, Style.l
Protected Width.l, Height.l, Change.l = #False
GadgetID = GadgetID(Gadget)
If GadgetID
Style = GetWindowLong_(GadgetID, #GWL_EXSTYLE)
Width = GadgetWidth(Gadget)
Height = GadgetHeight(Gadget)
If State
If Not Style & #PB_Image_Border
Width + ImageGadgetBorderWidth() * 2
Height + ImageGadgetBorderHeight() * 2
Style | #PB_Image_Border
Change = #True
EndIf
Else
If Style & #PB_Image_Border
Width - ImageGadgetBorderWidth() * 2
Height - ImageGadgetBorderHeight() * 2
Style & ~#PB_Image_Border
Change = #True
EndIf
EndIf
If Change
SetWindowLong_(GadgetID, #GWL_EXSTYLE, Style)
SetWindowPos_(GadgetID, 0, 0, 0, Width, Height, #SWP_NOMOVE | #SWP_FRAMECHANGED)
EndIf
Set = #True
EndIf
ProcedureReturn Set
EndProcedure
OpenWindow(#win,0,0,240,280,"RollOver Buttons Example",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(#win))
SetWindowColor(#win,RGB(157, 173, 206))
btn1=ImageGadget(#Btn_1,85,10,100,60,Image1);on se sert d'une image comme bouton
TextGadget(#Txt_Btn_1,5,70,220,30,"Button Number 1"+Chr(13)+"Ce bouton vous mène à rien",#PB_Text_Center)
SetGadgetColor(#Txt_Btn_1,#PB_Gadget_FrontColor,RGB(255,255,255))
SetGadgetColor(#Txt_Btn_1,#PB_Gadget_BackColor,RGB(157, 173, 206))
btn2=ImageGadget(#Btn_2,85,105,100,60,Image0);ImageGadget ajuste sa taille à celle de l'image
TextGadget(#Txt_Btn_2,5,165,220,30,"Button Number 2"+Chr(13)+"Celui-ci non plus d'ailleurs",#PB_Text_Center)
SetGadgetColor(#Txt_Btn_2,#PB_Gadget_FrontColor,RGB(255,255,255))
SetGadgetColor(#Txt_Btn_2,#PB_Gadget_BackColor,RGB(157, 173, 206))
Texto=TextGadget(#texto,5,210,220,30,"Mais vous pourriez leur donner une destination",#PB_Text_Center)
SetGadgetColor(#texto,#PB_Gadget_FrontColor,RGB(255,255,255))
SetGadgetColor(#texto,#PB_Gadget_BackColor,RGB(157, 173, 206))
;-STATUSBAR
If CreateStatusBar(#Statusbar, WindowID(#win))
AddStatusBarField(WindowWidth(#win)/2)
AddStatusBarField(WindowWidth(#win)/2)
StatusBarText(#Statusbar, 0, "RollOver effects", #PB_StatusBar_Raised)
StatusBarText(#Statusbar, 1, "PureBasic Users"+Chr(169), #PB_StatusBar_Raised|#PB_StatusBar_Right)
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
;ci-dessous quelques exemples, mais d'autres possibilités sont réalisables
Case #WM_MOUSEMOVE
If IsMouseOver(btn1):SetCursor_(MyHand)
StatusBarText(#Statusbar, 0, "Bouton 1 survolé")
SetImageGadgetBorder(#Btn_1, #True)
SetImageGadgetBorder(#Btn_2, #False)
SetGadgetFont(#Txt_Btn_1,Font0)
SetGadgetFont(#Txt_Btn_2,#PB_Default)
SetGadgetFont(#texto,#PB_Default)
ElseIf IsMouseOver(btn2):SetCursor_(MyHand)
StatusBarText(#Statusbar, 0, "Bouton 2 survolé")
SetImageGadgetBorder(#Btn_1, #False)
SetImageGadgetBorder(#Btn_2, #True)
SetGadgetFont(#Txt_Btn_1,#PB_Default)
SetGadgetFont(#Txt_Btn_2,Font0)
SetGadgetFont(#texto,#PB_Default)
ElseIf IsMouseOver(Texto):SetCursor_(Start)
StatusBarText(#Statusbar, 0, "Votre texto activé")
SetImageGadgetBorder(#Btn_1, #False)
SetImageGadgetBorder(#Btn_2, #False)
SetGadgetFont(#Txt_Btn_1,#PB_Default)
SetGadgetFont(#Txt_Btn_2,#PB_Default)
SetGadgetFont(#texto,Font0)
Else
StatusBarText(#Statusbar, 0, "RollOver effects")
SetImageGadgetBorder(#Btn_1, #False)
SetImageGadgetBorder(#Btn_2, #False)
SetGadgetFont(#Txt_Btn_1,#PB_Default)
SetGadgetFont(#Txt_Btn_2,#PB_Default)
SetGadgetFont(#texto,#PB_Default)
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case #Btn_1
Select EventType()
Case #PB_EventType_LeftClick
MessageRequester("BOUTON 1","Pas de programme de destination",#IDI_HAND)
EndSelect
Case #Btn_2
Select EventType()
Case #PB_EventType_LeftClick
MessageRequester("BOUTON 2","Pas de programme de destination",#IDI_APPLICATION)
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End

[Edit] défaut corrigé concernant l'event des boutons.