Change in EventWindow() behaviour

Just starting out? Need help? Post your questions and find answers here.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Change in EventWindow() behaviour

Post by TI-994A »

Following a question by kiwidave in another thread, I noticed a change in behaviour in PureBasic's EventWindow() handler.

In versions 5.11/x86 and 4.61/x86, even in the absence of any events, EventWindow() would return the number of the window that is being hovered upon by the mouse. However, in versions 5.20/x86 and 5.21/x86, it would only return the number of the active window, except when a gadget is hovered upon, after which time the number of the gadget's parent window will be returned.

This snippet will demonstrate this behaviour. Move the mouse over the windows and the buttons and notice the debug results:

Code: Select all

OpenWindow(1, 100, 100, 200, 200, "Window 1", #PB_Window_SystemMenu)
ButtonGadget(11, 10, 10, 100, 50, "Button 1")
OpenWindow(2, 310, 100, 200, 200, "Window 2", #PB_Window_SystemMenu)
ButtonGadget(21, 10, 10, 100, 50, "Button 2")

Repeat
  event = WaitWindowEvent()
  Debug EventWindow()
Until event = #PB_Event_CloseWindow
Is this an intended change?
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! Please visit my YouTube Channel :D
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Change in EventWindow() behaviour

Post by netmaestro »

Does it matter? The behavior you describe doesn't fall within the boundaries of supported functionality. EventWindow() is only valid when a PB event has been triggered and that isn't happening here. If you receive a PB event in your loop and EventWindow() returns something unexpected then there's something to worry about.
BERESHEIT
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Change in EventWindow() behaviour

Post by mestnyi »

After starting hover your mouse over the first window click the button in the debugger will appear once "2" which should not have been
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Change in EventWindow() behaviour

Post by mestnyi »

I mean, look what the garbage issues

Code: Select all

  Enumeration
      #Designer
      #Form
      #Form1
      #Form2
    EndEnumeration
    Enumeration
      #HyperLink_0
      #HyperLink_1
    EndEnumeration



  
Procedure _AnchorHide_MouseDown()
 Protected EventGadget=EventGadget()
 Protected EventWindow=EventWindow()
 
 Debug EventGadget  
Debug EventWindow  

 EndProcedure  
  




CompilerIf #PB_Compiler_OS =#PB_OS_Windows
  OpenWindow(#Designer, 0, 0, 930, 600, "Designer",  #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  OpenWindow(#Form, 30, 30, 550, 450, "Form", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  
  If GetWindowLongPtr_(WindowID(#Designer), #GWL_STYLE) & #WS_EX_COMPOSITED = #False 
    SetWindowLongPtr_(WindowID(#Designer),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Designer), #GWL_STYLE)|#WS_EX_COMPOSITED)
  EndIf
  
  If GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE) & #WS_EX_COMPOSITED = #False 
    ;SetWindowLongPtr_(WindowID(#Form),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE)|#WS_EX_CLIENTEDGE)
  EndIf
  
  
  If GetWindowLong_(WindowID(#Form), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form),WindowID(#Designer))
   SetWindowColor(#Form,RGB(236,236,236))

   OpenWindow(#Form1, 630, 30, 250, 150, "Form1", #PB_Window_SystemMenu,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  If GetWindowLong_(WindowID(#Form1), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form1),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form1), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form1),WindowID(#Designer))
 SetWindowColor(#Form1,RGB(236,236,236))
 HyperLinkGadget(3, 15, 11, 35, 15, "Hide", $FF0000, #PB_HyperLink_Underline)
      HyperLinkGadget(2, 55, 45, 35, 15, "Show", $FF0000, #PB_HyperLink_Underline)
      
   OpenWindow(#Form2, 630, 260, 250, 150, "Form1", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  If GetWindowLong_(WindowID(#Form2), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form2),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form2), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form2),WindowID(#Designer))
 SetWindowColor(#Form2,RGB(236,236,236))
     
CompilerElse
  OpenWindow(#Designer, 0, 0, 800, 600, "Designer",  #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  OpenWindow(#Form, 0, 0, 800, 600, "Form", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
       
  
CompilerEndIf
 
     Define ogl=UseGadgetList(WindowID(#Form) ) 
      ButtonGadget(1, 15, 45, 200, 125, "ButtonGadget",67108864)
      FrameGadget(4, 15, 280, 200, 125, "ButtonGadget",#PB_Frame_Flat)
      FrameGadget(5, 315, 45, 200, 125, "ButtonGadget",#PB_Frame_Single)
      FrameGadget(6,315, 280, 200, 125, "FrameGadget")
     UseGadgetList(ogl)     
   
      Repeat
      lEvent = WaitWindowEvent()
        
      If lEvent=#WM_LBUTTONDOWN
        _AnchorHide_MouseDown()
         
       ElseIf lEvent=#WM_LBUTTONUP
         
       ElseIf lEvent=#WM_MOUSEMOVE
         
       EndIf
      
      Until lEvent = #PB_Event_CloseWindow
   End
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Change in EventWindow() behaviour

Post by mestnyi »

And look how it should be, is it really impossible to fix?

Code: Select all

  Enumeration
      #Designer
      #Form
      #Form1
      #Form2
    EndEnumeration
    Enumeration
      #HyperLink_0
      #HyperLink_1
    EndEnumeration

;находится ли курсор над даным гаджетом
Procedure _OnTheGadget(Gadget)
  Protected mx = DesktopMouseX()
  Protected my = DesktopMouseY()
 
 If IsGadget(Gadget)
  Protected x=GadgetX(Gadget,#PB_Gadget_ScreenCoordinate)
  Protected y=GadgetY(Gadget,#PB_Gadget_ScreenCoordinate)
  Protected w=GadgetWidth(Gadget)
  Protected h=GadgetHeight(Gadget)
 EndIf
 
 If mx >= x And mx < (x+w) And my >= y And my < (y+h)
  ProcedureReturn #True
 EndIf
EndProcedure

;получить номер гаджета под курсором
Procedure _GetUnderTheCursorGadget(NotGadget=-1)
 CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Protected cursorpos.q
  Protected hWnd
  Protected hGnd
  Protected phGnd
  Protected ID=-1
  
  GetCursorPos_(@Cursorpos)
  hWnd=WindowFromPoint_(Cursorpos)
  ScreenToClient_ (hWnd, @Cursorpos) 
  hGnd= ChildWindowFromPoint_ (hWnd, Cursorpos)
  
  If GetProp_(GetParent_(hGnd),"PB_ID")
   phGnd= GetParent_(hGnd)
  EndIf

  If GetProp_(hWnd,"PB_WindowID")-1 =-1 
   If GetProp_(GetParent_(phGnd),"PB_ID") = GetProp_(hGnd,"PB_ID")  
    If _OnTheGadget(GetProp_(phGnd,"PB_ID"))
     ID= GetProp_(phGnd,"PB_ID") 
    Else
     ID= GetProp_(hWnd,"PB_ID")
    EndIf  
   Else
    If _OnTheGadget(GetProp_(hGnd,"PB_ID"))
     ID= GetProp_(hGnd,"PB_ID") 
    Else
     ID= -1 ;Windows
    EndIf
   EndIf
 Else 
    If _OnTheGadget(GetProp_(hGnd,"PB_ID"))
     If GetProp_(hGnd,"PB_ID") <>IsGadget(NotGadget)
      ID= GetProp_(hGnd,"PB_ID") 
     EndIf 
    Else
     ID= -1 ;Windows    
   EndIf
  EndIf
  
  ProcedureReturn ID
 CompilerElse  
  Debug "Не реализован (GetUnderTheCursorGadget())"
 CompilerEndIf
EndProcedure 
Macro EventGadget() :_GetUnderTheCursorGadget() :EndMacro

;получить номер окна под курсором
Procedure _GetUnderTheCursorWindow()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Protected cursorpos.q
  Protected hWnd
  Protected hGnd
  Protected phGnd
  Protected ID=-1
  
  GetCursorPos_(@Cursorpos)
  hWnd=WindowFromPoint_(Cursorpos)
  ScreenToClient_ (hWnd, @Cursorpos) 
  hGnd= ChildWindowFromPoint_ (hWnd, Cursorpos)
  
  If GetProp_(GetParent_(hGnd),"PB_ID")
   phGnd= GetParent_(hGnd)
  EndIf

  If GetProp_(hWnd,"PB_WindowID")-1 =-1 
   If GetProp_(GetParent_(phGnd),"PB_ID") = GetProp_(hGnd,"PB_ID")  
    If _OnTheGadget(GetProp_(phGnd,"PB_ID"))
     ID= -1
    Else
     ID= -1
    EndIf  
   Else
    If _OnTheGadget(GetProp_(hGnd,"PB_ID"))
     ID= -1 
    Else
     ID= GetProp_(hWnd,"PB_WindowID")-1 ;Windows
    EndIf
   EndIf
 Else 
    If _OnTheGadget(GetProp_(hGnd,"PB_ID"))
      ID= -1 
    Else
     ID= GetProp_(hWnd,"PB_WindowID")-1 ;Windows    
   EndIf
  EndIf
  
  ProcedureReturn ID
 CompilerElse  
  Debug "Не реализован (GetUnderTheCursorGadget())"
 CompilerEndIf
EndProcedure 
Macro EventWindow() :_GetUnderTheCursorWindow() :EndMacro

  
Procedure _AnchorHide_MouseDown()
 Protected EventGadget=EventGadget()
 Protected EventWindow=EventWindow()
 
 Debug EventGadget  
Debug EventWindow  

 EndProcedure  
  




CompilerIf #PB_Compiler_OS =#PB_OS_Windows
  OpenWindow(#Designer, 0, 0, 930, 600, "Designer",  #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  OpenWindow(#Form, 30, 30, 550, 450, "Form", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  
  If GetWindowLongPtr_(WindowID(#Designer), #GWL_STYLE) & #WS_EX_COMPOSITED = #False 
    SetWindowLongPtr_(WindowID(#Designer),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Designer), #GWL_STYLE)|#WS_EX_COMPOSITED)
  EndIf
  
  If GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE) & #WS_EX_COMPOSITED = #False 
    ;SetWindowLongPtr_(WindowID(#Form),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE)|#WS_EX_CLIENTEDGE)
  EndIf
  
  
  If GetWindowLong_(WindowID(#Form), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form),WindowID(#Designer))
   SetWindowColor(#Form,RGB(236,236,236))

   OpenWindow(#Form1, 630, 30, 250, 150, "Form1", #PB_Window_SystemMenu,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  If GetWindowLong_(WindowID(#Form1), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form1),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form1), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form1),WindowID(#Designer))
 SetWindowColor(#Form1,RGB(236,236,236))
 HyperLinkGadget(3, 15, 11, 35, 15, "Hide", $FF0000, #PB_HyperLink_Underline)
      HyperLinkGadget(2, 55, 45, 35, 15, "Show", $FF0000, #PB_HyperLink_Underline)
      
   OpenWindow(#Form2, 630, 260, 250, 150, "Form1", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
  If GetWindowLong_(WindowID(#Form2), #GWL_STYLE) & #WS_CHILD = #False 
    SetWindowLongPtr_(WindowID(#Form2),#GWL_STYLE, GetWindowLongPtr_(WindowID(#Form2), #GWL_STYLE)|#WS_CHILD|#WS_POPUP);
  EndIf
  
   SetParent_(WindowID(#Form2),WindowID(#Designer))
 SetWindowColor(#Form2,RGB(236,236,236))
     
CompilerElse
  OpenWindow(#Designer, 0, 0, 800, 600, "Designer",  #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  OpenWindow(#Form, 0, 0, 800, 600, "Form", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
       
  
CompilerEndIf
 
     Define ogl=UseGadgetList(WindowID(#Form) ) 
      ButtonGadget(1, 15, 45, 200, 125, "ButtonGadget",67108864)
      FrameGadget(4, 15, 280, 200, 125, "ButtonGadget",#PB_Frame_Flat)
      FrameGadget(5, 315, 45, 200, 125, "ButtonGadget",#PB_Frame_Single)
      FrameGadget(6,315, 280, 200, 125, "FrameGadget")
     UseGadgetList(ogl)     
   
      Repeat
      lEvent = WaitWindowEvent()
        
      If lEvent=#WM_LBUTTONDOWN
        _AnchorHide_MouseDown()
         
       ElseIf lEvent=#WM_LBUTTONUP
         
       ElseIf lEvent=#WM_MOUSEMOVE
         
       EndIf
      
      Until lEvent = #PB_Event_CloseWindow
   End
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Change in EventWindow() behaviour

Post by netmaestro »

After starting hover your mouse over the first window click the button in the debugger will appear once "2" which should not have been
The event you refer to is #PB_Event_DeactivateWindow and it is correct for this to appear in your event loop when switching focus from one toplevel window to another.
I mean, look what the garbage issues
Well... GIGO. Your unexpected results here are caused by your attempt to mix API events with PB events. There is nothing to be gained by handling WM_LBUTTONDOWN and then looking at EventGadget(). If you handle #PB_Event_Gadget and then examine EventGadget() and EventWindow() all will be as it should.

If you want to overcome limitations in the events that PB supports, ie mouse hovers etc., by all means write api code to gain the features. But it has to be written to provide all of its own functionality. You can't just jump back and forth between api and PureBasic commands arbitrarily and then expect the Purebasic commands to have kept up with everything that's gone on.
BERESHEIT
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Change in EventWindow() behaviour

Post by TI-994A »

netmaestro wrote:Does it matter? The behavior you describe doesn't fall within the boundaries of supported functionality. EventWindow() is only valid when a PB event has been triggered and that isn't happening here. If you receive a PB event in your loop and EventWindow() returns something unexpected then there's something to worry about.
You mean a change in the way PureBasic processes messages? Yes, I believe it does matter, especially if it is not an intended change; which was my only question. Such stuff as bugs are made on.

IMHO, it seems that the team has decided to stop translating which window the mouse is hovering on, since it is not a supported event to begin with, and also perhaps to save some processing time. However, if that is not the case, it could very well be an unidentified glitch, which could very well lead to further unintended behaviour.

Basically, it's for the attention of the PureBasic development team. :)
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! Please visit my YouTube Channel :D
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Change in EventWindow() behaviour

Post by mestnyi »

Code: Select all

       Enumeration
          #Designer
          #Form
          #Form1
          #Form2
        EndEnumeration
        Enumeration
          #HyperLink_0
          #HyperLink_1
        EndEnumeration
       
        Global LeftClickWindow.i=-1
        Global ActivateWindow.i=-1
       
  OpenWindow(#Designer, 0, 0, 930, 600, "Designer",  #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
      OpenWindow(#Form, 30, 30, 550, 450, "Form", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
     
      
       SetParent_(WindowID(#Form),WindowID(#Designer))
      
       OpenWindow(#Form1, 630, 30, 250, 150, "Form1", #PB_Window_SystemMenu,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
     
     
       SetParent_(WindowID(#Form1),WindowID(#Designer))
    
       OpenWindow(#Form2, 630, 260, 250, 150, "Form1", #PB_Window_SystemMenu|#PB_Window_SizeGadget,WindowID(#Designer) ) ;|#WS_CHILD|#WS_POPUP
      
       SetParent_(WindowID(#Form2),WindowID(#Designer))
        
     
         Define ogl=UseGadgetList(WindowID(#Form) )
          ButtonGadget(1, 15, 45, 200, 125, "ButtonGadget",67108864)
          FrameGadget(4, 15, 280, 200, 125, "ButtonGadget",#PB_Frame_Flat)
          FrameGadget(5, 315, 45, 200, 125, "ButtonGadget",#PB_Frame_Single)
          FrameGadget(6,315, 280, 200, 125, "FrameGadget")
         UseGadgetList(ogl)     
       
          Repeat
          lEvent = WaitWindowEvent()
           
          If lEvent=#PB_Event_LeftClick
            EventWindow=EventWindow()
            Debug "#PB_Event_LeftClick_Up"+EventWindow()
         EndIf
          If lEvent=#PB_Event_Gadget
            Debug "#PB_Event_Gadget_Up"+EventGadget()
         EndIf
         
          If lEvent=#PB_Event_ActivateWindow
            Debug "Activate"+EventWindow()
           
          EndIf 
           
            If lEvent=#WM_LBUTTONDOWN
             Debug "LBUTTONDOWN"+EventWindow()
             Debug "LeftClick"+EventWindow
             Debug "a"+GetActiveWindow()
             
           ElseIf lEvent=#WM_LBUTTONUP
             Debug "LBUTTONUP"+EventWindow()
           
             
           ElseIf lEvent=#WM_MOUSEMOVE
         
           EndIf
         
          Until lEvent = #PB_Event_CloseWindow
       End
The problem is that # PB_Event_LeftClick, # PB_Event_Gadget occur when released and not when you should be as

Code: Select all

    If OpenWindow(0, 200, 200, 600, 420, "")
      ButtonGadget(230, 15, 375, 80, 25, "ButtonGadget")
         ButtonGadget(231, 215, 315, 80, 35, "ButtonGadget")
         TextGadget(214, 95, 10, 60, 25, "TextGadget");,#SS_NOTIFY)
         StringGadget(244, 300, 10, 139, 25, "TStringGadget")
         ComboBoxGadget(144, 170, 10, 120, 25)
         
         ScrollAreaGadget(344, 10, 50, 480,100, 776, 450, 30,#SS_NOTIFY)
         ButtonGadget(444, 15, 10, 130, 45, "ButtonGadget");,6543)
         StringGadget(174, 225, 10, 150, 25, "StringGadget",19)
         CloseGadgetList()
         
         ContainerGadget(354, 10, 180, 480,100,#PB_Container_Flat|#SS_NOTIFY)
         ButtonGadget(454, 15, 10, 130, 45, "ButtonGadget");,6543)
         StringGadget(154, 225, 10, 250, 25, "StringGadget",19)
         CloseGadgetList()
         
         ListIconGadget(556, 300, 300, 222, 116, "", -1, #PB_ListIcon_MultiSelect )
        SpinGadget(222,100,307,105,22,0,1000,#PB_Spin_Numeric)
       
      ButtonGadget(1,150,150,150,25,"нажимай и двигай")
      SpinGadget(2,5,5,150,25,0,100,#PB_Spin_Numeric)
     SetGadgetText(2,"8")
     
      Repeat
         Select WaitWindowEvent()     ; check for window events
           Case #PB_Event_Gadget 
            Debug  "eg"+GetActiveGadget()
           
           
           Case 513
            Debug  "ld"+GetActiveGadget()
             
         
           Case #PB_Event_CloseWindow
              Quit = 1
          EndSelect
        Until Quit = 1
      EndIf
Last edited by mestnyi on Tue Mar 11, 2014 4:54 am, edited 4 times in total.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Change in EventWindow() behaviour

Post by c4s »

@mestnyi
Offtopic: You don't have to post three times in a row. Please try putting them in just one post by using the edit post functionality. Thanks.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Change in EventWindow() behaviour

Post by mestnyi »

netmaestro Still a problem in EventWindow() because you said you can't mix the API and PB why GetActiveWindow() no problems?

Code: Select all

#PB_Event_Window = -1

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import ""
  CompilerElse
    ImportC ""
    CompilerEndIf
    
    CompilerIf Not Defined(CountWindow, #PB_Function)   
      Procedure CountWindow()
        PB_Object_Count(*Object)
        PB_Window_Objects.l
      EndImport
      ProcedureReturn PB_Object_Count(PB_Window_Objects) 
    EndProcedure   
  CompilerEndIf
  
  ProcedureDLL WaitWindowClose_Init() 
    Structure SetWindowEventStruct
      Window.l
      ProcedureName.l
      Event.l
    EndStructure
    
    Global NewList WindowEventList.SetWindowEventStruct()
  EndProcedure
  
  WaitWindowClose_Init() 
  
  Procedure WaitWindowCloseCallBack()
    If (Not EventWindow() = (Val(GetEnvironmentVariable("PB_MainWindow")) -1)) And (CountWindow() <>1)
      CloseWindow(EventWindow())
    EndIf
  EndProcedure
  
  Procedure WaitWindowCloseEvent(Event, Window)
    ForEach WindowEventList()
      If WindowEventList()\Window = Window
        If Event =   WindowEventList()\Event
          CallFunctionFast(WindowEventList()\ProcedureName, Event, Window)
          LastElement(WindowEventList())
        ElseIf WindowEventList()\Event = #PB_Event_Window
          CallFunctionFast(WindowEventList()\ProcedureName, Event, Window)
          LastElement(WindowEventList())
        EndIf 
      ElseIf WindowEventList()\Window = #PB_Any
        If Event =   WindowEventList()\Event
          CallFunctionFast(WindowEventList()\ProcedureName, Event, Window)
          LastElement(WindowEventList())
        ElseIf WindowEventList()\Event = #PB_Event_Window
          CallFunctionFast(WindowEventList()\ProcedureName, Event, Window)
          LastElement(WindowEventList())
        EndIf 
      EndIf
    Next
  EndProcedure
  
  ProcedureDLL WaitWindowClose3(Window, Timeout)
    Protected Event
    If IsWindow(Window) 
      SetActiveWindow(Window) 
    EndIf
    SetEnvironmentVariable("PB_MainWindow", Str(Window +1)) 
    BindEvent(#PB_Event_CloseWindow, @WaitWindowCloseCallBack())
    
    If Timeout =-1 
      While Event <> #PB_Event_CloseWindow 
        Event = WindowEvent()
        If Event = #PB_Event_DeactivateWindow
         WaitWindowCloseEvent(Event, EventWindow())
        Else
         WaitWindowCloseEvent(Event, GetActiveWindow())
        EndIf  
      Wend 
    Else 
      While Event <> #PB_Event_CloseWindow 
        Event = WaitWindowEvent(Timeout)
        If Event = #PB_Event_DeactivateWindow
         WaitWindowCloseEvent(Event, EventWindow())
        Else
         WaitWindowCloseEvent(Event, GetActiveWindow())
        EndIf  
      Wend 
    EndIf
  EndProcedure
  ProcedureDLL WaitWindowClose2(Window)
    ProcedureReturn WaitWindowClose3(Window, 0)
  EndProcedure
  ProcedureDLL WaitWindowClose() ;WaitWindowEvent(timeout): if timeout = -1 WindowEvent()
    ProcedureReturn WaitWindowClose2(#PB_Any)
  EndProcedure
  
  ProcedureDLL SetWindowEvent(*ProcedureName, Window =#PB_Any, Event =#PB_Event_Window)
    If *ProcedureName
      AddElement(WindowEventList())
      WindowEventList()\Event         = Event
      WindowEventList()\Window        = Window
      WindowEventList()\ProcedureName = *ProcedureName
    EndIf 
  EndProcedure
  
  CompilerIf #PB_Compiler_IsMainFile
    CompilerIf Not Defined(WaitWindowClose, #PB_Function)
      Macro WaitWindowClose(Window=-1,Timeout=0)
        WaitWindowClose3(Window, Timeout) 
      EndMacro
    CompilerEndIf
    
    If OpenWindow(1, 0, 0, 322, 150, "1", #PB_Window_SystemMenu )
      ContainerGadget(10, 8, 8, 306, 133, #PB_Container_Raised)
      ButtonGadget(11, 10, 15, 80, 24, "Button 1")
      ButtonGadget(12, 95, 15, 80, 24, "Button 2")
      CloseGadgetList()
    EndIf
    If OpenWindow(2, 0, 230, 322, 150, "2", #PB_Window_SystemMenu )
      ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
      ButtonGadget(1, 10, 15, 80, 24, "Button 1")
      ButtonGadget(2, 95, 15, 80, 24, "Button 2")
      CloseGadgetList()
    EndIf
    If OpenWindow(3, 0, 460, 322, 150, "3", #PB_Window_SystemMenu )
      ContainerGadget(20, 8, 8, 306, 133, #PB_Container_Raised)
      ButtonGadget(21, 10, 15, 80, 24, "Button 1")
      ButtonGadget(22, 95, 15, 80, 24, "Button 2")
      CloseGadgetList()
    EndIf
    If OpenWindow(4, 0, 0, 322, 150, "4", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
      ContainerGadget(120, 8, 8, 306, 133, #PB_Container_Raised)
      ButtonGadget(121, 10, 15, 80, 24, "Button 1")
      ButtonGadget(122, 95, 15, 80, 24, "Button 2")
      CloseGadgetList()
    EndIf
    
    Procedure EventWindowAll(Event, Window)
      Select Event
        Case #PB_Event_Gadget
          Debug "#PB_Event_Gadget "+EventGadget()
        Case #PB_Event_LeftClick
          Debug "#PB_Event_LeftClick "+Window
        Case #WM_LBUTTONDOWN
          Debug "#WM_LBUTTONDOWN "+Window
        Case #PB_Event_DeactivateWindow
          Debug "#PB_Event_DeactivateWindow "+Window
        Case #PB_Event_ActivateWindow
          Debug "#PB_Event_activateWindow "+Window
      EndSelect
    EndProcedure 
    
    SetWindowEvent(@EventWindowAll(),2);,#PB_Event_Gadget)
    SetWindowEvent(@EventWindowAll(),3,#WM_LBUTTONDOWN)
    SetWindowEvent(@EventWindowAll(),4,#PB_Event_DeactivateWindow)
    
    WaitWindowClose(4) 
  CompilerEndIf
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Change in EventWindow() behaviour

Post by PB »

> In versions 5.11/x86 and 4.61/x86, even in the absence of any events,
> EventWindow() would return the number of the window that is being
> hovered upon by the mouse

Sorry, but no version of PureBasic has ever supported a "hover" event
for EventWindow(). Even version 5.11 doesn't mention it in the manual.

Now, the manual for EventWindow() in version 5.30 states:

"After a WindowEvent() or WaitWindowEvent() function, use this
function to determine on which window the event has occurred."

Then, in the list of SUPPORTED EVENTS for WindowEvent(), there
is absolutely nothing with "hover" or "mouse over" listed. So, you
can't expect EventWindow() to report when hovering over a window.

If it did happen to work in past PureBasic versions, it was probably
just an unintended feature, bug or exploit.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Change in EventWindow() behaviour

Post by TI-994A »

PB wrote:Sorry, but no version of PureBasic has ever supported a "hover" event for EventWindow(). Even version 5.11 doesn't mention it in the manual.
TI-994A wrote:IMHO, it seems that the team has decided to stop translating which window the mouse is hovering on, since it is not a supported event to begin with, and also perhaps to save some processing time. However, if that is not the case, it could very well be an unidentified glitch, which could very well lead to further unintended behaviour.
Nevertheless, thanks for bumping the topic. :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! Please visit my YouTube Channel :D
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Change in EventWindow() behaviour

Post by PB »

> since it is not a supported event to begin with

LOL, I only read the first post. :)

And I didn't bump the thread; the post above mine did that. :P
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply