Force close button to show on Cocoa Movable Modal?

I know OS X Movable Modal windows do not show a close button (according to wiki)… is there a quick n’ dirty trick to toss a close button on them? Or is it a strict limitation on Cocoa?

My application has the close buttons on Windows, but not on its Cocoa counterpart!

My other less-ideal solution is to show a regular button to close the Movable Modal with #If TargetCocoa, but that is really ugly.

Thanks as always!

This code (adapted from here) in the Open event handler of a Window set as Movable Modal seems to also work:

#If TargetCocoa
  Const NSTitledWindowMask = 1
  Const NSClosableWindowMask = 2
  Declare Sub setStyleMask Lib "Cocoa.framework" _
    selector "setStyleMask:" (obj_id As Integer, mask As Integer)
  setStyleMask(Self.Handle, NSTitledWindowMask Or NSClosableWindowMask)
1 Like

Michael the code I tried from that thread would work only if Maximize button was enabled, but then the Maximize button showed up in Windows as well and I could not disable it with any code.

Paul’s code is working well so I will utilize this on each Window Open

Thanks all!!

Sorry to revive an old post…
This works great for macOS…
but as Zachary mentioned above the Maximize Button must be enabled for it to work

For Windows nothing special needs to be done to show the Close icon, but how can I turn OFF the Maximize icon for Windows??? Since this can only be done via the IDE, the use of #TARGET cannot be applied

Assign a constant to the boolean switch and have a different value in the constant for Windows and MacOS

Except it is a READ ONLY property

You can assign a constant to an IDE switch by right-clicking on the switch. This lets you have platform specific settings.

Ok… something I did not know…
But how does it work? I right clicked, and now “#kwinDateFmtMaximizeButton” shows instead of the switch
but where is it, so that I can control its value

Ok… figured it out… the docs are really lame in respect to that

well actually I didn’t because the constant editor won’t allow the “#” as specified by the docs

the # syntax is used in many places
if you want a localized string in a label you use that same style
this is the exact same syntax just how you assign one to a boolean (or color) is different

Its not obvious where you’d find this in the docs BUT after a bunch of poking about

I had found that … but what is NOT clear from that is the when you create a constant, the you leave the “#” off.

Also… why doesn’t the compile fail if you don’t create an instance of the constant name?

the constant is not found
so the value is “#constantname” which is converted to a boolean so you probably get “false”

same as if you put in a #constant into the width (try it in a new project and set the width of window1 to #foo)
the constant is not found
so you get #constant converted to an integer - which is likely 0

it could be made to cause a “compile” error - although it hasnt actually hit the compiler at that point
sounds like a feature request to me