Force Z-Order?

Hi,
Is it possible to sort the z-order of a window when it opens via Window.Show, so that the window will always appear on top of ANY other windows on the user’s system?

At the moment - my window shows, but UNDERNEATH any other open windows belonging to other apps.

Thanks.

if the app is active & frontmost then its windows should be front most

if its not then its kind of rude to bully your way to the front (and annoys users regardless of how important you think it is)

There is the window type Global Floating Window…

I thought I saw at one time there was a declare for this?

Example:
If my app’s main window is closed, but the app is still open, and the user is looking at their browser - when they want to go back into my app, they can click on the NSStatusItem, which opens my app’s main window.

Therefore, the user WANTS my app to be at the forefront :slight_smile:
Unfortunately however, it appears under their browser :frowning:

Hope that made more sense.

Oh. The declare for that is [NSApp activateIgnoringOtherApps:TRUE]

If this is for an NSStatusItem app (as you mentioned in another thread), you’ll need to do what Tim suggests above to bring your app’s windows to the front.

This should do what you want (untested):

Declare Function NSClassFromString Lib "Cocoa" ( inName As CFStringRef ) As Ptr Declare Function sharedApplication Lib "Cocoa" selector "sharedApplication" ( classRef As Ptr ) As Ptr Dim myApp As Ptr = sharedApplication( NSClassFromString( "NSApplication" ) ) Declare Sub activateIgnoringOtherApps Lib "Cocoa" selector "activateIgnoringOtherApps:" ( appRef As Ptr, flag As Boolean ) activateIgnoringOtherApps( myApp, True )

Thanks Tim and Gavin - I appreciate it.
I have also just realised that if my app is running but has no open windows - nothing will happen if they click on my icon in the Dock.
They users may then not realise they need to click on the NSStatusItem in order to display my app again.

Is it possible to make Window1.show when the app icon in the dock is shown?
If not - then I will remove the NSStatusItem altogether.

Thanks :slight_smile:

If they click the icon in the dock that’ll* cause App.Activate
(so handle Window1.show in the Activate event for App)

*should

Thanks Tim - that kind of worked.

If the user closes the main window and then clicks on the dock icon - nothing happens.
But it the user closes the main window, then clicks on the desktop, AND THEN clicks on the app icon - the main window shows as required :frowning:

Alternatively, (an even better option) - can a second helper app (which creates the NSStatusItem) be put inside my main app’s bundle?

That way, when my main app opens, it could execute the second app, which in turn would create the NSStatusItem.
My main app could then quit when the MainWindow is closed, and be re-opened by the second helper app.

So basically I need to know if:

A) The helper app can be inside my main app’s bundle.
B) Can the helper app’s dock icon be hidden whilst it is running?

Thank you all for your kind advice :slight_smile:

A) Yes
B) Google LSUIElement to learn more about it

Thanks Tim,
I will look into LSUIElement :slight_smile:

[quote=103801:@Richard Summers]
I will look into LSUIElement :)[/quote]

https://forum.xojo.com/11024-how-to-start-app-with-no-window-and-without-icon-in-dock

Thanks Michel - I knew I had seen it somewhere :slight_smile:

I have applied the method Sasha posted with the build script. Works like a charm :slight_smile:

All working perfectly now :slight_smile:
I now know how to have JUST the NSStatusItem which is clickable, and also how to have a single menu item in the NSStatusItem.

I am however, having trouble getting multiple menu items to work in the NSStatusItem :frowning:
This is the code which creates the NSStatusItem and the accompanying 2 menu options:

[code]dim bar as NSStatusBar = NSStatusBar.SystemStatusBar
item1 = bar.CreateStatusItem(NSStatusBar.NSVariableStatusItemLength, AddressOf StatusItemHandler)
item1.title = “DevSuite”
item1.highlightMode = true
item1.Image = NSImage.StatusAvailable
item1.AlternateImage = NSImage.StatusPartiallyAvailable

dim mmenu as new NSMenu
call mmenu.Append(“Display App”)
mmenu.Append(NSMenuItem.CreateSeparatorItem)
call mmenu.Append(“Quit App”)

item1.menu = mmenu[/code]

What code do I put in the StatusItemHandler to determine which menu option was clicked?
At the moment I have this code:

MainWindow.show

But both menu items cause this code to execute, and I do not know what code to put in an if statement, in order to determine which menu item was clicked??

I need something like:

If FIRST MENU ITEM WAS CLICKED then MainWindow.show else Quit end if

Thanks.

Are you still using App Wrapper Mini? If so, you can simply check the “Background only application” and it’ll set the option when it sets the others.

Solved :slight_smile:

If hitItem.text = "Display App" then MainWindow.show else Quit End if

Great. Thank you Sam. I could not do without App Wrapper Mini :slight_smile: