GetActiveWindow and GetForegroundWindow on MAC

BlitzMax Forums/BlitzMax Programming/GetActiveWindow and GetForegroundWindow on MAC

Hi, are there equivalent MacOSX API calls to GetActiveWindow and GetForegroundWindow?

On PC, I use GetActiveWindow as soon as my game's graphics window is created to obtain a Window handle that I then use with other API calls such as GetForegroundWindow.

I use GetForegroundWindow to detect if the App has been suspended so that I can pause it. I normally use PeekEvent to capture EVENT_APPSUSPEND however, this doesn't work if a game is loading and the user clicks on some other app or the desktop meanwhile. When the game finishes loading, there is no EVENT_APPSUSPEND to process which I why I'm checking it with an API call to GetForegroundWindow.

If anyone can help with these I'd be very grateful, thanks!

I don't know if this will help you:

http://www.blitzbasic.com/Community/posts.php?topic=43341#500806

I'm not up on Cocoa

Thanks but that module doesn't have a Mac version of GetACtiveWindow, oh well.

I don't even know what Cocoa is but I've seen the name round a lot.

Well, looking at that code and a little probing (Oo-err), I reckon it should look something vaguely like this:

#import <AppKit/AppKit.h>

Int getActiveWindowOSX(){
    NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
    NSApplication *myApp;


    myApp=[NSApplication sharedApplication];

    NSWindow *myWindow = [myApp keyWindow];

    [pool release];
	return NWWindow;
};


I'm probably way off the mark, but hey, I don't own a Mac and have never coded on one. :)

interesting, I shall have to investigate...

any joy with this?

Sorry had to go out, will check now.

OK it nearly works. For a start I changed the return line to:

return NSWindow;


as NWWindow was a typo. But anyway it won't compile, I get "parse error before 'NSWindow'". I'm basically saving the above code into a file with extension .m and then importing it into my BMX. Any ideas? Is the return value the wrong type?

This will likely come in very handy, I have done previous searches and was dissapointed that nobody else had done it!