Weird MaxGui/EVentHook behavior

BlitzMax Forums/BlitzMax Programming/Weird MaxGui/EVentHook behavior

try this code
Strict
Global ConnectWindow:TGadget = CreateWindow("Connect",20,40,800,600,Null,  ..
      WINDOW_TITLEBAR | WINDOW_MENU | WINDOW_CLIENTCOORDS)
Global ConnectCanvas:TGadget = CreateCanvas(0,0,800,600,ConnectWindow)
Global X:Int, Y:Int, MouseIsDown:Int = False

AddHook EmitEventHook, ConnectHook

Repeat
 WaitEvent()
 Select EventID()
  Case EVENT_WINDOWCLOSE
   FreeGadget ConnectCanvas
   End
  Case EVENT_APPTERMINATE
   End
 End Select
Forever

Function ConnectHook:Object(id:Int,Data:Object,context:Object)
 Local event:TEvent = TEvent(Data)
 If event = Null Return Null

 Select event.id
  Case EVENT_GADGETPAINT
   SetGraphics CanvasGraphics(ConnectCanvas)
   Cls
   DrawText "X = "+X,10,10
   DrawText "Y = "+Y,10,30
   DrawText "Mouse Button is ",10,50
   If MouseIsDown
    DrawText "down",150,50
   Else
    DrawText "up",150,50
   End If
   Flip
   Return Null
  Case EVENT_MOUSEDOWN
   X = event.x
   Y = event.y
   MouseIsDown = True
   RedrawGadget ConnectCanvas
   Return Null
  Case EVENT_MOUSEUP
   MouseIsDown = False
   RedrawGadget ConnectCanvas
   Return Null
  Case EVENT_MOUSEMOVE
   'If MouseIsDown
    X = event.x
    Y = Event.y
   'End If
   RedrawGadget ConnectCanvas
   Return Null
 
 End Select
 Return Data

End Function

When you move the mouse around on the canvas, the X and Y positions get updated. When the mouse leaves the canvas area, the X and Y positions stop updating. However, if you press and hold the mouse button while you move, the X and Y positions continue to update even when you leave the canvas. It'll even report negative values if you move the mouse to the left or above the canvas.