Gestion des evenements sur les menus

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Droopy
Messages : 1151
Inscription : lun. 19/juil./2004 22:31

Gestion des evenements sur les menus

Message par Droopy »

Si je créé un menu + un CreateToolBar j'ai deux menus.

Comment savoir dans ma boucle d'évèment quel menu a généré l'évènement ?
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Essaye ça

Code : Tout sélectionner

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_SizeGadget, "ToolBar example")
  
  If CreateToolBar(0, WindowID())
  
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
    
    ToolBarSeparator()
    
    ToolBarStandardButton(3, #PB_ToolBarIcon_Print)
    ToolBarToolTip(3, "Print")
    
    ToolBarStandardButton(4, #PB_ToolBarIcon_Find)
    ToolBarToolTip(4, "Find a document")
    
    ToolBarSeparator()
    
    ToolBarImageButton(5, LoadImage(0, "Data\NewProject.ico"))
    ToolBarImageButton(10, LoadImage(5, "Data\SaveProject.ico"))
  EndIf
  
  
  If CreateMenu(1, WindowID())
    MenuTitle("Project")
    MenuItem(0, "New")
    MenuItem(1, "Open")
    MenuItem(2, "Save")
  EndIf
  
  ;
  ; Attach our previously created ToolBar to this window
  ;
  
  DisableToolBarButton(2, 1) ; Disable the button '2'
  
  ;
  ; The event loop. A ToolBar event is like a Menu event (as tools are shortcut for menu the most
  ; of the time). This is handy, as if the ToolBar buttons and the MenuItem have the same ID, then
  ; the same operation can be done on both action without any adds..
  ;
  
  Repeat
    EventID = WaitWindowEvent()
    
    ;Debug EventID
    ;Debug EventGadgetID()
    
    Select EventID
      
      Case #PB_Event_Menu
        Select EventlParam()
          Case 0 : MessageRequester("Information", "Menu ID: "+Str(EventMenuID()), 0)
          Default: MessageRequester("Information", "ToolBar ID: "+Str(EventMenuID()), 0)
        EndSelect
        
        
      Case #PB_Event_CloseWindow  ; If the user has pressed on the close button
        Quit = 1
        
    EndSelect
    
  Until Quit = 1
  
EndIf
Avatar de l’utilisateur
Droopy
Messages : 1151
Inscription : lun. 19/juil./2004 22:31

Message par Droopy »

Merci, c'est exactement ce que je recherchais

A+
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Ca fera 15 euros :idea:
Avatar de l’utilisateur
venom
Messages : 3138
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Message par venom »

a se prix la tu va etre rapidement riche :wink: :lol:

0/10 je sort
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Répondre