OSX set window focus (Use of undeclared identifier 'NSWindow')

I have an app running in the background and on receiving a certain OSC message it should 1) get focus 2) go to fullscreen. I’m having troubles with the getting focus part (even though I did something similar with older versions of openFrameworks, but can’t find that code anymore.)

I found this snippet on how to get a window pointer

NSWindow * appWindow = (NSWindow *)ofGetCocoaWindow();
if(appWindow) {
    // make your obj-c calls here

but if I try to use it I get

Use of undeclared identifier ‘NSWindow’

I set my code type to Objective-C++. Any hints on what I need to do?

OF 0.10.1, XCode 10.3

Also: importing Cocoa.h yields 2 errors in glew.h:

Typedef redefinition with different types (‘unsigned int’ vs ‘void *’)

Gltypes.h included before glew.h


I am not entirely sure how to set the window focus - but I can at least help you get this compiling :slight_smile:

At the top of ofApp.cpp put:

#include "ofApp.h"
#include <Cocoa/Cocoa.h>

Then click ofApp.cpp in the left sidebar of Xcode so it is highlighted and then in the right sidebar set the file type to Objective-C++ Source.


Then it should compile just fine.

Let me know if you figure out the window focus!
All the best,

Reading your post again - it might just be the header include order at the top of ofApp.cpp.