Page 1 of 1

Gadgets and Events....

Posted: Thu Jun 05, 2003 5:40 pm
by Skipsy
Hello,

The following code does 2 strange things :

Code: Select all

#Window_0 = 0
#MenuBar_25 = 0
#MENU_1  = 101
#MENU_2  = 102

#Gadget_1 = 10

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 211, 114, 515, 491, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
    If CreateMenu(#MenuBar_25, WindowID())
      MenuTitle("File")
      MenuItem(#MENU_1, "Save")
      MenuItem(#MENU_2, "Quit")
      MenuTitle("About")
    EndIf
    
    If CreateGadgetList(WindowID())
      ButtonGadget(#Gadget_1, 105, 30, 45, 30, "B1")
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  Event = WindowEvent()

Menu = EventMenuID() 
  Delay(1)
  
  StartDrawing(WindowOutput())
  Locate( 50, 120 )
  DrawText("MENU "+ Str( Menu  ) + "     ")
  StopDrawing()
  
Until Event = #PB_EventCloseWindow
End
First thing :
If I click on File and select 'Save' value 101 is displayed until I select
another item. EventMenuID() still detect 'Save' selected when the menu
is closed.

Second :
EventMenuID() detects when I click on the button #gadget1. I thought
it was supposed to only detect events on menu... as EventGadget() is
supposed to do with gadgets ONLY.

Any idea :?:

Posted: Thu Jun 05, 2003 6:25 pm
by Pupil
You should check the result from WindowEvent() to determine if it's a gadget event or a menu event or for that matter any other event that is supported..

An event loop typically looks something like this:

Code: Select all

Repeat
  event = WindowEvent()
  if event = 0
    delay(1)
  else
    if event = #PB_Event_Gadget
      select EventGadgetID()
        case #GAD1
           ...
      endselect
    elseif event = #PB_Event_Menu
      select EventMenuID()
        case #Menu1
           ...
      endselect
    endif
  endif
until event = #PB_Event_CloseWindow
Note: I typed this from memory so the constants might be misspelled....

Posted: Thu Jun 05, 2003 7:09 pm
by fsw
If you use WaitWindowEvent() you don't have to use a delay.

Posted: Fri Jun 06, 2003 10:31 am
by Skipsy
of course !
It is so obvious... :oops:

Thks.