Strange behaviour??

Hi,
I have a window which pops up when the user clicks on my StatusItem.

When I first click on the statusitem and then click outside the window - the window.deactivate event handler closes the window (as desired).
BUT
When I click on the statusitem a second time, and then click outside the window - nothing happens (the window.deactivate event fails to work).
If I click on any control in the window, (causing my window to close) and then try agin - it works??

So basically, the deactivate.event only works every other time (if I click on a window control)???

Any ideas, geniuses?
Thanks.
:slight_smile:

[quote=109115:@Richard Summers]Hi,
I have a window which pops up when the user clicks on my StatusItem.

When I first click on the statusitem and then click outside the window - the window.deactivate event handler closes the window (as desired).
BUT
When I click on the statusitem a second time, and then click outside the window - nothing happens (the window.deactivate event fails to work).
If I click on any control in the window, (causing my window to close) and then try agin - it works??

So basically, the deactivate.event only works every other time (if I click on a window control)???

Any ideas, geniuses?
Thanks.
:)[/quote]
Assuming this is Dock-less app (LSUIElement) then when you “click outside the window”, you are giving the focus to another app (or, probably, the desktop/Finder). After that, even if you then access your statusitem, your app actually isn’t gaining focus and therefore your window.deactivate won’t fire.

The solution is to give your app the focus again, when the status item is clicked. Use the following code in your status item handler:

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 )

Let me know if that works for you.

Thanks Gavin - will try that after Kem’s webinar :slight_smile:

That worked just dandy - Cheers Gavin :slight_smile: