Cool this works well, and it turns out that I don't need to know the client coords/area. I asked for that because in Windows, a normal window seems to have a border round it and also because the y coords start from the top you have to know where the client area begins AFTER the title bar which can vary height depending on user preferences.
However, on the Mac, because the coords are from the bottom there is no title bar to take into account and also there doesn't seem to be any border round the window. Unless you can CHANGE the window border in any of the MacOS options, anyone know if that's possible?
Here's the final code. When I've finalised this in the framework, I'll have to tweak the X and Y coords by a couple of pixels as if I point at the bottom corner of the window the coords don't quite match up...
cocoamouse.m
main code:
Thanks to all for their help! :-)
However, on the Mac, because the coords are from the bottom there is no title bar to take into account and also there doesn't seem to be any border round the window. Unless you can CHANGE the window border in any of the MacOS options, anyone know if that's possible?
Here's the final code. When I've finalised this in the framework, I'll have to tweak the X and Y coords by a couple of pixels as if I point at the bottom corner of the window the coords don't quite match up...
cocoamouse.m
#include <AppKit/AppKit.h> void macGetCursorPos(int *x,int *y){ NSPoint mouseLoc = [NSEvent mouseLocation]; *x = mouseLoc.x; *y = mouseLoc.y; } int macGetActiveWindow(){ NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; NSApplication *myApp; myApp=[NSApplication sharedApplication]; NSWindow *myWindow = [myApp keyWindow]; [pool release]; // return *NSWindow; } void macGetWindowOrigin(int * x, int * y){ NSApplication *myApp = [NSApplication sharedApplication]; NSWindow *myWindow = [myApp keyWindow]; NSRect myFrame = [myWindow frame]; *x = myFrame.origin.x; *y = myFrame.origin.y; }
main code:
Strict Import "cocoa_mouse.m" Extern Function macGetCursorPos(x:Int Ptr, y:Int Ptr) Function macGetWindowOrigin(x:Int Ptr, y:Int Ptr) End Extern Type TPoint Field X Field Y End Type Function GetScreenPointerPos(x:Int Var, y:Int Var) macGetCursorPos(Varptr x, Varptr y) End Function Function GetWindowOrigin:TPoint() Local p:TPoint = New TPoint macGetWindowOrigin(Varptr p.X, Varptr p.Y) Return p End Function Graphics 640,480, 0 While Not KeyDown(KEY_ESCAPE) Cls Local x:Int, y:Int GetScreenPointerPos(x, y) DrawText "Mouse Pos = " + x + ", " + y, 50, 50 Local p:TPoint = GetWindowOrigin() DrawText "Window Pos = " + p.x + ", " + p.y, 50, 70 Flip Wend End
Thanks to all for their help! :-)