简体   繁体   中英

Activate all windows from background when clicking on main window

I have an Objective-C application with a main window and a small progress window with a stack view to show the current progress.

If the application is put in the background by activating any other application and then clicking on the Dock icon, both the Main and secondary windows is brought to the front and shown.

But, if I just click one of the windows when in the background, only that window is activated and brought to the front, the other stays in the back.

I want to implement so that when I click on the main window it does the same thing as clicking on the Dock icon, it should show both windows on top with the Main window activated.

But if I click on the progress window, I don't want the main window to be brought to the front.

I haven't been able to find a way to do this, how should I go about achieving this?

You can detect the window being clicked with the window delegate's -windowDidBecomeKey: or -becomeKeyWindow , or the app delegate's -didBecomeActive: .

Then depending on your exact needs, you can use [NSApp activateIgnoringOtherApps:] or [[NSRunningApplication currentApplication] activateWithOptions:] (and possibly NSApplicationActivateAllWindows ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM