How to make the Mac window go to the fore?

How can I programmatically make the mac window be the front window? I have a window handle and want my window to appear above all other windows. I can use both Carbon and Cocoa for this.

+6
c ++ cocoa graphics carbon macos
source share
2 answers

For Cocoa, you can set the window level using:

[window setLevel:NSFloatingWindowLevel]; 

A floating window will appear above all other normal windows, even if your application is inactive.

If you want your application to be active, you can use:

 [NSApp activateIgnoringOtherApps:YES]; 

and

 [window makeKeyAndOrderFront:nil]; 
+12
source share

If you can (only 32-bit) use kOverlayWindowClass:

 WindowRef carbon_window = NULL; CreateNewWindow( kOverlayWindowClass , ... , &carbon_window ); // if you need cocoa: NSWindow *cocoa_window = [[NSWindow alloc] initWithWindowRef:carbon_window]; 

Otherwise, create an NSWindow and set the window level to kCGOverlayWindowLevel .

Please note that this will also be above the panel. If you want to be under the elevator, use kCGUtilityWindowLevel.

0
source share

All Articles