It is currently Fri Apr 10, 2020 11:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 61 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: IsValidPBEvent?
PostPosted: Sun Nov 15, 2015 8:17 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2349
Location: Germany
I do not know where the problem lies.
The help is exactly when an event has occurred.
Only then can be queried with the correct function of the origin of the events
Everything else is invalid ...
Code:
Procedure Main()
 
  Protected event
 
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 800, 600, "Events")
   
    ButtonGadget(0, 10, 10, 120, 25, "Good bye...")
   
    Repeat
      event = WaitWindowEvent()
      Select event
         
        Case #PB_Event_Menu
          Select EventMenu()
             
          EndSelect
         
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0 : Break
             
          EndSelect
         
        Case #PB_Event_SysTray
          Select EventGadget()
             
          EndSelect
         
        Case #PB_Event_Timer
          Select EventTimer()
             
          EndSelect
         
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0 : Break
             
          EndSelect
         
        Case #PB_Event_Repaint
          Select EventWindow()
             
          EndSelect
             
        Case #PB_Event_SizeWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_MoveWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_MinimizeWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_MaximizeWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_RestoreWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_ActivateWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_DeactivateWindow
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_WindowDrop
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_GadgetDrop
          Select EventGadget()
             
          EndSelect
         
        Case #PB_Event_RightClick
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_LeftClick
          Select EventWindow()
             
          EndSelect
         
        Case #PB_Event_LeftDoubleClick
          Select EventWindow()
             
          EndSelect
         
      EndSelect
     
    ForEver
   
  EndIf
 
