Gadgets and Events....

Just starting out? Need help? Post your questions and find answers here.
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Gadgets and Events....

Post 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 :?:
Beware of the man who has the solution before he understands the problem...
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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....
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

If you use WaitWindowEvent() you don't have to use a delay.
Skipsy
User
User
Posts: 98
Joined: Wed Apr 30, 2003 12:26 pm
Location: France

Post by Skipsy »

of course !
It is so obvious... :oops:

Thks.
Beware of the man who has the solution before he understands the problem...
Post Reply