How to force Mac window to foreground?

你。 提交于 2019-12-18 06:19:02

问题


How can I programmatically force a mac window to be the front window? I have the window handle, and want to ensure that my window is displayed above all other windows. I can use both Carbon & Cocoa for this.


回答1:


For Cocoa, you can set the window level using:

[window setLevel:NSFloatingWindowLevel];

A floating window will display above all other regular windows, even if your app isn't active.

If you want to make your app active, you can use:

[NSApp activateIgnoringOtherApps:YES];

and

[window makeKeyAndOrderFront:nil];



回答2:


If you can (32 bit only) 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.

Note that this will be above the dashboard as well. If you want to be below the dashbord use kCGUtilityWindowLevel.



来源:https://stackoverflow.com/questions/2763827/how-to-force-mac-window-to-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!