Page 2 of 2

Re: Understanding how the events works

Posted: Mon Jun 25, 2012 1:17 am
by BasicallyPure
Sorry I can't help with anything related to ProGui.
takis76 wrote:... I am asking and for PureBasic native gadgets material.
You probably have figured this much out already, Just another example,
someone may find it useful.

I think this is about all you can do with ToolBar events using native PureBasic.
It's all I know how to do anyway.
As you know, only the 'toggle' mode tool button supports 'GetToolBarButtonState()'.

Code: Select all

; example for event handling of menus, toolBars, and gadgets
; #PB_Any is used when possible with variables in place of constants

; Tool buttons must be numbered with menu items
Enumeration
   #Menu_Item_A
   #Menu_Item_B
   #Menu_Item_C
   #Menu_Item_D
   #Tool_Button_AA
   #Tool_Button_BB
   #Tool_Button_CC
EndEnumeration

Global WinNumber = OpenWindow(#PB_Any, 10, 200, 300, 200, "Window title")

; create menu and add menu items
Global MenuNumber = CreateMenu(#PB_Any, WindowID(WinNumber))
MenuTitle("Menu 1")
   MenuItem(#Menu_Item_A, "Item_A")
   MenuItem(#Menu_Item_B, "Exit")
MenuTitle("Menu 2")
   MenuItem(#Menu_Item_C, "Item_C")
   MenuItem(#Menu_Item_D, "Item_D")
   
; create tool bar and tool tips
Global ToolBarNumber = CreateToolBar(#PB_Any, WindowID(WinNumber))
   ToolBarStandardButton(#Tool_Button_AA, #PB_ToolBarIcon_New)
   ToolBarToolTip(ToolBarNumber, #Tool_Button_AA, "New") 
   ToolBarStandardButton(#Tool_Button_BB, #PB_ToolBarIcon_Cut)
   ToolBarToolTip(ToolBarNumber, #Tool_Button_BB, "Cut") 
   ToolBarStandardButton(#Tool_Button_CC, #PB_ToolBar_Toggle, #PB_ToolBar_Toggle)
   ToolBarToolTip(ToolBarNumber, #Tool_Button_CC, "Toggle") 

; create gadgets
Global Button_A = ButtonGadget(#PB_Any, 20, 20, 50, 25, "A")
Global Button_B = ButtonGadget(#PB_Any, 20, 60, 50, 25, "B")

Repeat ; event loop
   Event = WaitWindowEvent() ; detect all window events
   Select Event ; what type of event was it?
         
      Case #PB_Event_Gadget ; the event was from a gadget
         
         Select EventGadget() ; which gadget produced the event?
            Case Button_A
               Debug "Button A generated an event"
            Case Button_B
               Debug "Button B generated an event"
         EndSelect
         
      Case #PB_Event_Menu ; the event was from a menu or toolbar item
         
         Select EventMenu() ; which menu or toolbar item produced the event?
            Case #Menu_Item_A
               Debug "Menu Item_A generated an event"
               
            Case #Menu_Item_B
               Debug "Menu Item_B generated an event"
               End
               
            Case #Menu_Item_C
               Debug "Menu Item_C generated an event"
               
            Case #Menu_Item_D
               Debug "Menu Item_D generated an event"
               
            Case #Tool_Button_AA
               Debug "Toolbar button 'AA' generated an event"
               
            Case #Tool_Button_BB
               Debug "Toolbar button 'BB' generated an event"
               
            Case #Tool_Button_CC
               If GetToolBarButtonState(ToolBarNumber, #Tool_Button_CC)
                  Debug "Toolbar button 'CC' is toggled 'On'"
               Else
                  Debug "Toolbar button 'CC' is toggled 'Off'"
               EndIf
         EndSelect
         
      Case #PB_Event_CloseWindow
         Debug "Close window event detected"
         Break ;exit the loop
   EndSelect
ForEver

End

;more code can go here, Procedures, DataSections etc.

Re: Understanding how the events works

Posted: Mon Jun 25, 2012 7:01 am
by IdeasVacuum
Nice example BasicallyPure 8)

Takis76, have you seen these? :
Free Book about Programming with PB by Kale It includes source code and Win API references.

PB Survival Guide by Bluez Well written in a user-friendly style.

For those used to using other programming languages: Rosetta Code
Rosetta Code has working code snippets covering a variety of things and languages can be compared.

Also, there are some fabulous, well maintained User Libs that extend the capability of PB. Take a look at:
Gnozal's Libs and ABBKlaus's Libs

Visual Form Designers

You might also like to take a look at Gnozal's PureForm - it works well and it's free. This is the one I like to use.

There is also PureVision - it's a commercial form designer and offers some very cool capabilities.