Prevent window title bar going under OSX Menu bar

Anyone know how I can prevent someone sliding a window title bar up under the OSX menu bar and losing access to its controls and the ability to move it? Is the menu bar always a certain number of pixels high? Thanks.

If you use macoslib there is the NSMenu menuBarHeight property you can use to retrieve the height of the menu bar…

I believe it is 22 pixels in height (44 for retina).

I believe Apple recommends against hardcoding the value incase it changes in a future version…

Check Screen.AvailableTop and the other Screen.Available____ functions. They will allow you to do what you want.

How is it that this is happening in the first place? The OS should be doing this automatically. If you’ve made a window that’s drag movable using mouseDown/Drag then use this declare instead in the Windows Open event

[code]Sub Open()

declare sub setMovable lib “Cocoa” selector “setMovableByWindowBackground:” _
(id As integer, b As Boolean)

setMovable(self.Handle, true)

End Sub[/code]

Thanks Will.
Lennox

In the window.Moved event, add

If me.top < Screen(0).AvailableTop then me.top = Screen(0).AvailableTop end if

That said, unless you manipulate the position of the window by code or change resolution, I do not see how you can slide it under the menu bar with the mouse.

I have never even seen a window which could be placed so high, that it goes under the menubar???

Sub Open() me.top = -20 End Sub

Ah - yes - if you specifically tell it to :slight_smile:

I have had apps that ended up at -16 and could never figure out why… and to make it worse it seemed to be “random”

Or if you use the mouse to move about a plain box window or a transparent one, where it is necessary to fix boundaries.

That said, it can also be nice to display the bottom of a global floating window on top of the screen with data such as elapsed time, which will look as a small box that cannot be moved.

Just a side note: if, as an user, you happen to have a bad luck and an app you use hides its window title bar under the menu bar, just press Command-Option-D twice to get it back.

That’s a neat trick. I sometimes run into that after changing resolution when I plug in a cord to echo the screen on TV. With Xojo, I click in the bottom of the window. But with other applications, that will save me from stopping them and restarting. Thank you :slight_smile: