Bring Window to the Front

Mac OSX specific forum
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Bring Window to the Front

Post 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
Colin
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Bring Window to the Front

Post by Kiffi »

StickyWindow() does not work on a Mac?

Greetings ... Peter
Hygge
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Bring Window to the Front

Post 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)
macOS Catalina 10.15.7
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Re: Bring Window to the Front

Post by ColBoy »

Kiffi wrote:StickyWindow() does not work on a Mac?

Greetings ... Peter
Thanks Peter, wasn't even aware of that one. Works well.
Colin
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Re: Bring Window to the Front

Post 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.
Colin
Post Reply