Custom Titlebar

I have done a lot of research and have gotten most of what I want to happen working, but something very simple (at least in my head) is driving me nuts that I can’t seem to solve.

I am wanting to be able to eliminate the titlebar, but still retain the system traffic light buttons on the window. Essentially, I’m wanting to draw my own titlebar, similar to this image (not my product and I have zero affiliation, but it’s a good example of what I’m looking for):

Sample Window

As you can see in that image, it has a button, a custom title and graphics in the background. I’ve figured out, using declares (and some MBS Plugin stuff) how to get buttons and hiding the title itself, but I can’t figure out how to draw in the titlebar area.

Any suggestions or pointers to a discussion on this or whatnot would be very appreciated.

Somewhat related discussion here about black windows. https://forum.xojo.com/10914-black-windows/

Discussion about controls in a title bar: https://forum.xojo.com/18847-custom-title-bar-with-buttons-etc/

And discussion about custom frames. https://forum.xojo.com/32413-nsthemeframe-custom-theme/

or you can try this component: http://www.pesarosystem.it/xojo-new-window-style-english.asp

So, I figured out a solution to my question and am posting it here for anyone who ends up searching in the future. It turns out I was not setting the NSWindow.StyleMask correctly. Once I figured out the correct code for the correct StyleMask, I was able to get the content area to go across the entire window, including vertically and still have the OS toolbar and window controls.

The bar on the left is a simple FillRect in the window’s Paint event. The window’s title is just a Label control. The icons on the right are part of the window’s toolbar (created 100% using the Xojo Toolbar control).

The code I used to get there is a combination of some declares I found previously and some MBS plugin code (that I’m sure could be replaced with declares).

[code]Declare Function toolbar Lib “Cocoa” Selector “toolbar” (NSWindow As Ptr) As Ptr
Declare Sub setShowsBaselineSeparator Lib “Cocoa” Selector “setShowsBaselineSeparator:” (NSToolbar As Ptr, flag As Boolean)
Declare Sub setDisplayMode Lib “Cocoa” Selector “setDisplayMode:” (NSToolbar As Ptr, NSToolbarDisplayMode As UInteger)

Const ToolbarDisplayModeDefault = 0
Const ToolbarDisplayModeIconAndLabel = 1
Const ToolbarDisplayModeIconOnly = 2
Const ToolbarDisplayModeLabelOnly = 3

me.NSWindowMBS.titleVisibility = NSWindowMBS.NSWindowTitleHidden
me.NSWindowMBS.titlebarAppearsTransparent = True
me.NSWindowMBS.styleMask = me.NSWindowMBS.styleMask + NSWindowMBS.NSFullSizeContentViewWindowMask

Dim ToolbarPtr as Ptr = Toolbar( Ptr( Self.Handle ) )
SetShowsBaselineSeparator( toolbarPtr, false )
SetDisplayMode( toolbarPtr, ToolbarDisplayModeLabelOnly )[/code]

Thank you to @Tanner Lee for his pointing out some other very useful threads that I’ll be sure to have bookmarked for the future. And @Gabriele Marchionni that window class looks interesting as well.

1 Like

Does anyone happen to know the declares which can replace the MBS code in he above example?

If you own the Retina Kit, they’re included there. Check the demo application.

I purchased your original Retina Kit, but no longer have it, as I lost it when I formatted my Mac.
Maybe I will repurchase it.

Thanks Sam.