[resolu] EventType() et Buttongadget ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

[resolu] EventType() et Buttongadget ?

Message par Ar-S »

Est-ce normal que l'EventType() #PB_EventType_RightClick ne fonctionne pas sur un ButtonGadget() ?

Je suis en train de me faire une appli faisant apparaitre X boutons dans une fenêtre, chaque bouton lançant un mp3. (j'utilise fmodex)
Je souhaite que le clique gauche face "Jouer/Pause" (ça c'est fait) mais j'aimerai aussi que le clique droit serve de "stop" or le classique EventType() #PB_EventType_RightClick ne veut rien savoir sur un bouton.
Dernière modification par Ar-S le jeu. 15/déc./2011 12:35, modifié 1 fois.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
MLD
Messages : 1124
Inscription : jeu. 05/févr./2009 17:58
Localisation : Bretagne

Re: EventType() et Buttongadget ?

Message par MLD »

Salut Ar-S

C'est Widows qui ne prend pas en compte l'appuis a partir du bouton droit de la souris :roll:
Du moins il me semble :?: :roll:

Code : Tout sélectionner

OpenWindow(1, 0, 0, 500, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(2, 20, 200, 50, 40, "Test")


Repeat
  Event = WaitWindowEvent()
   Select EventGadget() ; Gadgets
    Case 2
     Select EventType()
      Case #PB_EventType_RightClick
       Debug "ok"
     EndSelect  
   EndSelect
   
Until Event = #PB_Event_CloseWindow
End   
Mais tu peu faire en sorte que le fait d'appuyer une fois sur le bouton fasse une action, et un deuxieme appuis sur le même bouton arrête l'action. :wink:

Code : Tout sélectionner

Global drapeaubt2 = 0
OpenWindow(1, 0, 0, 500, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(2, 20, 200, 50, 40, "Test")


Repeat
  Event = WaitWindowEvent()
   Select EventGadget() ; Gadgets
    Case 2
    Select EventType()
      Case #PB_EventType_LeftClick
       If drapeaubt2 = 0
        Debug "Action"
        drapeaubt2 = 1
       Else
        Debug "Arrête l'action"
        drapeaubt2 = 0
       EndIf
      EndSelect    
   EndSelect
   
Until Event = #PB_Event_CloseWindow
End  
Pour le fun :lol:
Bonne journée
Michel
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: EventType() et Buttongadget ?

Message par Mesa »

Vois à cette adresse, les codes sont anciens mais la plupart fonctionne encore :
http://www.purearea.net/pb/CodeArchiv/French.html#5

Code : Tout sélectionner

OpenWindow(1, 0, 0, 500, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(2, 20, 200, 50, 40, "Test")


Repeat
  Event = WaitWindowEvent()
   
      If event= #WM_RBUTTONDOWN ;propre à windows ?!
       Debug "ok"
     EndIf
   
Until Event = #PB_Event_CloseWindow
End   
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: EventType() et Buttongadget ?

Message par Mesa »

Tu peux aussi utiliser un toggle button comme ça :

Code : Tout sélectionner

Global drapeaubt2 = 0
OpenWindow(1, 0, 0, 500, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(2, 20, 200, 50, 40, "Test",#PB_Button_Toggle)


Repeat
  Event = WaitWindowEvent()
   Select EventGadget() ; Gadgets
    Case 2
    Select EventType()
      Case #PB_EventType_LeftClick
       If drapeaubt2 = 0
         Debug "Action"
          SetGadgetState(2,1)
        drapeaubt2 = 1
       Else
        Debug "Arrête l'action"
        drapeaubt2 = 0
        SetGadgetState(2,0)
       EndIf
      EndSelect   
   EndSelect
   
Until Event = #PB_Event_CloseWindow
End  
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: EventType() et Buttongadget ?

Message par Mesa »

Voici le vieux code dont je parlais mais avec le Clic gauche milieu droit et double-click gauche milieu droit :

Code : Tout sélectionner

; German forum: http://www.purebasic.fr/german/viewtopic.php?t=10149&postdays=0&postorder=asc&start=60
; Author: hardfalcon (completely new code, originally written by CyberRun8)
; Date: 19. November 2006
; OS: Windows
; Demo: No


; 19.11.2006 by hardfalcon 
; Determine the type of mouseclick if a button gadget has been clicked. 
; Caution: As this code filters out unnecessary "single click" events 
; which normally preceed a double click event, all single clicks are 
; handled with the delay defined by GetDoubleClickTime_() (usually 500ms) 


If OpenWindow(0,0,0,200,200,"LEFT MIDDLE RIGHT",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
   
  ButtonGadget(0,50,50,100,100,"Click me!") 
    Repeat 
    Event = WaitWindowEvent() 
    
    If Event = #WM_LBUTTONDOWN 
      Debug "left click"
      GetCursorPos_(@pt.POINT) 
      If GadgetID(0) = WindowFromPoint_(pt) 
        If timer 
          KillTimer_(WindowID(0),0) 
        EndIf 
        timer = SetTimer_(WindowID(0),0,GetDoubleClickTime_(),0) 
        mousebutton = event 
      EndIf 
    ElseIf Event = #WM_LBUTTONDBLCLK 
      timer = 0 
      KillTimer_(WindowID(0),0) 
      mousebutton = 0 
      Debug "Left doubleclick" 
      
    ElseIf Event = #WM_MBUTTONDOWN 
      Debug "middle click"
      GetCursorPos_(@pt.POINT) 
      If GadgetID(0) = WindowFromPoint_(pt) 
        If timer 
          KillTimer_(WindowID(0),0) 
        EndIf 
        timer = SetTimer_(WindowID(0),0,GetDoubleClickTime_(),0) 
        mousebutton = event 
      EndIf 
    ElseIf Event = #WM_MBUTTONDBLCLK 
      
      timer = 0 
      KillTimer_(WindowID(0),0) 
      mousebutton = 0 
      Debug "Middle doubleclick"      
      
    ElseIf Event = #WM_RBUTTONDOWN
      Debug "Right click"
      GetCursorPos_(@pt.POINT) 
      If GadgetID(0) = WindowFromPoint_(pt) 
        If timer 
          KillTimer_(WindowID(0),0) 
        EndIf 
        timer = SetTimer_(WindowID(0),0,GetDoubleClickTime_(),0) 
        mousebutton = event 
      EndIf 
    ElseIf Event = #WM_RBUTTONDBLCLK 
      timer = 0 
      KillTimer_(WindowID(0),0) 
      mousebutton = 0 
      Debug "Right doubleclick" 
      
    ElseIf Event = #WM_TIMER 
      timer = 0 
      KillTimer_(WindowID(0),0) 
      If mousebutton = #WM_LBUTTONDOWN 
        Debug "Left click" 
      ElseIf mousebutton = #WM_MBUTTONDOWN 
        Debug "Middle click" 
      ElseIf mousebutton = #WM_RBUTTONDOWN 
        Debug "Right click" 
      EndIf 
      mousebutton = 0 
    
    ElseIf Event = #PB_Event_CloseWindow 
      End 
    EndIf 
  ForEver 
EndIf

; IDE Options = PureBasic v4.00 (Windows - x86)
; Folding = -
; EnableXP
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: EventType() et Buttongadget ?

Message par Ar-S »

Yop, merci.
Je m'en suis effectivement sortie grâce à #WM_LBUTTONDOWN et des flags
Au final j'ai tout de même viré la gestion du clique droit qui compliquait le tout pour pas grand chose.
En fait je clique sur un bouton : "Play" pour lancer un morceau de musique, si je reclique => "Pause" etc... Et je souhaitais que le clique droit fasse "Stop" mais du coup j'ai créé un bouton "stop" ce qui est bien plus simple et moins source d'erreur pour l'utilisateur.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
gnozal
Messages : 832
Inscription : mar. 07/déc./2004 17:35
Localisation : France
Contact :

Re: [resolu] EventType() et Buttongadget ?

Message par gnozal »

Un subclassing devrait fonctionner aussi.

Exemple (Windows x86) :

Code : Tout sélectionner

;
; Enable Right-Click Event For ButtonGadget
;
;/
Import "" 
  PB_Gadget_SendGadgetCommand(Handle.l, EventType.l) 
EndImport 
Procedure RightClickForButtonCB(hwnd.l, message.l, wParam.l, lParam.l)
  Protected OldCallback, ReturnValue
  OldCallback = GetProp_(hwnd, "RC_CB")
  If OldCallback
    ReturnValue = CallWindowProc_(OldCallback, hwnd, message, wParam, lParam)
    Select message
      Case #WM_RBUTTONUP
       PB_Gadget_SendGadgetCommand(hwnd, #PB_EventType_RightClick)
      Case #WM_NCDESTROY
        RemoveProp_(hwnd, "RC_CB")
    EndSelect
  EndIf
  ProcedureReturn ReturnValue
EndProcedure
Procedure EnableRightClickForButton(GadgetNumber)
  Protected GadgetHandle
  If IsGadget(GadgetNumber)
    GadgetHandle = GadgetID(GadgetNumber)
    SetProp_(GadgetHandle, "RC_CB", SetWindowLongPtr_(GadgetHandle, #GWL_WNDPROC, @RightClickForButtonCB()))
  EndIf
EndProcedure
;/
If OpenWindow(0, 450, 200, 322, 185, "Right-clikc on button", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
  ButtonGadget(0, 17, 35, 91, 31, "0")
  EnableRightClickForButton(0)
  ButtonGadget(1, 113, 35, 91, 31, "1")
  EnableRightClickForButton(1)
  ButtonGadget(2, 209, 35, 91, 31, "2")
  EnableRightClickForButton(2)
  TextGadget(3, 18, 113, 282, 25, "", #PB_Text_Center)
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        If EventType() = #PB_EventType_RightClick
          Debug "button " + Str(EventGadget()) + " : right-click"
        ElseIf EventType() = #PB_EventType_LeftClick
          Debug "button " + Str(EventGadget()) + " : left-click"
        EndIf
      Case #PB_Event_CloseWindow
        CloseWindow(0)
        Break
    EndSelect
  ForEver
EndIf
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: [resolu] EventType() et Buttongadget ?

Message par Ar-S »

Merci gnozal, ça marche impeccablement.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Répondre