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.
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
Unfortunately however, it appears under their browser
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.
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
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?
All working perfectly now
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
This is the code which creates the NSStatusItem and the accompanying 2 menu options:
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