I'm trying to create a small webapp and I'm having trouble when I try to use events on a small window that launches from the main window. I put the code here:
Code: Select all
;EnableExplicit
#Window = 0
#window1 = 1
#Menu = 0
Enumeration
#btn
#btn2
#btn3
#Str1
#Str2
#sound1
EndEnumeration
Global ww, hh
Define desktop = ExamineDesktops()
ww = DesktopWidth(desktop)
hh = DesktopHeight(desktop)
If ww < 400 Or hh < 400 : End : EndIf
Declare Handler2()
Procedure open_window_login()
OpenWindow(#Window1, 0, 0, 130, 110, "login test", #PB_Window_ScreenCentered | #PB_Window_TitleBar)
StringGadget(#Str1, 5, 5, 120, 30, "Nickname", #PB_String_PlaceHolder)
StringGadget(#Str2, 5, 40, 120, 30, "Password", #PB_String_PlaceHolder)
ButtonGadget(#btn2, 5, 75, 60, 30, "Ok")
ButtonGadget(#btn3, 65, 75, 60, 30, "Cancel")
BindGadgetEvent(#PB_Event_Gadget, @Handler2())
EndProcedure
Procedure Handler2()
Debug "#btn2 = " + #btn2
Debug "#btn3 = " + #btn3
Event = EventGadget()
Debug "Event = " + Event;This is where things go wrong. The gadget never equals 2 and I don't understand why.
Select Event
Case #btn2
MessageRequester("Button click event on gadget #btn2")
Case #btn3
MessageRequester("Button click event on gadget #btn3");It never happens that way...
EndSelect
EndProcedure
Procedure Handler()
DisplayPopupMenu(#Menu, WindowID(#Window))
EndProcedure
Procedure EventsMenu()
Select EventMenu()
Case 0 To 2
MessageRequester("Menu")
Case 3
open_window_login();It is this choice that must be tested.
Case 4
PlaySound(#sound1)
EndSelect
EndProcedure
If ww < hh
OpenWindow(#Window, 0, 0, ww, hh, "test.sb", #PB_Window_Background)
Else
OpenWindow(#Window, 0, 0, 500, 770, "test.sb", #PB_Window_ScreenCentered | #PB_Window_TitleBar)
EndIf
ButtonGadget(#btn, 5, 5, 30, 30, Chr($2630))
GadgetToolTip(#btn, "Menu")
If CreatePopupMenu(#Menu)
MenuItem(0, "New")
MenuItem(1, "Open")
MenuItem(2, "Save as")
MenuItem(3, "login");It is this choice that must be tested.
MenuItem(4, "Play sound")
EndIf
If InitSound()
LoadSound(#sound1, "./res/Recording_10.mp3")
EndIf
BindGadgetEvent(#btn, @Handler())
BindEvent(#PB_Event_Menu, @EventsMenu())
It's in the Handler2() procedure that things are wrong and I don't know why?
I would like to point out that before I had already programmed some small utilities in Purebasic and that I used the EventDesigner tool to manage my Events. And so, I don't really know how it works and it poses a problem for me in Spiderbasic because I no longer have either Formdesigner or Eventdesigner.
If you have a link to a tutorial on Events, I'm interested. Or a fairly complete code example that would help me understand?
Thank you in advance for your answers.