Detaching to Close Child Window

I need to detach a child window added with addchildwindow.
There are a couple of posts I made for starting this.
why-does-close-fail
keep-window-at-front-macos

In both of these posts a declare for detaching is posted, but I cannot figure out how to apply it, because of the situation.
I need to disable the menuitem FileClose because it closes the parent window first. So, I have a Pushbutton added for close.
This CloseButton closes the controls on the window but not the window.

The code for detaching is:

soft declare sub removeChildWindow lib "Cocoa" selector "removeChildWindow:" (parentWindow As Ptr, childWindow As Ptr) removeChildWindow(Ptr(Self.Handle), Ptr(Window2.Handle))

Where do I put the code, because it doesn’t belong in the ChildWindow and how do I coordinate the pointers?
Here’s a link to the project Close window

Have you tried to simply set the child window invisible ?

About the code, I believe it should be in the Parent window. Or a module.

If the declare should be in the parent window, and I need to pass the parent window as an object to the child window.
Is there a way that this can be done without a constructor?
If not, then how do I add a constructor to a window without subclassing it?

I solved my problem. I read one of my previous questions and responses. I forgot to change the Frame Type from SheetWindow to Document. It was 2 months ago, it was only one of severals things I needed to change.
why-does-close-fail
It now works fine.