
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
WINDOWS
Detect on which window the mouse is over
' _cursevent doesn't seem to work correctly for me, as shown below.
' i correctly get a zero when i move outside of my app's windows,
' but don't get a _cursevent when i move over one of my windows.
' anyone know why?
COMPILE 0,_caseinsensitive
WINDOW 1,"",(100,100)-(300,200),_doc
WINDOW 2,"",(200,200)-(400,300),_doc
END GLOBALS
CLEAR LOCAL FN dodialog
evnt=DIALOG(0) : id=DIALOG(evnt)
LONG IF evnt=_cursevent
BEEP
PRINT id,TIME$
IF id<>0 THEN WINDOW ABS(id)
END IF
END FN
ON DIALOG FN dodialog
DO
HANDLEEVENTS
UNTIL 0
I don't know why but I had a similar experience so I moved to an ON EVENT... routine, rather than ON DIALOG..., and started using my own logic to determine when the mouse cursor entered or left a certain region.
The details go something like this...
LOCAL FN DoEvent
theEvent = {EVENT}
thePoint;4 = EVENT+_evtMouse
modKeys;2 = EVENT+_evtMeta
optDown = modKeys AND _optionKey%
cmdDown = modKeys AND _cmdKey%
ctrlDown = modKeys AND _controlKey%
activeWnd = WINDOW(_activeWnd)
LONG IF activeWnd = theWindowIWant
WINDOW OUTPUT #theWindowIWant
CALL GLOBALTOLOCAL(thePoint)
LONG IF FN PTINRGN(thePoint, theRegionOfTheWindowIWant)
inTheRegion = _zTrue
XELSE
LONG IF inTheRegion
leftTheRegion = _zTrue
END IF
inTheRegion = _false
END IF
END IF
This type of thing works quite well for me.
I have never gotten any ID value except zero with a _cursEvent event, and then only when the cursor moved _off_ the window.
I would recommend that you use the Toolbox function FINDWINDOW to determine which window your mouse is over.
Code snippets to track what's what with your windows and where your mouse is :
Everything starting with a little "g" is a global. I create a window called "debug" which allows me to track everything going on as the programs starts up, runs, and terminates. Hope this helps someone, and allows bowerbid to track his mouse.
' In the Dialog event :
CASE _cursEvent
LONG IF DialogIdent = 0
gMouseWindow = 0
gMouseState = _MouseNotInWindow
END IF
'
CASE _cursOver
gMouseState = _MouseInWindow
gMouseWindow = DIALOG(_cursEvent)
SELECT DialogIdent
CASE = 0
gMouseField = 0
gMouseButton = 0
CASE < 0
gMouseState = _MouseInField
gMouseField = ABS(DialogIdent)
gMouseButton = 0
CASE > 0
gMouseState = _MouseInButton
gMouseButton = ABS(DialogIdent)
gMouseField = 0
END SELECT
' The event Loop :
DO
HANDLEEVENTS
FN TrackWindow
UNTIL gTheCowsComeHome
' In the INCL file or wherever
LOCAL
DIM ActWin,OutWin
LOCAL FN TrackWindow
LONG IF gWinState(_DebugWindow) = _WinOpen : ' User defined constant
TEXT _monaco,9,0,0
LONG COLOR 0,0,0
ActWin = WINDOW (_ActiveWnd)
OutWin = WINDOW (_OutputWnd)
WINDOW OUTPUT _DebugWindow
TEXT _monaco,9,0,0
CALL MOVETO (10,30)
PRINT "Act Win = ";ActWin;". Out Win = ";OutWin;" ";
CALL MOVETO (10,45)
PRINT "Mouse State = ";gMouseState;
PRINT " Window = ";gMouseWindow;" Field ";gMouseField
WINDOW OUTPUT OutWin
END IF
END FN
|