EndProcedure : Main()

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Sun Nov 15, 2015 11:35 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 811
Code:
DeclareModule Window
  EnableExplicit
 
  Declare Activate( Window )
  Declare Deactivate( Window )
  Declare Event( State = #True )
  Declare WaitWindowClose( Window = #PB_All )
  Declare BindWindowEvent( Window, *CallBack, Event = #PB_All )
  Declare UnbindWindowEvent( Window, *CallBack, Event = #PB_All )
EndDeclareModule

Module Window
  EnableExplicit
 
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Import ""
    CompilerElse
      ImportC ""
      CompilerEndIf
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
     
      PB_Object_Count( PB_Objects )
     
      PB_Window_Objects.i
      PB_Gadget_Objects.i
      PB_Image_Objects.i
    EndImport
   
    #PB_Event_Window = #PB_Event_FirstCustomValue
 
  Procedure Event_Activate( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_ActivateWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Deactivate( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_DeactivateWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Repaint( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_Repaint ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_LeftClick( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_LeftClick ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_LeftDoubleClick( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_LeftDoubleClick ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_RightClick( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_RightClick ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Move( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_MoveWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Size( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_SizeWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Minimize( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_MinimizeWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Maximize( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_MaximizeWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Restore( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_RestoreWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Close( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_CloseWindow ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Menu( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_Menu ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
  Procedure Event_Gadget( )
    If IsWindow( EventWindow())
      SetEnvironmentVariable(Str(EventWindow()), Str(#PB_Event_Gadget ))
      PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
    EndIf
  EndProcedure
 
  Procedure BindWindowEvent( Window, *CallBack, Event = #PB_All )
    If Event = #PB_All
      BindEvent( #PB_Event_Window, *CallBack, Window )
    Else
      BindEvent( Event, *CallBack, Window )
    EndIf
  EndProcedure
 
  Procedure UnbindWindowEvent( Window, *CallBack, Event = #PB_All )
    If Event = #PB_All
      UnbindEvent( #PB_Event_Window, *CallBack, Window )
    Else
      UnbindEvent( Event, *CallBack, Window )
    EndIf
  EndProcedure
 
  Procedure Activate( Window )
    BindEvent(#PB_Event_DeactivateWindow, @Event_Deactivate( ),Window)
    BindEvent(#PB_Event_ActivateWindow, @Event_Activate( ),Window)
   
    BindEvent(#PB_Event_Repaint, @Event_Repaint( ),Window)
   
    BindEvent(#PB_Event_LeftClick, @Event_LeftClick( ),Window)
    BindEvent(#PB_Event_LeftDoubleClick, @Event_LeftDoubleClick( ),Window)
    BindEvent(#PB_Event_RightClick, @Event_RightClick( ),Window)
   
    BindEvent(#PB_Event_MoveWindow, @Event_Move( ),Window)
    BindEvent(#PB_Event_SizeWindow, @Event_Size( ),Window)
   
    BindEvent(#PB_Event_MinimizeWindow, @Event_Minimize( ),Window)
    BindEvent(#PB_Event_MaximizeWindow, @Event_Maximize( ),Window)
    BindEvent(#PB_Event_RestoreWindow, @Event_Restore( ),Window)
    BindEvent(#PB_Event_CloseWindow, @Event_Close( ),Window)
   
    BindEvent(#PB_Event_Menu, @Event_Menu( ),Window)
    BindEvent(#PB_Event_Gadget, @Event_Gadget( ),Window)
  EndProcedure
  Procedure Deactivate( Window )
    UnbindEvent(#PB_Event_DeactivateWindow, @Event_Deactivate( ),Window)
    UnbindEvent(#PB_Event_ActivateWindow, @Event_Activate( ),Window)
   
    UnbindEvent(#PB_Event_Repaint, @Event_Repaint( ),Window)
   
    UnbindEvent(#PB_Event_LeftClick, @Event_LeftClick( ),Window)
    UnbindEvent(#PB_Event_LeftDoubleClick, @Event_LeftDoubleClick( ),Window)
    UnbindEvent(#PB_Event_RightClick, @Event_RightClick( ),Window)
   
    UnbindEvent(#PB_Event_MoveWindow, @Event_Move( ),Window)
    UnbindEvent(#PB_Event_SizeWindow, @Event_Size( ),Window)
   
    UnbindEvent(#PB_Event_MinimizeWindow, @Event_Minimize( ),Window)
    UnbindEvent(#PB_Event_MaximizeWindow, @Event_Maximize( ),Window)
    UnbindEvent(#PB_Event_RestoreWindow, @Event_Restore( ),Window)
    UnbindEvent(#PB_Event_CloseWindow, @Event_Close( ),Window)
   
    UnbindEvent(#PB_Event_Menu, @Event_Menu( ),Window)
    UnbindEvent(#PB_Event_Gadget, @Event_Gadget( ),Window)
  EndProcedure
 
  Procedure Event( State = #True )
    If IsWindow( EventWindow())
      If State = #True
        ProcedureReturn Val( GetEnvironmentVariable( Str(EventWindow())) )
      Else
        Debug State
        SetEnvironmentVariable(Str(EventWindow()), Str( State ))
        ;PostEvent(#PB_Event_Window, EventWindow(), EventGadget(), EventType(), EventData())
     EndIf
    EndIf
  EndProcedure
  Procedure WaitWindowClose( Window = #PB_All )
    Protected EnumWindow
   
    If PB_Window_Objects
      PB_Object_EnumerateStart( PB_Window_Objects )
      While PB_Object_EnumerateNext( PB_Window_Objects, @EnumWindow )
        Activate( EnumWindow )
      Wend
      PB_Object_EnumerateAbort( PB_Window_Objects )
    EndIf
   
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_Window
          Select Event()
            Case #PB_Event_CloseWindow
              If EventWindow() = Window
                Break
              Else
                CloseWindow( EventWindow() )
                If Not PB_Object_Count( PB_Window_Objects )
                  Break
                EndIf
              EndIf
          EndSelect
        Default
          ;
          If Window ! #PB_All And Not IsWindow(Window)
            Break
          EndIf
      EndSelect
    ForEver
  EndProcedure
EndModule

; example

UseModule Window
   
Procedure Event_Gadgets( )
  If IsWindow( EventWindow())
    Select EventType()
      Case #PB_EventType_MouseEnter       :Debug ""+EventGadget()+" 2_1_EventType_MouseEnter"       ; The Mouse Cursor entered the Gadget
      Case #PB_EventType_MouseLeave       :Debug ""+EventGadget()+" 2_1_EventType_MouseLeave"       ; The Mouse Cursor left the Gadget
      Case #PB_EventType_MouseMove        :Debug ""+EventGadget()+" 2_1_EventType_MouseMove"        ; The Mouse Cursor moved
      Case #PB_EventType_MouseWheel       :Debug ""+EventGadget()+" 2_1_EventType_MouseWheel"       ; The Mouse wheel was moved
      Case #PB_EventType_LeftButtonDown   :Debug ""+EventGadget()+" 2_1_EventType_LeftButtonDown"   ; The left Mouse button was pressed
      Case #PB_EventType_LeftButtonUp     :Debug ""+EventGadget()+" 2_1_EventType_LeftButtonUp"     ; The left Mouse button was released
      Case #PB_EventType_LeftClick        :Debug ""+EventGadget()+" 2_1_EventType_LeftClick"        ; A click With the left Mouse button
      Case #PB_EventType_LeftDoubleClick  :Debug ""+EventGadget()+" 2_1_EventType_LeftDoubleClick"  ; A double-click With the left Mouse button
      Case #PB_EventType_RightButtonDown  :Debug ""+EventGadget()+" 2_1_EventType_RightButtonDown"  ; The right Mouse button was pressed
      Case #PB_EventType_RightButtonUp    :Debug ""+EventGadget()+" 2_1_EventType_RightButtonUp"    ; The right Mouse button was released
      Case #PB_EventType_RightClick       :Debug ""+EventGadget()+" 2_1_EventType_RightClick"       ; A click With the right Mouse button
      Case #PB_EventType_RightDoubleClick :Debug ""+EventGadget()+" 2_1_EventType_RightDoubleClick" ; A double-click With the right Mouse button
      Case #PB_EventType_MiddleButtonDown :Debug ""+EventGadget()+" 2_1_EventType_MiddleButtonDown" ; The middle Mouse button was pressed
      Case #PB_EventType_MiddleButtonUp   :Debug ""+EventGadget()+" 2_1_EventType_MiddleButtonUp"   ; The middle Mouse button was released
      Case #PB_EventType_Focus            :Debug ""+EventGadget()+" 2_1_EventType_Focus"            ; The Gadget gained keyboard focus
      Case #PB_EventType_LostFocus        :Debug ""+EventGadget()+" 2_1_EventType_LostFocus"        ; The Gadget lost keyboard focus
      Case #PB_EventType_KeyDown          :Debug ""+EventGadget()+" 2_1_EventType_KeyDown"          ; A key was pressed
      Case #PB_EventType_KeyUp            :Debug ""+EventGadget()+" 2_1_EventType_KeyUp"            ; A key was released
      Case #PB_EventType_Input            :Debug ""+EventGadget()+" 2_1_EventType_Input"            ; Text input was generated 
       
      Case #PB_EventType_Change           :Debug ""+EventGadget()+" 2_1_EventType_Change"           ; Content change.
      Case #PB_EventType_DragStart        :Debug ""+EventGadget()+" 2_1_EventType_DragStart"        ; The user tries To start a Drag & Drop operation.
       
      Case #PB_EventType_Up               :Debug ""+EventGadget()+" 2_1_EventType_Up"               ; The 'Up' button was pressed.
      Case #PB_EventType_Down             :Debug ""+EventGadget()+" 2_1_EventType_Down"             ; The 'Down' button was pressed.
       
      Case #PB_EventType_TitleChange      :Debug ""+EventGadget()+" 2_1_EventType_TitleChange"      ; The page title changed (Windows only).
      Case #PB_EventType_StatusChange     :Debug ""+EventGadget()+" 2_1_EventType_StatusChange"     ; The status message changed (Windows only).
      Case #PB_EventType_DownloadStart    :Debug ""+EventGadget()+" 2_1_EventType_DownloadStart"    ; A page download started  (Windows, OS X).
      Case #PB_EventType_DownloadProgress :Debug ""+EventGadget()+" 2_1_EventType_DownloadProgress" ; Progress info is available With GetGadgetAttribute() (Windows only).
      Case #PB_EventType_DownloadEnd      :Debug ""+EventGadget()+" 2_1_EventType_DownloadEnd"      ; A page download ended Or aborted (Windows, OS X).
      Case #PB_EventType_PopupWindow      :Debug ""+EventGadget()+" 2_1_EventType_PopupWindow"      ; A popup Window was blocked (Windows only).
      Case #PB_EventType_PopupMenu        :Debug ""+EventGadget()+" 2_1_EventType_PopupMenu"        ; The popup menu was blocked (display a custom menu here) (Windows only).
    EndSelect
  EndIf
EndProcedure


Procedure Event_Window_1_1( )
  Select Event()
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 1_1_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 1_1_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 1_1_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 1_1_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 1_1_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                          ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 1_1_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 1_1_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 1_1_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 1_1_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 1_1_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 1_1_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 1_1_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 1_1_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 1_1_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 1_1_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 1_1_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 1_1_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 1_1_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure


Procedure Event_Window_2_1( )
  Select Event()
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 2_1_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 2_1_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 2_1_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 2_1_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 2_1_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                          ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 2_1_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 2_1_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 2_1_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 2_1_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 2_1_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 2_1_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 2_1_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 2_1_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 2_1_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 2_1_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 2_1_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 2_1_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 2_1_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure

Procedure Event_Window_2_2( )
  Select Event()
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 2_2_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 2_2_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 2_2_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 2_2_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 2_2_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                          ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 2_2_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 2_2_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 2_2_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 2_2_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 2_2_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 2_2_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 2_2_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 2_2_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 2_2_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 2_2_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 2_2_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 2_2_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 2_2_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure

Procedure Event_Window_2_3( )
  Select Event()
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 2_3_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 2_3_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 2_3_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 2_3_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 2_3_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                          ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 2_3_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 2_3_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 2_3_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 2_3_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 2_3_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 2_3_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 2_3_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 2_3_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 2_3_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 2_3_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 2_3_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 2_3_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 2_3_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure


Procedure Event_Window_1( )
  Select Event( )
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 1_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 1_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 1_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 1_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 1_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                        ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 1_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 1_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 1_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 1_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 1_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 1_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 1_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 1_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 1_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 1_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 1_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 1_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 1_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure

Procedure Event_Window_2( )
  Select Event( )
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 2_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 2_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 2_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 2_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 2_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                        ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 2_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 2_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 2_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 2_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 2_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 2_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 2_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 2_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 2_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 2_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 2_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 2_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 2_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure

Procedure Event_Window_3( )
  Select Event( )
    Case #PB_Event_Menu             :Debug ""+EventWindow()+" 3_Event_Menu"             ; a menu has been selected
    Case #PB_Event_Gadget           :Debug ""+EventWindow()+" 3_Event_Gadget"           ; a Gadget has been pushed
    Case #PB_Event_SysTray          :Debug ""+EventWindow()+" 3_Event_SysTray"          ; an icon in the systray zone was clicked
    Case #PB_Event_Timer            :Debug ""+EventWindow()+" 3_Event_Timer"            ; a timer has reached its timeout
    Case #PB_Event_CloseWindow      :Debug ""+EventWindow()+" 3_Event_CloseWindow"      ; the Window close Gadget has been pushed
                                                                                        ;Case #PB_Event_Repaint          :Debug ""+EventWindow()+" 3_Event_Repaint"          ; the Window content has been destroyed And must be repainted (useful For 2D graphics operations)
    Case #PB_Event_SizeWindow       :Debug ""+EventWindow()+" 3_Event_SizeWindow"       ; the Window has been resized
    Case #PB_Event_MoveWindow       :Debug ""+EventWindow()+" 3_Event_MoveWindow"       ; the Window has been moved
    Case #PB_Event_MinimizeWindow   :Debug ""+EventWindow()+" 3_Event_MinimizeWindow"   ; the Window has been minimized
    Case #PB_Event_MaximizeWindow   :Debug ""+EventWindow()+" 3_Event_MaximizeWindow"   ; the Window has been maximized
    Case #PB_Event_RestoreWindow    :Debug ""+EventWindow()+" 3_Event_RestoreWindow"    ; the Window has been restored To normal Size (either from a minimum Or maximum Size)
    Case #PB_Event_ActivateWindow   :Debug ""+EventWindow()+" 3_Event_ActivateWindow"   ; the Window has been activated (got the focus)
    Case #PB_Event_DeactivateWindow :Debug ""+EventWindow()+" 3_Event_DeactivateWindow" ; the Window has been deactivated (lost the focus)
    Case #PB_Event_WindowDrop       :Debug ""+EventWindow()+" 3_Event_WindowDrop"       ; a Drag & Drop operation was finished on a Window
    Case #PB_Event_GadgetDrop       :Debug ""+EventWindow()+" 3_Event_GadgetDrop"       ; a Drag & Drop operation was finished on a Gadget
    Case #PB_Event_RightClick       :Debug ""+EventWindow()+" 3_Event_RightClick"       ; a right Mouse button click has occurred on the Window. This can be useful To display a popup menu
    Case #PB_Event_LeftClick        :Debug ""+EventWindow()+" 3_Event_LeftClick"        ; a left Mouse button click has occurred on the Window
    Case #PB_Event_LeftDoubleClick  :Debug ""+EventWindow()+" 3_Event_LeftDoubleClick"  ; a left Mouse button double-click has occurred on the Window
  EndSelect
EndProcedure


Define Width =135
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Width - 35 ; bug in windows
CompilerEndIf


OpenWindow(1, 50, 100, Width, 205, "Event_1")
ButtonGadget(11,5,5,125,25,"1_1")
ButtonGadget(12,5,35,125,25,"1_2")

ButtonGadget(13,5,75,125,25,"1_3")
ButtonGadget(14,5,105,125,25,"1_4")

ButtonGadget(15,5,145,125,25,"1_5")
ButtonGadget(16,5,175,125,25,"1_6")

OpenWindow(2, 250, 100, Width, 205, "Event_2")
ButtonGadget(21,5,5,125,25,"2_1")
ButtonGadget(22,5,35,125,25,"2_2")

ButtonGadget(23,5,75,125,25,"2_3")
ButtonGadget(24,5,105,125,25,"2_4")

ButtonGadget(25,5,145,125,25,"2_5")
ButtonGadget(26,5,175,125,25,"2_6")

OpenWindow(3, 450, 100, Width, 205, "Event_3")
ButtonGadget(31,5,5,125,25,"3_1")
ButtonGadget(32,5,35,125,25,"3_2")

ButtonGadget(33,5,75,125,25,"3_3")
ButtonGadget(34,5,105,125,25,"3_4")

ButtonGadget(35,5,145,125,25,"3_5")
ButtonGadget(36,5,175,125,25,"3_6")


Procedure Event_Window_0( )
  Select Event()
    Case #PB_Event_Gadget 
      Select EventType()
        Case #PB_EventType_LeftClick
          Select EventGadget()
            Case 1 :Activate( 1 )
            Case 2 :Deactivate( 1 )
            Case 3 :Activate( 2 )
            Case 4 :Deactivate( 2 )
            Case 5 :Activate( 3 )
            Case 6 :Deactivate( 3 )
          EndSelect
      EndSelect
     
    Case #PB_Event_CloseWindow
      If MessageRequester("предупреждение","Закрыть это окно "+Str(EventWindow()),#PB_MessageRequester_YesNo ) = #PB_MessageRequester_Yes
        CloseWindow(EventWindow())
      EndIf
     
  EndSelect
EndProcedure
;
OpenWindow(0, 600, 200, Width, 205, "Event_0", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(1,5,5,125,25,"BindAllEvent_1")
ButtonGadget(2,5,35,125,25,"UnBindAllEvent_1")

ButtonGadget(3,5,75,125,25,"BindAllEvent_2")
ButtonGadget(4,5,105,125,25,"UnBindAllEvent_2")

ButtonGadget(5,5,145,125,25,"BindAllEvent_3")
ButtonGadget(6,5,175,125,25,"UnBindAllEvent_3")



BindWindowEvent( 0, @Event_Window_0());, #PB_Event_Gadget )

BindWindowEvent( 1, @Event_Window_1() )
BindWindowEvent( 2, @Event_Window_2() )
BindWindowEvent( 3, @Event_Window_3() )

BindWindowEvent( 1, @Event_Window_1_1() )

BindWindowEvent( 2, @Event_Window_2_3() )
BindWindowEvent( 2, @Event_Window_2_2() )
BindWindowEvent( 2, @Event_Window_2_1() )

BindWindowEvent( 1, @Event_Gadgets(), #PB_Event_Gadget )
BindWindowEvent( 2, @Event_Gadgets(), #PB_Event_Gadget )
BindWindowEvent( 3, @Event_Gadgets(), #PB_Event_Gadget )

WaitWindowClose( 0 )

Debug "close"
End



Last edited by mestnyi on Mon Nov 16, 2015 6:41 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Mon Nov 16, 2015 5:24 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Mar 24, 2011 12:40 am
Posts: 536
Location: Iowa, USA
collectordave wrote:
I simply want all valid PB events that happen on a window to be sent to that windows Event_Handler procedure.

Only considering the quote above I think this code could be used as a template to achieve the results you want.
As you can see it only has one event loop to dispatch the events to the appropriate procedure.
A separate procedure is used to handle each windows events.
This example assumes there are five possible windows that might generate events.
This code is of course incomplete as is, windows must be created, gadgets added, etc.
No binding of events is required.

I hope this helps.
Code:
Enumeration
   #Window_01
   #Window_02
   #Window_03
   #Window_04
   #Window_05
EndEnumeration

Global Quit = #False

Procedure HANDLE_WINDOW_01_EVENTS(event)
   Select event
      ; insert code for all events of interest
      ; Case ?
      ; Case ?
      ; etc...
   EndSelect
EndProcedure

Procedure HANDLE_WINDOW_02_EVENTS(event)
   Select event
      ; insert code for all events of interest
      ; Case ?
      ; Case ?
      ; etc...
   EndSelect
EndProcedure

Procedure HANDLE_WINDOW_03_EVENTS(event)
   Select event
      ; insert code for all events of interest
      ; Case ?
      ; Case ?
      ; etc...
   EndSelect
EndProcedure

Procedure HANDLE_WINDOW_04_EVENTS(event)
   Select event
      ; insert code for all events of interest
      ; Case ?
      ; Case ?
      ; etc...
   EndSelect
EndProcedure

Procedure HANDLE_WINDOW_05_EVENTS(event)
   Select event
      ; insert code for all events of interest
      ; Case ?
      ; Case ?
      ; etc...
   EndSelect
EndProcedure


Repeat ; Main Event Loop
   Define event = WaitWindowEvent()
   Select EventWindow()
      Case #Window_01 : HANDLE_WINDOW_01_EVENTS(event)
      Case #Window_02 : HANDLE_WINDOW_02_EVENTS(event)
      Case #Window_03 : HANDLE_WINDOW_03_EVENTS(event)
      Case #Window_04 : HANDLE_WINDOW_04_EVENTS(event)
      Case #Window_05 : HANDLE_WINDOW_05_EVENTS(event)
   EndSelect
Until Quit = #True

_________________
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Mon Nov 16, 2015 3:38 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3651
Location: Utah, USA
BasicallyPure wrote:
Only considering the quote above I think this code could be used as a template to achieve the results you want.
As you can see it only has one event loop to dispatch the events to the appropriate procedure.


You can't use EventWindow() reliably until you know that it is a valid PB event first.

@Edit: Fred made a clarifying statement in his post a few messages down below. Which states that you can use EventWindow() reliably without checking the event first. EventWindow() will return -1 if it is not a valid event or the window number if it is.

_________________
Image


Last edited by Demivec on Sat Jan 02, 2016 7:42 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Mon Nov 16, 2015 3:59 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1771
BasicallyPure's approach is fine - I use something similar all the time.

Demivec wrote:
You can't use EventWindow() reliably until you know that it is a valid PB event first.


It's harmless when used this way.
Some OS events might be routed to your window handlers,
but assuming your procedure only reacts to "valid" #PB events anyway, there will be no side effects.


EDIT:
You can ignore "non-valid" events in a handler procedure, just like you would ignore them in a main event loop.

Code:
Procedure HandleWindow0(Event.i)
  If (Event = #PB_Event_Gadget)
    Debug "Clicked button in Window 0"
  ElseIf (Event = #PB_Event_CloseWindow)
    CloseWindow(0)
    Debug "Closed Window 0"
  EndIf
EndProcedure

Procedure HandleWindow1(Event.i)
  If (Event = #PB_Event_Gadget)
    Debug "Clicked button in Window 1"
  ElseIf (Event = #PB_Event_CloseWindow)
    CloseWindow(1)
    Debug "Closed Window 1"
  EndIf
EndProcedure

OpenWindow(0, 100, 100, 200, 100, "Window 0", #PB_Window_SystemMenu)
  ButtonGadget(0, 20, 20, 160, 25, "Trigger #PB_Event_Gadget")
OpenWindow(1, 300, 300, 200, 100, "Window 1", #PB_Window_SystemMenu)
  ButtonGadget(1, 20, 20, 160, 25, "Trigger #PB_Event_Gadget")

Repeat
  Event = WaitWindowEvent()
  Select (EventWindow())
    Case 0 : HandleWindow0(Event)
    Case 1 : HandleWindow1(Event)
  EndSelect
Until (Not (IsWindow(0) Or IsWindow(1)))


BindEvent()s can also be used if you don't like a Select EventWindow() in the main loop.

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Mon Nov 16, 2015 4:22 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14021
Location: France
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Mon Nov 16, 2015 7:17 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2306
Location: Singapore
Fred wrote:
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.
Clearly, great examples to modulate the handling of multiple windows.

But, while this too may be "safe", would you recommend such an approach as efficient? Or even necessary?
collectordave wrote:
Code:
Procedure IsValidPBEvent(event)
  Select event
    Case  #PB_Event_Menu            ,
          #PB_Event_Gadget          ,
          #PB_Event_SysTray         ,
          #PB_Event_Timer           ,
          #PB_Event_CloseWindow     ,
          #PB_Event_Repaint         ,
          #PB_Event_SizeWindow      ,
          #PB_Event_MoveWindow      ,
          #PB_Event_MinimizeWindow  ,
          #PB_Event_MaximizeWindow  ,
          #PB_Event_RestoreWindow   ,
          #PB_Event_ActivateWindow  ,
          #PB_Event_DeactivateWindow,
          #PB_Event_WindowDrop      ,
          #PB_Event_GadgetDrop      ,
          #PB_Event_RightClick      ,
          #PB_Event_LeftClick       ,
          #PB_Event_LeftDoubleClick
      ProcedureReturn #True
    Default
      ProcedureReturn #False
  EndSelect ;event
EndProcedure
Important, only because it's being touted as an approach in a PureBasic tutorial at another BASIC site. :wink:

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 1:03 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
Quote:
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.


Sorry but not at all times.

If a valid PB event occurs on say window1 then you move the mouse to window 2 window 2 is reported by eventwindow() which is a valid window ID even for an non valid PB event.

This can be seen at

http://www.purebasic.fr/english/viewtopic.php?f=13&t=63778

So you need to check that the event being processed is a valid PB event.

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 4:25 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3651
Location: Utah, USA
Fred wrote:
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.

I am getting out my notebook and writing this down immediately. :)

Can this also be included in the help file too. There's been a few discussions on this recently and having this in the manual could've prevented some headaches.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 5:01 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1771
I agree with collectordave, that PB sometimes reports an "invalid" (OS) WindowEvent, with a "valid" EventWindow (not -1).
I've seen it happen, and maybe a small bug report should be written.

BUT I still see no harm!

You can pass an "invalid" event like WM_MOUSEMOVE through any handler.
It will have no effect, if you only handle "valid" PB events like #PB_Event_Gadget!

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 6:45 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2306
Location: Singapore
collectordave wrote:
Fred wrote:
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.
Sorry but not at all times.

So, I see that you've met the team leader. :lol:

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 7:04 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
In almost all cases no harm done.

I originally noticed this behaviour when I was actually setting the text of a stringgadget on the main form dependent upon a vqalue entered by the user on the second form, I placed the code after the call to eventwindow() which resulted in the evnet being passed to window two's event handler. After using window two to enter the data I was simply moving my mouse over other windows and the stringgadget was flashing.

That is the only scenario that I can think of where it can be a problem.

I now use this procedure in my programs and have had no bother at all in running them reliably.

I have reported this behaviour before and even requested that two letters be added to the PB documentation.

If EventWindow() returned -1 for a non valid pb event then no bother and no need to check for a valid pb event.

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 7:15 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3800
Location: Berlin, Germany
mk-soft wrote:
I do not know where the problem lies.
The help is exactly when an event has occurred.
Only then can be queried with the correct function of the origin of the events
Everything else is invalid ...

I agree.

kenmo wrote:
You can pass an "invalid" event like WM_MOUSEMOVE through any handler.
It will have no effect, if you only handle "valid" PB events like #PB_Event_Gadget!

I agree.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:13 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
Thanks to all for posting solutions.

Just to try and clear things up a little here is an event loop I use in my Database skeleton:-

Code:
Repeat
 
  event = WaitWindowEvent()
 
  If IsValidPBEvent(event)
         
    Select EventWindow() ;Select window. Just main and search form here
     
      Case frmMain
       
        Event_Handler(event)
       
      Case frmSearch
       
        SearchFrm::Ok = 0
        SearchFrm::Event_Handler(event)

        ;After Searchform events
        If SearchFrm::Ok = 1 ;User pressed the OK button
       
          CurrentRow = 1
          Criteria = SearchFrm::SearchString
          GetTotalRecords(Criteria)
          CheckRecords()
          If TotalRows > 0
            Displayrecord(CurrentRow)
          Else
            SetGadgetText(str_Record,"")
          EndIf
        EndIf
     
    EndSelect
 
  EndIf
     
ForEver


With the check for a valid PB event it works fine all the time.

Maybe not the place to mention this but you can see the line

SearchFrm::Event_Handler(event)

Which shows that I now also use another powerful feature of PB namely modules. Saves me having to invent sometimes hundreds of constant or variable names. Plus really helps with debugging.

It appears from all the replies that if I was to rewrite my event loop as below:-

Code:
Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
         
    Case #PB_Event_Gadget
     
      Select EventWindow() ;Select window. Just search form here
     
        Case frmMain
       
          Event_Handler(event)
       
        Case frmSearch
       
          SearchFrm::Ok = 0
          SearchFrm::Event_Handler(event)

          ;After Searchform events
          If SearchFrm::Ok = 1 ;User pressed the OK button
       
            CurrentRow.i = 1
            Criteria = SearchFrm::SearchString
            GetTotalRecords(Criteria)
            CheckRecords()
            If TotalRows > 0
              Displayrecord(CurrentRow)
            Else
              SetGadgetText(str_Record,"")
            EndIf
          EndIf
     
      EndSelect
 
  EndSelect
     
ForEver


All would be fine? Of course I would have to copy this over and over again for each event I wish a window to respond to! The lines

Select Event

Case #PB_Event_Gadget

are just checking that a valid PB event happened on a gadget and achieves the same result as the IsValid procedure. The advantage I gain from checking immediatly for a valid event is that I do not need lots of lines of code in my main event loop. I simply send the event to the correct window event handler.

Hope this clears this up a little.

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:24 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14021
Location: France
TI-994A wrote:
Fred wrote:
It's safe to use it like this because even if the event isn't supported EventWindow() will return -1, which isn't in the Select/Case. EventWindow() can either return a valid window or -1, no any random value.
Clearly, great examples to modulate the handling of multiple windows.

But, while this too may be "safe", would you recommend such an approach as efficient? Or even necessary?
collectordave wrote:
Code:
Procedure IsValidPBEvent(event)
  Select event
    Case  #PB_Event_Menu            ,
          #PB_Event_Gadget          ,
          #PB_Event_SysTray         ,
          #PB_Event_Timer           ,
          #PB_Event_CloseWindow     ,
          #PB_Event_Repaint         ,
          #PB_Event_SizeWindow      ,
          #PB_Event_MoveWindow      ,
          #PB_Event_MinimizeWindow  ,
          #PB_Event_MaximizeWindow  ,
          #PB_Event_RestoreWindow   ,
          #PB_Event_ActivateWindow  ,
          #PB_Event_DeactivateWindow,
          #PB_Event_WindowDrop      ,
          #PB_Event_GadgetDrop      ,
          #PB_Event_RightClick      ,
          #PB_Event_LeftClick       ,
          #PB_Event_LeftDoubleClick
      ProcedureReturn #True
    Default
      ProcedureReturn #False
  EndSelect ;event
EndProcedure
Important, only because it's being touted as an approach in a PureBasic tutorial at another BASIC site. :wink:


No, it's not needed. You have to respond to specific events, so even if EventWindow() isn't -1 for an OS event (which can be the case as PB sometimes maps PB event constant values with real OS event value for historical reasons) and you don't have it in your Select/Case, it won't be processed. So in both way, you can't have any issues.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 61 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye