Handle (Ptr) is zero for dynamically created DesktopContainer

I’ve been working on implementing @Greg_O’s example project for MacOS SaveOpenDialogs for a text editor type project.

The example includes an AccessoryView feature that I would like to use to offer some options for both opening & saving files (e.g., alternate Encodings).

Note: for custom controls to appear in the NSOpenPanelGTO or NSSavePanelGTO windows, they need to be hosted in a DesktopContainer.

The challenge is that the example project is based on having a DesktopWindow open, which the custom container (for the AccessoryView) is added as a control.

But what I’m attempting to do is invoke the Open & Save Panels (with the AccessoryView) without a window open.

I can successfully display the Open & Save Panels from the app’s DesktopApplication object (App) fine, but I cannot attach the AccessoryView because calling the custom container with the New keyword results in the container object having a Handle of &h0000000000000000 (zero).

After some testing and reading of the docs, I see that a DesktopContainer does not have a Handle value until either one of the .EmbedWithin methods are called, or the control is “opened” like when the window it is attached too is opened.

In other words, I’m trying to convert Greg’s example code from the following:

// add the custom accessory view
SaveAccessories1.SetFileTypes(types)
SaveAccessories1.Reset
mDialog.AccessoryView = SaveAccessories1

To something like the following:

// add the custom accessory view
Var accView As New SaveAccessories()
accView.SetFileTypes(types)
accView.Reset
mDialog.AccessoryView = accView // assignment errors out

The project will run in debug mode, but when the Open or Save panel is invoked, it fails because the AccessoryView method requires an object with a proper Handle value.

I tried to adopt @Ian_Kennedy’s workaround from this post, but I couldn’t get it to work. I had trouble following the conversation (brain-fog, eh), so I’m not sure where I went wrong.

Any suggestions would be appreciated.

Keep in mind, I’m trying to make this work without having a DesktopWindow already open.

Thank you.

That’s never going to work because the controls don’t exist until the window opens and initializes.

Your best bet might be to open the window but have be invisible (Window.Visible=false).

2 Likes

You have to have a window open to make it work. For save this is pretty much required anyway, otherwise what are you saving. Equally, it cannot be closed while the save dialog is open. I made this work by using the sheet version of the save dialog.

As for open, my application only has one document type so if none are open and I do an import I just open one and use that, again in sheet mode.

1 Like

As a workaround, the idea did occur to me, but I’m not happy about it :upside_down_face:

Thank you for confirming what I already suspected. I appreciate your feedback Eric.

Thank you also, Ian, for confirming this. I wasn’t 100% sure.

I want to create a file from a predefined template, that is saved to disk (to a location of the user’s choice) before opening it in the editor. Otherwise, in most cases I’m calling “File Save As…” on files that are already open in a window.

It’s the “create from a template” scenario (when the editor window happens to be closed) I’m trying to work out.

I guess I’ll have to re-think my workflow for both the Open and Save panels… :face_with_monocle: