Page 1 of 1

Bring Window to the Front

Posted: Wed Apr 08, 2020 3:13 pm
by ColBoy
I've written a cross platform application for Windows and Mac. It sits on the system tray and when there is a trigger, a window pops up. On Windows I can force the window to the top, so it is always visible, no matter what application I am working on. For the Mac, I can't seem to find the same functionality. So in essence I want to unhide a window, which works, but also make this window appear foremost. Does anyone have any pointers for achieving this?

Thanks

Re: Bring Window to the Front

Posted: Wed Apr 08, 2020 3:16 pm
by Kiffi
StickyWindow() does not work on a Mac?

Greetings ... Peter

Re: Bring Window to the Front

Posted: Wed Apr 08, 2020 4:14 pm
by Wolfram
Maybe you need to bring the whole program to front.

Code: Select all

#NSApplicationActivateAllWindows = 1 << 0
#NSApplicationActivateIgnoringOtherApps = 1 << 1

currentApplication = CocoaMessage(0, 0, "NSRunningApplication currentApplication")
CocoaMessage(0, currentApplication, "activateWithOptions:", #NSApplicationActivateAllWindows | #NSApplicationActivateIgnoringOtherApps)

Re: Bring Window to the Front

Posted: Wed Apr 08, 2020 4:26 pm
by ColBoy
Kiffi wrote:StickyWindow() does not work on a Mac?

Greetings ... Peter
Thanks Peter, wasn't even aware of that one. Works well.

Re: Bring Window to the Front

Posted: Wed Apr 08, 2020 4:27 pm
by ColBoy
Wolfram wrote:Maybe you need to bring the whole program to front.

Code: Select all

#NSApplicationActivateAllWindows = 1 << 0
#NSApplicationActivateIgnoringOtherApps = 1 << 1

currentApplication = CocoaMessage(0, 0, "NSRunningApplication currentApplication")
CocoaMessage(0, currentApplication, "activateWithOptions:", #NSApplicationActivateAllWindows | #NSApplicationActivateIgnoringOtherApps)
Thanks Wolfram. HAven't checked this one as the other works and also gives me the benefit of having the same code for Windows.