buy my framework ;-) (actually no Joke, it's probably very useful for someone like you, there's tons of stuff like this...)
Anyway you need this in WINDOWS ONLY:
?win32
Extern "win32"
Function GetCursorPos%(point: Byte Ptr)
Function GetWindowInfo(hWnd%, WindowInfo: Byte Ptr)
End Extern
?
Type TPoint
Field X
Field Y
Method Set(tx,ty)
X = tx
Y = ty
End Method
End Type
Type TWindowInfo
Field cbSize
Field wl,wt,wr,wb 'need to inline the TRect as 4xIntegers
Field cl,ct,cr,cb 'need to inline the TRect as 4xIntegers
Field dwStyle
Field dwExStyle
Field dwWindowStatus
Field cxWindowBorders
Field cyWindowBorders
Field atomWindowType:Short 'Research shows an Atom to be a 16-bit value (I hope)
Field wCreatorVersion:Short
End Type
' -----------------------------------------------------------------------------
' ccGetCursorPos: Windows API call to get the mouse cursor position relative to the desktop top left
' -----------------------------------------------------------------------------
Function ccGetCursorPos:TPoint()
'Returns a TPoint
Local point:TPoint = New TPoint
?Win32
If Not GetCursorPos(point) Then
'Don't error any more otherwise you get a bomb if the screensaver kicks in
'when "on resume, password protect" is ticked.
' ccRunTimeError ("Error Getting Cursor Pos")
Return Null
Else
Return point
EndIf
?
Return point 'safety for non-windows
End Function
Method SetClientCoords()
?Win32
Local wi:TWindowInfo = ccGetWindowInfoHandle(WindowHandle)
ClientX = wi.cl
ClientY = wi.ct
?
End Method
' -----------------------------------------------------------------------------
' ccGetWindowInfoHandle: Uses Windows API call to return useful info such as any window area and client area
' -----------------------------------------------------------------------------
Function ccGetWindowInfoHandle:TWindowInfo(hWnd%)
'Pass in a handle to a window.
Local wi:TWindowInfo = New TWindowInfo
?Win32
wi.cbSize = SizeOf(wi)
GetWindowInfo(hwnd,wi)
?
Return wi 'leave outside ?Win32 bit for safety
End Function
There I think that's everything, if something seems missing post again.
Haven't got time to show you how to use it, but it's obvious really. e.g. get the client window X/Y relative to desktop, then get the mouse coords relative to desktop, then check to see if mouse is outside client window (you should know it's width and height of course), then you can do some jiggery pokery to hide the mouse or SLIDE it in an out of the window in a lovely manner like my games do ;-)
When you get it working on a MAC via MacOSX calls please let me know! :-)
[edit] You can get a window handle like this: Local hWnd% = GetActiveWindow(). I would advise doing this STRAIGHT AFTER creating your windowed mode and storing it globally. Oh GetActiveWindow is another win32 API call - put this in the extern section: Function GetActiveWindow%()
|