mestnyi wrote:I need to get a window under the mouse cursor.
there are three windows and when you hover over one of them get its handle.
Code: Select all
Procedure GetWindowUnderMouse()
Protected.i NSApp, NSWindow, WindowNumber, Point.CGPoint
CocoaMessage(@Point, 0, "NSEvent mouseLocation")
WindowNumber = CocoaMessage(0, 0, "NSWindow windowNumberAtPoint:@", @Point, "belowWindowWithWindowNumber:", 0)
NSApp = CocoaMessage(0, 0, "NSApplication sharedApplication")
NSWindow = CocoaMessage(0, NSApp, "windowWithWindowNumber:", WindowNumber)
ProcedureReturn NSWindow
EndProcedure
OpenWindow(0,100,100,300,300,"",#PB_Window_SystemMenu)
OpenWindow(1,200,200,300,300,"",#PB_Window_SystemMenu)
OpenWindow(2,300,300,300,300,"",#PB_Window_SystemMenu)
SetWindowTitle(0, Str(WindowID(0)))
SetWindowTitle(1, Str(WindowID(1)))
SetWindowTitle(2, Str(WindowID(2)))
Repeat
event = WaitWindowEvent()
If #PB_Event_Repaint
Debug GetWindowUnderMouse()
EndIf
Until event = #PB_Event_CloseWindow
or if you need to call it very often you can also compare against the window number.
Code: Select all
Procedure WindowNumberUnderMouse()
Protected Point.CGPoint
CocoaMessage(@Point, 0, "NSEvent mouseLocation")
ProcedureReturn CocoaMessage(0, 0, "NSWindow windowNumberAtPoint:@", @Point, "belowWindowWithWindowNumber:", 0)
EndProcedure
Procedure WindowNumber(PBWindow)
ProcedureReturn CocoaMessage(0, WindowID(PBWindow), "windowNumber")
EndProcedure
OpenWindow(0,100,100,300,300,"",#PB_Window_SystemMenu)
OpenWindow(1,200,200,300,300,"",#PB_Window_SystemMenu)
OpenWindow(2,300,300,300,300,"",#PB_Window_SystemMenu)
SetWindowTitle(0, Str(WindowNumber(0)))
SetWindowTitle(1, Str(WindowNumber(1)))
SetWindowTitle(2, Str(WindowNumber(2)))
Repeat
event = WaitWindowEvent()
If #PB_Event_Repaint
Debug WindowNumberUnderMouse()
EndIf
Until event = #PB_Event_CloseWindow