Attach a Window child to Window Parent?

Hi everyone - I figured I would broaden my audience on this forum topic from earlier today. Does anyone happen to have windows Declares to attach a window to a parent window so when you move the parent window the child window moves with it? Its what Christian has for OS X NSWindowMBS.AddChildWindow().

Thank you much in advance!
Mike

NSWindowMBS class is for macOS.

I think this would have to be done at the time the window is created (which is before you see any events / constructors in Xojo code)

The method CreateWindowEXW like


creates a new window with the supplied parent window as a child. There’s no way to access this directly from Xojo

The closest I could find it the SetParent which seems like it will make a window be a child of an existing window

However this still doesnt seem to be quite the same as macOS where children move as a group with their parents
You might have to use calls to TileWindows


to do this “automatically” as the parent window is moved

Thanks Norman! Im testing SetParent now. Will let you know what I find between that and TileWindows.

@npalardy et al.

Update on SetParent - It was an easy declare to make, but it didn’t glue the child to the parent.

TileWindows:
What do you normally do when Win32API calls for an array (Integer Type) but we can’t pass that to an external function using a declare (I get this message and I’m new to declares on Win32API)?

Type: const HWND*

An array of handles to the child windows to arrange. If a specified child window is a top-level window with the style WS_EX_TOPMOST or WS_EX_TOOLWINDOW , the child window is not arranged. If this parameter is NULL , all child windows of the specified parent window (or of the desktop window) are arranged.

How would i pass this array to an external function? --> I found this answer in @eugenedakin’s Declare eBook (http://scispec.ca/) Thanks Eugene!

I’m getting a failed code 0 - Ill keep at it and post working code then.

Thanks!

really need to get Julian in here to comment :stuck_out_tongue:

If the Windows move together anyway, why not do it in ONE Window?

You could use a WindowSplitter, give different parts different background colours, etc

Thanks Markus, but in my case no - The UX for my app uses this to give a bootstrap feel. Ill post screen shots after Im done.

Hi Mike,

I am not close to my development computer. Sorry, I won’t be able to comment for a while (week or so?).

Oh no need Eugene – I was saying that i answered my own question by reading your Declare book! :slight_smile:
To pass an array to an external source you need to create a memory block and pass it as a pointer :wink: Thank you for writing that book! Now getting that function to work is my next challenge :slight_smile:
Hope you are doing well @eugenedakin

1 Like

WHAT !!! ???
OMG PANIC Eugene is away from his computer ???
What has the world come to ? :stuck_out_tongue:

Hows the field ?
And … where ?

1 Like

My apologies for my misunderstanding. LOL, its been a very long day - rewarding, just a long day.

Chuckle, Norm, you soooo know how this works :slight_smile: I can’t tell you how many times I have been asked a ‘rush’ question that quickly suffers from scope creep.

Its good - I can’t see the forest for the trees - literally :slight_smile:

Google maps says that I am near the Alberta Saskatchewan border, about 1.5 hours from nowhere… chuckle… I just have to make sure that my truck is full of fuel and my power cords can charge my portable equipment. Roads? I don’t need any roads where I am … lol…

In the oil business ??? Nawwwwwww
Been there done that and used to write software for a geophysical company and …
OMG !!!

Have fun !

1 Like

Success!!

Ok this took a few declares to attach a child window to a parent window (Move the parent and the child follows seamlessly). Here is the sample project I built.

https://www.dropbox.com/s/ue5ayl9o5r7cfh6/ChildParentMoveTest.xojo_binary_project?dl=1

The View code is in ChildWindow.Open and the controller code is in the WindowsAPI module.

// SET PARENT OF THIS WINDOW TO MAIN WINDOW
Var setParentResultInt as Integer = WindowsAPI.setParent(Self.Handle, ParentWindow.Handle)

// SET CHILD BIT ON WINDOW STYLE
Var childStyle as Integer = WS_CHILDWINDOW
Var setWinStyleResultInt as Integer = WindowsAPI.SetWindowLong(Self.Handle, GWL_STYLE, childStyle)

// SET BORDER AROUND CHILD WINDOW
Var borderStyle as Integer = WS_BORDER
Var borderResultInt as Integer = WindowsAPI.SetWindowLong(Self.Handle, GWL_STYLE, borderStyle)

// SET CHILD X/Y POS  VARIABLES
Var newXpos as Integer = (ParentWindow.Width/2 - self.Width/2)
Var newYpos as Integer = (ParentWindow.Height/2 - self.Height/2)
Var newW as Integer = Self.Width
Var newH as Integer = Self.Height
Var moveWinResultInt as Integer = WindowsAPI.MoveWindow(Self.Handle, newXpos, newYpos, newW, newH, True)

// UPDATE PARENT
Var updateWinResultInt as Integer = WindowsAPI.UpdateWindow(ParentWindow.Handle)